diff options
author | Chris Lattner <sabre@nondot.org> | 2008-01-25 00:01:10 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-01-25 00:01:10 +0000 |
commit | 0cbc215ccd01ba7ce8e46cac5be147746cf0af4e (patch) | |
tree | df62dd951f6285a2e531cbe78df3e472856d2841 | |
parent | 09cf90f6d6d87c32f0611b4d6ca563ed1ab05c15 (diff) |
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
-rw-r--r-- | Driver/TextDiagnosticPrinter.cpp | 2 | ||||
-rw-r--r-- | Sema/SemaDecl.cpp | 9 | ||||
-rw-r--r-- | test/Sema/recover-goto.c | 4 |
3 files changed, 12 insertions, 3 deletions
diff --git a/Driver/TextDiagnosticPrinter.cpp b/Driver/TextDiagnosticPrinter.cpp index bd98b91124..2f867d0626 100644 --- a/Driver/TextDiagnosticPrinter.cpp +++ b/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/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 51d6547aa5..a264eeab04 100644 --- a/Sema/SemaDecl.cpp +++ b/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/test/Sema/recover-goto.c b/test/Sema/recover-goto.c new file mode 100644 index 0000000000..4bb7c51bbf --- /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 '}'}} |