summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/Driver/TextDiagnosticPrinter.cpp2
-rw-r--r--clang/Sema/SemaDecl.cpp9
-rw-r--r--clang/test/Sema/recover-goto.c4
3 files changed, 12 insertions, 3 deletions
diff --git a/clang/Driver/TextDiagnosticPrinter.cpp b/clang/Driver/TextDiagnosticPrinter.cpp
index bd98b91124f..2f867d06265 100644
--- a/clang/Driver/TextDiagnosticPrinter.cpp
+++ b/clang/Driver/TextDiagnosticPrinter.cpp
@@ -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();
diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp
index 51d6547aa5c..a264eeab048 100644
--- a/clang/Sema/SemaDecl.cpp
+++ b/clang/Sema/SemaDecl.cpp
@@ -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/clang/test/Sema/recover-goto.c b/clang/test/Sema/recover-goto.c
new file mode 100644
index 00000000000..4bb7c51bbf9
--- /dev/null
+++ b/clang/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 '}'}}
OpenPOWER on IntegriCloud