From 00a0cf70d9ee5f28438d22ae0f28e4f3655bdc12 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 16 Mar 2010 06:04:47 +0000 Subject: [PATCH] Don't consume tokens past the end-of-file in an @interface. Fixes . llvm-svn: 98613 --- clang/include/clang/Basic/DiagnosticParseKinds.td | 1 + clang/lib/Frontend/CompilerInstance.cpp | 2 ++ clang/lib/Parse/ParseObjc.cpp | 4 ++++ clang/test/Parser/missing-end.m | 7 +++++++ 4 files changed, 14 insertions(+) create mode 100644 clang/test/Parser/missing-end.m diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 80a4eaee1120..9d001d48cc2a 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -183,6 +183,7 @@ def err_objc_no_attributes_on_category : Error< def err_objc_missing_end : Error<"missing @end">; def warn_objc_protocol_qualifier_missing_id : Warning< "protocol qualifiers without 'id' is archaic">; +def err_objc_unknown_at : Error<"expected an Objective-C directive after '@'">; def err_objc_illegal_visibility_spec : Error< "illegal visibility specification">; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index c43118ce56b0..3bc566192965 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -294,6 +294,8 @@ void CompilerInstance::createCodeCompletionConsumer() { getFrontendOpts().DebugCodeCompletionPrinter, getFrontendOpts().ShowMacrosInCodeCompletion, llvm::outs())); + if (!CompletionConsumer) + return; if (CompletionConsumer->isOutputBinary() && llvm::sys::Program::ChangeStdoutToBinary()) { diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 7ab0e71dc235..7b2b6e855bb7 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -375,6 +375,10 @@ void Parser::ParseObjCInterfaceDeclList(DeclPtrTy interfaceDecl, AtEnd.setBegin(AtLoc); AtEnd.setEnd(Tok.getLocation()); break; + } else if (DirectiveKind == tok::objc_not_keyword) { + Diag(Tok, diag::err_objc_unknown_at); + SkipUntil(tok::semi); + continue; } // Eat the identifier. diff --git a/clang/test/Parser/missing-end.m b/clang/test/Parser/missing-end.m new file mode 100644 index 000000000000..fb264610aecb --- /dev/null +++ b/clang/test/Parser/missing-end.m @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@interface AAA +{ +} +@ x// expected-error{{expected an Objective-C directive after '@'}} +// expected-error{{missing @end}}