]> granicus.if.org Git - clang/commitdiff
improve comments, build array and array range designator nodes,
authorChris Lattner <sabre@nondot.org>
Sun, 26 Oct 2008 23:06:54 +0000 (23:06 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 26 Oct 2008 23:06:54 +0000 (23:06 +0000)
fix an obscure memory leak.

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

lib/Parse/ParseInit.cpp

index 1f5fa1cf8c0505c1bd0d04fdae1592e7d1899463..ed30f64d93967e375b3bb2bbae0d353b8e616ac3 100644 (file)
@@ -104,11 +104,18 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations,
     // We must have either an array designator now or an objc message send.
     assert(Tok.is(tok::l_square) && "Unexpected token!");
     
-    // array-designator: '[' constant-expression ']'
-    // array-designator: '[' constant-expression '...' constant-expression ']'
-    // When designation is empty, this can be '[' objc-message-expr ']'.  Note
-    // that we also have the case of [4][foo bar], which is the gnu designator
-    // extension + objc message send.
+    // Handle the two forms of array designator:
+    //   array-designator: '[' constant-expression ']'
+    //   array-designator: '[' constant-expression '...' constant-expression ']'
+    //
+    // Also, we have to handle the case where the expression after the
+    // designator an an objc message send: '[' objc-message-expr ']'.
+    // Interesting cases are:
+    //   [foo bar]         -> objc message send
+    //   [foo]             -> array designator
+    //   [foo ... bar]     -> array designator
+    //   [4][foo bar]      -> obsolete GNU designation with objc message send.
+    //
     SourceLocation StartLoc = ConsumeBracket();
     
     // If Objective-C is enabled and this is a typename or other identifier
@@ -140,17 +147,26 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations,
       // [4][foo bar].
       return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, 0,Idx.Val);
     }
+
+    // Create designation if we haven't already.
+    if (Desig == 0)
+      Desig = &Designations.CreateDesignation(InitNum);
     
-    // Handle the gnu array range extension.
-    if (Tok.is(tok::ellipsis)) {
+    // If this is a normal array designator, remember it.
+    if (Tok.isNot(tok::ellipsis)) {
+      Desig->AddDesignator(Designator::getArray(Idx.Val));
+    } else {
+      // Handle the gnu array range extension.
       Diag(Tok, diag::ext_gnu_array_range);
       ConsumeToken();
       
       ExprResult RHS = ParseConstantExpression();
       if (RHS.isInvalid) {
+        Actions.DeleteExpr(Idx.Val);
         SkipUntil(tok::r_square);
         return RHS;
       }
+      Desig->AddDesignator(Designator::getArrayRange(Idx.Val, RHS.Val));
     }
     
     MatchRHSPunctuation(tok::r_square, StartLoc);