From 4c1a6e0ccd90da71cb6d2e7cacfc284a07b180b8 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Sun, 15 Oct 2017 00:42:42 -0400 Subject: [PATCH] Bug 486140 - Cast expression with label reference expression as operand Change-Id: I77d8e7dabc64f68818f4222ffe3d6ba7eebae542 --- .../cdt/core/parser/tests/ast2/AST2Tests.java | 35 +++++++++++++++++++ .../parser/AbstractGNUSourceCodeParser.java | 3 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java index d9e51074ed2..8a9675c606a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2Tests.java @@ -7569,6 +7569,41 @@ public class AST2Tests extends AST2TestBase { parseAndCheckBindings(true); } + // void f() { + // unsigned long long labelPtr; + // labelPtr = (unsigned long long) &&L; + // goto *labelPtr; + // L: + // return; + // } + public void testExpressionLabelReferenceCast_486140a() throws Exception { + // Here, the cast-expression is the only valid parse. + parseAndCheckBindings(true); + } + + // typedef unsigned long long ULL; + // void f() { + // unsigned long long labelPtr; + // labelPtr = (ULL) &&L; + // goto *labelPtr; + // L: + // return; + // } + public void testExpressionLabelReferenceCast_486140b() throws Exception { + // Here, the cast-expression and the binary-expression are both + // syntactically valid, but the correct parse is the cast-expression. + parseAndCheckBindings(true); + } + + // int test(int waldo, int other) { + // return (waldo) && other; + // } + public void testBinaryExprNotMisparsedAsCast_486140() throws Exception { + // Again cast-expression and binary-expression are both syntactically + // valid, but this time the correct parse is binary-expression. + parseAndCheckBindings(true); + } + // int version = 0; // int NextVersion() { // return __atomic_add_fetch(&version, 1, 5); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 4302ee90c2e..3ff0f8204f9 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -1097,6 +1097,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { break; case IToken.tAND: op= IASTBinaryExpression.op_logicalAnd; + unaryOp = IASTUnaryExpression.op_labelReference; break; case IToken.tBITOR: op= IASTBinaryExpression.op_binaryOr; @@ -1269,6 +1270,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { // ambiguity with unary operator case IToken.tPLUS: case IToken.tMINUS: case IToken.tSTAR: case IToken.tAMPER: + case IToken.tAND: final int operatorOffset = LA(1).getOffset(); IToken markEnd= mark(); backup(mark); @@ -2597,7 +2599,6 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { skipBrackets(IToken.tLPAREN, IToken.tRPAREN, IToken.tSEMI); switch (LTcatchEOF(1)) { case IToken.tAMPERASSIGN: - case IToken.tAND: case IToken.tARROW: case IToken.tARROWSTAR: case IToken.tASSIGN: