]> granicus.if.org Git - clang/commitdiff
When a statement is dropped from the AST because it was invalid, make sure
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 15 Feb 2013 18:34:13 +0000 (18:34 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 15 Feb 2013 18:34:13 +0000 (18:34 +0000)
we don't do the scope checks otherwise we are going to hit assertion checks
since a label may not have been actually added.

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

include/clang/Sema/ScopeInfo.h
lib/Parse/ParseStmt.cpp
lib/Sema/SemaStmt.cpp
test/SemaCXX/scope-check.cpp

index 990bb53c099dba99f1ddf739da14c00614166c15..2295bf437cb3bc6aee7e2c1f296216e35cf7d750 100644 (file)
@@ -91,6 +91,9 @@ public:
   /// \brief Whether this function contains any indirect gotos.
   bool HasIndirectGoto;
 
+  /// \brief Whether a statement was dropped because it was invalid.
+  bool HasDroppedStmt;
+
   /// A flag that is set when parsing a method that must call super's
   /// implementation, such as \c -dealloc, \c -finalize, or any method marked
   /// with \c __attribute__((objc_requires_super)).
@@ -287,9 +290,14 @@ public:
     HasIndirectGoto = true;
   }
 
+  void setHasDroppedStmt() {
+    HasDroppedStmt = true;
+  }
+
   bool NeedsScopeChecking() const {
-    return HasIndirectGoto ||
-          (HasBranchProtectedScope && HasBranchIntoScope);
+    return !HasDroppedStmt &&
+        (HasIndirectGoto ||
+          (HasBranchProtectedScope && HasBranchIntoScope));
   }
   
   FunctionScopeInfo(DiagnosticsEngine &Diag)
@@ -297,6 +305,7 @@ public:
       HasBranchProtectedScope(false),
       HasBranchIntoScope(false),
       HasIndirectGoto(false),
+      HasDroppedStmt(false),
       ObjCShouldCallSuper(false),
       ErrorTrap(Diag) { }
 
index 8b026e859f644cd7333e3e2b58296041091a4112..4c8bd6fe56b1ced764eb33b0044e807a29f2ca71 100644 (file)
@@ -1042,11 +1042,6 @@ StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) {
 
   IfScope.Exit();
 
-  // If the condition was invalid, discard the if statement.  We could recover
-  // better by replacing it with a valid expr, but don't do that yet.
-  if (CondExp.isInvalid() && !CondVar)
-    return StmtError();
-
   // If the then or else stmt is invalid and the other is valid (and present),
   // make turn the invalid one into a null stmt to avoid dropping the other
   // part.  If both are invalid, return error.
index fd3ee0d9f56c65cda4f8e0d5da49efb75fdf0ceb..dcb86b780b193e8fbd44bc5aabbdff81fd458ee6 100644 (file)
@@ -406,6 +406,13 @@ StmtResult
 Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar,
                   Stmt *thenStmt, SourceLocation ElseLoc,
                   Stmt *elseStmt) {
+  // If the condition was invalid, discard the if statement.  We could recover
+  // better by replacing it with a valid expr, but don't do that yet.
+  if (!CondVal.get() && !CondVar) {
+    getCurFunction()->setHasDroppedStmt();
+    return StmtError();
+  }
+
   ExprResult CondResult(CondVal.release());
 
   VarDecl *ConditionVar = 0;
index 8fd23f4efe91504cbc630ce87056817520d5c419..de276ae3d3d6dc4cd7ae10a69651af38e10811f7 100644 (file)
@@ -274,3 +274,15 @@ namespace test15 {
     goto x; // expected-error {{goto into protected scope}}
   }
 }
+
+namespace test16 {
+Invalid inv; // expected-error {{unknown type name}}
+// Make sure this doesn't assert.
+void fn()
+{
+    int c = 0;
+    if (inv)
+Here: ;
+    goto Here;
+}
+}