[cfe-commits] r45975 - in /cfe/trunk: Sema/SemaDecl.cpp test/Sema/merge-decls.c
Steve Naroff
snaroff at apple.com
Mon Jan 14 12:51:30 PST 2008
Author: snaroff
Date: Mon Jan 14 14:51:29 2008
New Revision: 45975
URL: http://llvm.org/viewvc/llvm-project?rev=45975&view=rev
Log:
Fix crasher when redefining functions. Not 100% pleased with this solution, but it is clearly an improvement. Will discuss with Chris later.
Modified:
cfe/trunk/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/merge-decls.c
Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=45975&r1=45974&r2=45975&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Mon Jan 14 14:51:29 2008
@@ -245,16 +245,12 @@
if (OldQType.getTypePtr()->getTypeClass() == Type::FunctionNoProto &&
Old->getResultType() == New->getResultType())
return New;
- // Function types need to be compatible, not identical. This handles
- // duplicate function decls like "void f(int); void f(enum X);" properly.
- if (Context.functionTypesAreCompatible(OldQType, NewQType))
- return New;
}
+ // Function types need to be compatible, not identical. This handles
+ // duplicate function decls like "void f(int); void f(enum X);" properly.
+ if (Context.functionTypesAreCompatible(OldQType, NewQType))
+ return New;
- if (New->getBody() == 0 && OldQType == NewQType) {
- return 0;
- }
-
// TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
// TODO: This is totally simplistic. It should handle merging functions
// together etc, merging extern int X; int X; ...
@@ -950,9 +946,20 @@
}
Scope *GlobalScope = FnBodyScope->getParent();
-
+
+ // See if this is a redefinition.
+ ScopedDecl *PrevDcl = LookupScopedDecl(D.getIdentifier(), Decl::IDNS_Ordinary,
+ D.getIdentifierLoc(), GlobalScope);
+ if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(PrevDcl)) {
+ if (FD->getBody()) {
+ Diag(D.getIdentifierLoc(), diag::err_redefinition,
+ D.getIdentifier()->getName());
+ Diag(FD->getLocation(), diag::err_previous_definition);
+ }
+ }
FunctionDecl *FD =
static_cast<FunctionDecl*>(ActOnDeclarator(GlobalScope, D, 0));
+ assert(FD != 0 && "ActOnDeclarator() didn't return a FunctionDecl");
CurFunctionDecl = FD;
// Create Decl objects for each parameter, adding them to the FunctionDecl.
Modified: cfe/trunk/test/Sema/merge-decls.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/merge-decls.c?rev=45975&r1=45974&r2=45975&view=diff
==============================================================================
--- cfe/trunk/test/Sema/merge-decls.c (original)
+++ cfe/trunk/test/Sema/merge-decls.c Mon Jan 14 14:51:29 2008
@@ -1,8 +1,19 @@
// RUN: clang %s -verify -fsyntax-only
void foo(void);
-void foo(void) {} // expected-error{{previous definition is here}}
-void foo(void);
+void foo(void) {}
void foo(void);
+void foo(void); // expected-error{{previous definition is here}}
void foo(int); // expected-error {{redefinition of 'foo'}}
+
+int funcdef()
+{
+ return 0;
+}
+
+int funcdef();
+
+int funcdef2() { return 0; } // expected-error{{previous definition is here}}
+int funcdef2() { return 0; } // expected-error {{redefinition of 'funcdef2'}}
+
More information about the cfe-commits
mailing list