[cfe-commits] r44253 - in /cfe/trunk: Sema/SemaDecl.cpp test/Sema/predefined-function.c

Chris Lattner sabre at nondot.org
Tue Nov 20 11:04:50 PST 2007


Author: lattner
Date: Tue Nov 20 13:04:50 2007
New Revision: 44253

URL: http://llvm.org/viewvc/llvm-project?rev=44253&view=rev
Log:
Improve function decl merging, patch by Oliver Hunt!

Added:
    cfe/trunk/test/Sema/predefined-function.c
Modified:
    cfe/trunk/Sema/SemaDecl.cpp

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=44253&r1=44252&r2=44253&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Tue Nov 20 13:04:50 2007
@@ -238,16 +238,23 @@
     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;
+  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 && 
-      Old->getCanonicalType() == New->getCanonicalType()) {
+  if (New->getBody() == 0 && OldQType == NewQType) {
     return 0;
   }
   

Added: cfe/trunk/test/Sema/predefined-function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/predefined-function.c?rev=44253&view=auto

==============================================================================
--- cfe/trunk/test/Sema/predefined-function.c (added)
+++ cfe/trunk/test/Sema/predefined-function.c Tue Nov 20 13:04:50 2007
@@ -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;
+}





More information about the cfe-commits mailing list