[cfe-commits] r45789 - in /cfe/trunk: Sema/SemaDecl.cpp test/Sema/predefined-function.c
Steve Naroff
snaroff at apple.com
Wed Jan 9 15:34:56 PST 2008
Author: snaroff
Date: Wed Jan 9 17:34:55 2008
New Revision: 45789
URL: http://llvm.org/viewvc/llvm-project?rev=45789&view=rev
Log:
Fix Sema::ActOnDeclarator() to call MergeFunctionDecl for function decls that aren't in scope. Since C functions are in a flat namespace, we need to give them special treatment (when compared with variables and typedefs).
Modified:
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/predefined-function.c
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=45789&r1=45788&r2=45789&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Jan 9 17:34:55 2008
@@ -637,9 +637,6 @@
// See if this is a redefinition of a variable in the same scope.
ScopedDecl *PrevDecl = LookupScopedDecl(II, Decl::IDNS_Ordinary,
D.getIdentifierLoc(), S);
- if (PrevDecl && !S->isDeclScope(PrevDecl))
- PrevDecl = 0; // If in outer scope, it isn't the same thing.
-
ScopedDecl *New;
bool InvalidDecl = false;
@@ -653,8 +650,9 @@
// Handle attributes prior to checking for duplicates in MergeVarDecl
HandleDeclAttributes(NewTD, D.getDeclSpec().getAttributes(),
D.getAttributes());
- // Merge the decl with the existing one if appropriate.
- if (PrevDecl) {
+ // Merge the decl with the existing one if appropriate. If the decl is
+ // in an outer scope, it isn't the same thing.
+ if (PrevDecl && S->isDeclScope(PrevDecl)) {
NewTD = MergeTypeDefDecl(NewTD, PrevDecl);
if (NewTD == 0) return 0;
}
@@ -692,7 +690,8 @@
// Transfer ownership of DeclSpec attributes to FunctionDecl
D.getDeclSpec().clearAttributes();
- // Merge the decl with the existing one if appropriate.
+ // Merge the decl with the existing one if appropriate. Since C functions
+ // are in a flat namespace, make sure we consider decls in outer scopes.
if (PrevDecl) {
NewFD = MergeFunctionDecl(NewFD, PrevDecl);
if (NewFD == 0) return 0;
@@ -731,8 +730,9 @@
HandleDeclAttributes(NewVD, D.getDeclSpec().getAttributes(),
D.getAttributes());
- // Merge the decl with the existing one if appropriate.
- if (PrevDecl) {
+ // Merge the decl with the existing one if appropriate. If the decl is
+ // in an outer scope, it isn't the same thing.
+ if (PrevDecl && S->isDeclScope(PrevDecl)) {
NewVD = MergeVarDecl(NewVD, PrevDecl);
if (NewVD == 0) return 0;
}
Modified: cfe/trunk/test/Sema/predefined-function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/predefined-function.c?rev=45789&r1=45788&r2=45789&view=diff
==============================================================================
--- cfe/trunk/test/Sema/predefined-function.c (original)
+++ cfe/trunk/test/Sema/predefined-function.c Wed Jan 9 17:34:55 2008
@@ -4,9 +4,14 @@
enum Test {A=-1};
char *funk(enum Test x);
+int eli(float b); // expected-error {{previous definition is here}}
+int b(int c) {return 1;}
+
int foo();
int foo()
{
+ int eli(int (int)); // expected-error {{redefinition of 'eli'}}
+ eli(b);
return 0;
}
More information about the cfe-commits
mailing list