]> granicus.if.org Git - clang/commitdiff
Parse "sizeof(arr)[0]" as a sizeof of an expr if arr
authorChris Lattner <sabre@nondot.org>
Tue, 13 Nov 2007 20:50:37 +0000 (20:50 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 13 Nov 2007 20:50:37 +0000 (20:50 +0000)
is an expression.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44065 91177308-0d34-0410-b5e6-96231b3b80d8

Parse/ParseExpr.cpp
test/Parser/expressions.c

index 2bc1d62fcfafe1a427c770194ae10405aa91227e..c1a200cd71056ee719f50f392bf790fb1d26322c 100644 (file)
@@ -748,11 +748,15 @@ Parser::ExprResult Parser::ParseSizeofAlignofExpression() {
     
     // 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.
index 3fb8c1c89df950dcbadca379e63ae554ee1ed2cb..3b47260c32f2e69d8a179210868f9de4c98a9ec9 100644 (file)
@@ -28,3 +28,12 @@ int test_offsetof() {
   // 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];
+}
+
+