summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-04-05 05:52:15 +0000
committerChris Lattner <sabre@nondot.org>2008-04-05 05:52:15 +0000
commit94fc8063b4e4635bd18ea2b9cf76b4a71685b5ca (patch)
tree537556bb09f188d8d649bae16a4f40ce96b4391e /clang/lib/Parse/Parser.cpp
parent8519c0ead83135fbf712aceac0db281d2800438f (diff)
downloadbcm5719-llvm-94fc8063b4e4635bd18ea2b9cf76b4a71685b5ca.tar.gz
bcm5719-llvm-94fc8063b4e4635bd18ea2b9cf76b4a71685b5ca.zip
Step #1 to fixing PR2012: c89 allows declspecs to be completely
missing from function definitions only. If we see a function definiton with missing declspecs, just fudge in an int. llvm-svn: 49250
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
-rw-r--r--clang/lib/Parse/Parser.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 703144b3c44..76091245b55 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -356,8 +356,10 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() {
/// compound-statement in function-definition.
///
/// function-definition: [C99 6.9.1]
-/// declaration-specifiers[opt] declarator declaration-list[opt]
-/// compound-statement
+/// decl-specs declarator declaration-list[opt] compound-statement
+/// [C90] function-definition: [C99 6.7.1] - implicit int result
+/// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement
+///
/// declaration: [C99 6.7]
/// declaration-specifiers init-declarator-list[opt] ';'
/// [!C99] init-declarator-list ';' [TODO: warn in c99 mode]
@@ -451,8 +453,10 @@ Parser::DeclTy *Parser::ParseDeclarationOrFunctionDefinition() {
/// Declarator is well formed. If this is a K&R-style function, read the
/// parameters declaration-list, then start the compound-statement.
///
-/// declaration-specifiers[opt] declarator declaration-list[opt]
-/// compound-statement [TODO]
+/// function-definition: [C99 6.9.1]
+/// decl-specs declarator declaration-list[opt] compound-statement
+/// [C90] function-definition: [C99 6.7.1] - implicit int result
+/// [C90] decl-specs[opt] declarator declaration-list[opt] compound-statement
///
Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) {
const DeclaratorChunk &FnTypeInfo = D.getTypeObject(0);
@@ -460,6 +464,15 @@ Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) {
"This isn't a function declarator!");
const DeclaratorChunk::FunctionTypeInfo &FTI = FnTypeInfo.Fun;
+ // If this is C90 and the declspecs were completely missing, fudge in an
+ // implicit int. We do this here because this is the only place where
+ // declaration-specifiers are completely optional in the grammar.
+ if (getLang().isC90() && !D.getDeclSpec().getParsedSpecifiers() == 0) {
+ const char *PrevSpec;
+ D.getDeclSpec().SetTypeSpecType(DeclSpec::TST_int, D.getIdentifierLoc(),
+ PrevSpec);
+ }
+
// If this declaration was formed with a K&R-style identifier list for the
// arguments, parse declarations for all of the args next.
// int foo(a,b) int a; float b; {}
OpenPOWER on IntegriCloud