]> granicus.if.org Git - clang/commitdiff
Fix a bug recovering from broken code with a goto that Eli reported.
authorChris Lattner <sabre@nondot.org>
Fri, 25 Jan 2008 00:01:10 +0000 (00:01 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 25 Jan 2008 00:01:10 +0000 (00:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46336 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/TextDiagnosticPrinter.cpp
Sema/SemaDecl.cpp
test/Sema/recover-goto.c [new file with mode: 0644]

index bd98b91124faab07f9682f37f96dfb1ae998b64a..2f867d0626553ff319ad70de0e3a3167e4f4f816 100644 (file)
@@ -131,7 +131,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic &Diags,
     ColNo = LPos.getColumnNumber();
     const char *TokLogicalPtr = LPos.getCharacterData();
     LineStart = TokLogicalPtr-ColNo+1;  // Column # is 1-based
-  
+
     // Compute the line end.  Scan forward from the error position to the end of
     // the line.
     const llvm::MemoryBuffer *Buffer = LPos.getBuffer();
index 51d6547aa5c7a78aa7d62f38e1dcc213ee47addf..a264eeab048526d0e7ff6c0bffd1022ff8d617e6 100644 (file)
@@ -1031,8 +1031,13 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtTy *Body) {
       // At this point, we have gotos that use the bogus label.  Stitch it into
       // the function body so that they aren't leaked and that the AST is well
       // formed.
-      L->setSubStmt(new NullStmt(L->getIdentLoc()));
-      cast<CompoundStmt>((Stmt*)Body)->push_back(L);
+      if (Body) {
+        L->setSubStmt(new NullStmt(L->getIdentLoc()));
+        cast<CompoundStmt>((Stmt*)Body)->push_back(L);
+      } else {
+        // The whole function wasn't parsed correctly, just delete this.
+        delete L;
+      }
     }
   }
   LabelMap.clear();
diff --git a/test/Sema/recover-goto.c b/test/Sema/recover-goto.c
new file mode 100644 (file)
index 0000000..4bb7c51
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: clang -fsyntax-only %s -verify
+
+void a() {goto A; // expected-error {{use of undeclared label}}
+// expected-error {{expected '}'}}