[cfe-commits] r41637 - /cfe/trunk/Parse/ParseExpr.cpp

Chris Lattner sabre at nondot.org
Thu Aug 30 21:58:34 PDT 2007


Author: lattner
Date: Thu Aug 30 23:58:34 2007
New Revision: 41637

URL: http://llvm.org/viewvc/llvm-project?rev=41637&view=rev
Log:
fix some memory leaks when recovering.

Modified:
    cfe/trunk/Parse/ParseExpr.cpp

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

==============================================================================
--- cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/Parse/ParseExpr.cpp Thu Aug 30 23:58:34 2007
@@ -315,7 +315,10 @@
         // In particular, the RHS of the '?' is 'expression', not
         // 'logical-OR-expression' as we might expect.
         TernaryMiddle = ParseExpression();
-        if (TernaryMiddle.isInvalid) return TernaryMiddle;
+        if (TernaryMiddle.isInvalid) {
+          Actions.DeleteExpr(LHS.Val);
+          return TernaryMiddle;
+        }
       } else {
         // Special case handling of "X ? Y : Z" where Y is empty:
         //   logical-OR-expression '?' ':' conditional-expression   [GNU]
@@ -326,6 +329,8 @@
       if (Tok.getKind() != tok::colon) {
         Diag(Tok, diag::err_expected_colon);
         Diag(OpToken, diag::err_matching, "?");
+        Actions.DeleteExpr(LHS.Val);
+        Actions.DeleteExpr(TernaryMiddle.Val);
         return ExprResult(true);
       }
       
@@ -335,7 +340,11 @@
     
     // Parse another leaf here for the RHS of the operator.
     ExprResult RHS = ParseCastExpression(false);
-    if (RHS.isInvalid) return RHS;
+    if (RHS.isInvalid) {
+      Actions.DeleteExpr(LHS.Val);
+      Actions.DeleteExpr(TernaryMiddle.Val);
+      return RHS;
+    }
 
     // Remember the precedence of this operator and get the precedence of the
     // operator immediately to the right of the RHS.
@@ -355,7 +364,11 @@
       // is okay, to bind exactly as tightly.  For example, compile A=B=C=D as
       // A=(B=(C=D)), where each paren is a level of recursion here.
       RHS = ParseRHSOfBinaryExpression(RHS, ThisPrec + !isRightAssoc);
-      if (RHS.isInvalid) return RHS;
+      if (RHS.isInvalid) {
+        Actions.DeleteExpr(LHS.Val);
+        Actions.DeleteExpr(TernaryMiddle.Val);
+        return RHS;
+      }
 
       NextTokPrec = getBinOpPrecedence(Tok.getKind());
     }
@@ -368,6 +381,8 @@
     else
       LHS = Actions.ParseConditionalOp(OpToken.getLocation(), ColonLoc,
                                        LHS.Val, TernaryMiddle.Val, RHS.Val);
+    if (LHS.isInvalid)
+      return LHS;
   }
 }
 





More information about the cfe-commits mailing list