[cfe-commits] r106317 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CodeGen/regparm.c test/Sema/attr-regparm.c test/SemaCXX/attr-regparm.cpp

Douglas Gregor dgregor at apple.com
Fri Jun 18 14:30:25 PDT 2010


Author: dgregor
Date: Fri Jun 18 16:30:25 2010
New Revision: 106317

URL: http://llvm.org/viewvc/llvm-project?rev=106317&view=rev
Log:
Merge the "regparm" attribute from a previous declaration of a
function to redeclarations of that function. Fixes PR7025.

Added:
    cfe/trunk/test/SemaCXX/attr-regparm.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CodeGen/regparm.c
    cfe/trunk/test/Sema/attr-regparm.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=106317&r1=106316&r2=106317&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 18 16:30:25 2010
@@ -914,6 +914,10 @@
   "function with no prototype cannot use %0 calling convention">;
 def err_cconv_varargs : Error<
   "variadic function cannot use %0 calling convention">;
+def err_regparm_mismatch : Error<"function declared with with regparm(%0) "
+  "attribute was previously declared %plural{0:without the regparm|1:"
+  "with the regparm(1)|2:with the regparm(2)|3:with the regparm(3)|:with the"
+  "regparm}1 attribute">;
 
 def warn_impcast_vector_scalar : Warning<
   "implicit cast turns vector to scalar: %0 to %1">,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=106317&r1=106316&r2=106317&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jun 18 16:30:25 2010
@@ -1057,13 +1057,27 @@
   }
 
   // FIXME: diagnose the other way around?
-  if (OldType->getNoReturnAttr() &&
-      !NewType->getNoReturnAttr()) {
+  if (OldType->getNoReturnAttr() && !NewType->getNoReturnAttr()) {
     NewQType = Context.getNoReturnType(NewQType);
     New->setType(NewQType);
     assert(NewQType.isCanonical());
   }
 
+  // Merge regparm attribute.
+  if (OldType->getRegParmType() != NewType->getRegParmType()) {
+    if (NewType->getRegParmType()) {
+      Diag(New->getLocation(), diag::err_regparm_mismatch)
+        << NewType->getRegParmType()
+        << OldType->getRegParmType();
+      Diag(Old->getLocation(), diag::note_previous_declaration);      
+      return true;
+    }
+    
+    NewQType = Context.getRegParmType(NewQType, OldType->getRegParmType());
+    New->setType(NewQType);
+    assert(NewQType.isCanonical());    
+  }
+  
   if (getLangOptions().CPlusPlus) {
     // (C++98 13.1p2):
     //   Certain function declarations cannot be overloaded:

Modified: cfe/trunk/test/CodeGen/regparm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/regparm.c?rev=106317&r1=106316&r2=106317&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/regparm.c (original)
+++ cfe/trunk/test/CodeGen/regparm.c Fri Jun 18 16:30:25 2010
@@ -14,6 +14,11 @@
 static void FASTCALL
 reduced(char b, double c, foo* d, double e, int f);
 
+// PR7025
+void FASTCALL f1(int i, int j, int k);
+// CHECK: define void @f1(i32 inreg %i, i32 inreg %j, i32 %k)
+void f1(int i, int j, int k) { }
+
 int
 main(void) {
   // CHECK: call void @reduced(i8 signext inreg 0, {{.*}} %struct.anon* inreg null

Modified: cfe/trunk/test/Sema/attr-regparm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-regparm.c?rev=106317&r1=106316&r2=106317&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-regparm.c (original)
+++ cfe/trunk/test/Sema/attr-regparm.c Fri Jun 18 16:30:25 2010
@@ -1,7 +1,11 @@
 // RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
 
-__attribute((regparm(2))) int x(void);
-__attribute((regparm(1.0))) int x(void); // expected-error{{'regparm' attribute requires integer constant}}
-__attribute((regparm(-1))) int x(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
-__attribute((regparm(5))) int x(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
-__attribute((regparm(5,3))) int x(void); // expected-error{{attribute requires 1 argument(s)}}
+__attribute((regparm(2))) int x0(void);
+__attribute((regparm(1.0))) int x1(void); // expected-error{{'regparm' attribute requires integer constant}}
+__attribute((regparm(-1))) int x2(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
+__attribute((regparm(5))) int x3(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
+__attribute((regparm(5,3))) int x4(void); // expected-error{{attribute requires 1 argument(s)}}
+
+void __attribute__((regparm(3))) x5(int);
+void x5(int); // expected-note{{previous declaration is here}}
+void __attribute__((regparm(2))) x5(int); // expected-error{{function declared with with regparm(2) attribute was previously declared with the regparm(3) attribute}}

Added: cfe/trunk/test/SemaCXX/attr-regparm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-regparm.cpp?rev=106317&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-regparm.cpp (added)
+++ cfe/trunk/test/SemaCXX/attr-regparm.cpp Fri Jun 18 16:30:25 2010
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR7025
+struct X0 {
+  void __attribute__((regparm(3))) f0();
+  void __attribute__((regparm(3))) f1();
+  void __attribute__((regparm(3))) f2(); // expected-note{{previous declaration is here}}
+  void f3(); // expected-note{{previous declaration is here}}
+};
+
+void X0::f0() { }
+void __attribute__((regparm(3))) X0::f1() { }
+void __attribute__((regparm(2))) X0::f2() { } // expected-error{{function declared with with regparm(2) attribute was previously declared with the regparm(3) attribute}}
+void __attribute__((regparm(2))) X0::f3() { } // expected-error{{function declared with with regparm(2) attribute was previously declared without the regparm attribute}}





More information about the cfe-commits mailing list