[cfe-commits] r60719 - in /cfe/trunk: lib/Parse/Parser.cpp test/Parser/recovery-3.c
Chris Lattner
sabre at nondot.org
Mon Dec 8 13:59:01 PST 2008
Author: lattner
Date: Mon Dec 8 15:59:01 2008
New Revision: 60719
URL: http://llvm.org/viewvc/llvm-project?rev=60719&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/test/Parser/recovery-3.c
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=60719&r1=60718&r2=60719&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Mon Dec 8 15:59:01 2008
@@ -295,6 +295,7 @@
}
/// ParseExternalDeclaration:
+///
/// external-declaration: [C99 6.9], declaration: [C++ dcl.dcl]
/// function-definition
/// declaration
@@ -318,6 +319,13 @@
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 @@
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();
Modified: cfe/trunk/test/Parser/recovery-3.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/recovery-3.c?rev=60719&r1=60718&r2=60719&view=diff
==============================================================================
--- cfe/trunk/test/Parser/recovery-3.c (original)
+++ cfe/trunk/test/Parser/recovery-3.c Mon Dec 8 15:59:01 2008
@@ -7,3 +7,8 @@
s = g (p, __builtin_va_arg(v, int)); // expected-error {{identifier}} expected-warning {{extension}}
}
+
+// PR3172
+} // expected-error {{expected external declaration}}
+
+
More information about the cfe-commits
mailing list