aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-11-20 19:04:50 +0000
committerChris Lattner <sabre@nondot.org>2007-11-20 19:04:50 +0000
commit5519644892c1bcc9111418134601a287b223dcc2 (patch)
tree25ce9733d2254e63312c2c30f4bbd6f14c066902
parent74c43a0967d07572dd6907776d91cdb2b2e7179a (diff)
Improve function decl merging, patch by Oliver Hunt!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44253 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Sema/SemaDecl.cpp27
-rw-r--r--test/Sema/predefined-function.c29
2 files changed, 46 insertions, 10 deletions
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 2c3b335fb7..30505d66cd 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -238,16 +238,23 @@ FunctionDecl *Sema::MergeFunctionDecl(FunctionDecl *New, ScopedDecl *OldD) {
return New;
}
- // This is not right, but it's a start. If 'Old' is a function prototype with
- // the same type as 'New', silently allow this. FIXME: We should link up decl
- // objects here.
- if (Old->getBody() == 0 &&
- Old->getCanonicalType() == New->getCanonicalType()) {
- return New;
- }
-
- if (New->getBody() == 0 &&
- Old->getCanonicalType() == New->getCanonicalType()) {
+ QualType OldQType = Old->getCanonicalType();
+ QualType NewQType = New->getCanonicalType();
+
+ // This is not right, but it's a start.
+ // If Old is a function prototype with no defined arguments we only compare
+ // the return type; If arguments are defined on the prototype we validate the
+ // entire function type.
+ // FIXME: We should link up decl objects here.
+ if (Old->getBody() == 0) {
+ if (OldQType.getTypePtr()->getTypeClass() == Type::FunctionNoProto &&
+ Old->getResultType() == New->getResultType())
+ return New;
+ if (OldQType == NewQType)
+ return New;
+ }
+
+ if (New->getBody() == 0 && OldQType == NewQType) {
return 0;
}
diff --git a/test/Sema/predefined-function.c b/test/Sema/predefined-function.c
new file mode 100644
index 0000000000..bca25fb995
--- /dev/null
+++ b/test/Sema/predefined-function.c
@@ -0,0 +1,29 @@
+// RUN: clang -fsyntax-only -verify -pedantic %s
+
+int foo();
+int foo()
+{
+ return 0;
+}
+
+int bar();
+int bar(int i) // expected-error {{previous definition is here}}
+{
+ return 0;
+}
+int bar() // expected-error {{redefinition of 'bar'}}
+{
+ return 0;
+}
+
+int foobar(int); // expected-error {{previous definition is here}}
+int foobar() // expected-error {{redefinition of 'foobar'}}
+{
+ return 0;
+}
+
+int wibble(); // expected-error {{previous definition is here}}
+float wibble() // expected-error {{redefinition of 'wibble'}}
+{
+ return 0.0f;
+}