Fix a bug recovering from broken code with a goto that Eli reported.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46336 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/TextDiagnosticPrinter.cpp b/Driver/TextDiagnosticPrinter.cpp
index bd98b91..2f867d0 100644
--- a/Driver/TextDiagnosticPrinter.cpp
+++ b/Driver/TextDiagnosticPrinter.cpp
@@ -131,7 +131,7 @@
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();
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 51d6547..a264eea 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -1031,8 +1031,13 @@
// 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
index 0000000..4bb7c51
--- /dev/null
+++ b/test/Sema/recover-goto.c
@@ -0,0 +1,4 @@
+// RUN: clang -fsyntax-only %s -verify
+
+void a() {goto A; // expected-error {{use of undeclared label}}
+// expected-error {{expected '}'}}