[cfe-commits] r44065 - in /cfe/trunk: Parse/ParseExpr.cpp test/Parser/expressions.c

Chris Lattner sabre at nondot.org
Tue Nov 13 12:50:37 PST 2007


Author: lattner
Date: Tue Nov 13 14:50:37 2007
New Revision: 44065

URL: http://llvm.org/viewvc/llvm-project?rev=44065&view=rev
Log:
Parse "sizeof(arr)[0]" as a sizeof of an expr if arr 
is an expression.

Modified:
    cfe/trunk/Parse/ParseExpr.cpp
    cfe/trunk/test/Parser/expressions.c

Modified: cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseExpr.cpp?rev=44065&r1=44064&r2=44065&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/Parse/ParseExpr.cpp Tue Nov 13 14:50:37 2007
@@ -748,11 +748,15 @@
     
     // If ParseParenExpression parsed a '(typename)' sequence only, the this is
     // sizeof/alignof a type.  Otherwise, it is sizeof/alignof an expression.
-    if (ExprType == CastExpr) {
+    if (ExprType == CastExpr)
       return Actions.ActOnSizeOfAlignOfTypeExpr(OpTok.getLocation(),
                                                 OpTok.is(tok::kw_sizeof),
                                                 LParenLoc, CastTy, RParenLoc);
-    }
+    
+    // If this is a parenthesized expression, it is the start of a 
+    // unary-expression, but doesn't include any postfix pieces.  Parse these
+    // now if present.
+    Operand = ParsePostfixExpressionSuffix(Operand);
   }
   
   // If we get here, the operand to the sizeof/alignof was an expresion.

Modified: cfe/trunk/test/Parser/expressions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/expressions.c?rev=44065&r1=44064&r2=44065&view=diff

==============================================================================
--- cfe/trunk/test/Parser/expressions.c (original)
+++ cfe/trunk/test/Parser/expressions.c Tue Nov 13 14:50:37 2007
@@ -28,3 +28,12 @@
   // FIXME: change into something that is semantically correct.
   __builtin_offsetof(int, a.b.c[4][5]);
 }
+
+void test_sizeof(){
+        int arr[10];
+        sizeof arr[0];
+        sizeof(arr[0]);
+        sizeof(arr)[0];
+}
+
+





More information about the cfe-commits mailing list