From 0cbc215ccd01ba7ce8e46cac5be147746cf0af4e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 25 Jan 2008 00:01:10 +0000 Subject: [PATCH] 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 --- Driver/TextDiagnosticPrinter.cpp | 2 +- Sema/SemaDecl.cpp | 9 +++++++-- test/Sema/recover-goto.c | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 test/Sema/recover-goto.c 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((Stmt*)Body)->push_back(L); + if (Body) { + L->setSubStmt(new NullStmt(L->getIdentLoc())); + cast((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 '}'}} -- 2.40.0