diff options
author | Chris Lattner <sabre@nondot.org> | 2008-12-08 21:59:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-12-08 21:59:01 +0000 |
commit | 46415261ee5dc828c6f6c6f2be95bd3896c5683c (patch) | |
tree | 3c27c3b020d73eb508b3623e988920ab55958759 /clang | |
parent | 3a90716f6a955e3a2de557f6714a29a84422ea87 (diff) | |
download | bcm5719-llvm-46415261ee5dc828c6f6c6f2be95bd3896c5683c.tar.gz bcm5719-llvm-46415261ee5dc828c6f6c6f2be95bd3896c5683c.zip |
Fix PR3172: if we see an eof or } at the top level, reject it.
This is important because ParseDeclarationOrFunctionDefinition
skips to, but does not consume, an } on error.
llvm-svn: 60719
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Parse/Parser.cpp | 9 | ||||
-rw-r--r-- | clang/test/Parser/recovery-3.c | 5 |
2 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index bce73ccdeb4..8a5498828e3 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -295,6 +295,7 @@ void Parser::ParseTranslationUnit() { } /// ParseExternalDeclaration: +/// /// external-declaration: [C99 6.9], declaration: [C++ dcl.dcl] /// function-definition /// declaration @@ -318,6 +319,13 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() { ConsumeToken(); // TODO: Invoke action for top-level semicolon. return 0; + case tok::r_brace: + Diag(Tok, diag::err_expected_external_declaration); + ConsumeBrace(); + return 0; + case tok::eof: + Diag(Tok, diag::err_expected_external_declaration); + return 0; case tok::kw___extension__: { // __extension__ silences extension warnings in the subexpression. ExtensionRAIIObject O(Diags); // Use RAII to do this. @@ -352,6 +360,7 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() { case tok::kw_export: // As in 'export template' // A function definition cannot start with a these keywords. return ParseDeclaration(Declarator::FileContext); + default: // We can't tell whether this is a function-definition or declaration yet. return ParseDeclarationOrFunctionDefinition(); diff --git a/clang/test/Parser/recovery-3.c b/clang/test/Parser/recovery-3.c index 40cf8cd709d..955d7288277 100644 --- a/clang/test/Parser/recovery-3.c +++ b/clang/test/Parser/recovery-3.c @@ -7,3 +7,8 @@ static char *f (char * (*g) (char **, int), char **p, ...) { s = g (p, __builtin_va_arg(v, int)); // expected-error {{identifier}} expected-warning {{extension}} } + +// PR3172 +} // expected-error {{expected external declaration}} + + |