[cfe-commits] r49250 - in /cfe/trunk: include/clang/Basic/LangOptions.h lib/Parse/Parser.cpp test/Sema/c89.c
Chris Lattner
sabre at nondot.org
Fri Apr 4 22:52:15 PDT 2008
Author: lattner
Date: Sat Apr 5 00:52:15 2008
New Revision: 49250
URL: http://llvm.org/viewvc/llvm-project?rev=49250&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/test/Sema/c89.c
Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=49250&r1=49249&r2=49250&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Sat Apr 5 00:52:15 2008
@@ -49,6 +49,8 @@
LaxVectorConversions = 0;
}
+ bool isC90() const { return !C99 && !CPlusPlus; }
+
/// Emit - Emit this LangOptions object to bitcode.
void Emit(llvm::Serializer& S) const;
Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=49250&r1=49249&r2=49250&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Sat Apr 5 00:52:15 2008
@@ -356,8 +356,10 @@
/// 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 @@
/// 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 @@
"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; {}
Modified: cfe/trunk/test/Sema/c89.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/c89.c?rev=49250&r1=49249&r2=49250&view=diff
==============================================================================
--- cfe/trunk/test/Sema/c89.c (original)
+++ cfe/trunk/test/Sema/c89.c Sat Apr 5 00:52:15 2008
@@ -33,3 +33,9 @@
/* PR2041 */
int *restrict;
int *__restrict; /* expected-error {{expected identifier}} */
+
+
+/* Implicit int, always ok */
+foo() {}
+
+
More information about the cfe-commits
mailing list