[cfe-commits] r164454 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/builtins.c

Abramo Bagnara abramo.bagnara at bugseng.com
Sat Sep 22 02:05:22 PDT 2012


Author: abramo
Date: Sat Sep 22 04:05:22 2012
New Revision: 164454

URL: http://llvm.org/viewvc/llvm-project?rev=164454&view=rev
Log:
Avoid multiple atomic builtin declaration.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/builtins.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=164454&r1=164453&r2=164454&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Sat Sep 22 04:05:22 2012
@@ -1198,10 +1198,19 @@
   // concrete integer type we should convert to is.
   unsigned NewBuiltinID = BuiltinIndices[BuiltinIndex][SizeIndex];
   const char *NewBuiltinName = Context.BuiltinInfo.GetName(NewBuiltinID);
-  IdentifierInfo *NewBuiltinII = PP.getIdentifierInfo(NewBuiltinName);
-  FunctionDecl *NewBuiltinDecl =
-    cast<FunctionDecl>(LazilyCreateBuiltin(NewBuiltinII, NewBuiltinID,
-                                           TUScope, false, DRE->getLocStart()));
+  FunctionDecl *NewBuiltinDecl;
+  if (NewBuiltinID == BuiltinID)
+    NewBuiltinDecl = FDecl;
+  else {
+    // Perform builtin lookup to avoid redeclaring it.
+    DeclarationName DN(&Context.Idents.get(NewBuiltinName));
+    LookupResult Res(*this, DN, DRE->getLocStart(), LookupOrdinaryName);
+    LookupName(Res, TUScope, /*AllowBuiltinCreation=*/true);
+    assert(Res.getFoundDecl());
+    NewBuiltinDecl = dyn_cast<FunctionDecl>(Res.getFoundDecl());
+    if (NewBuiltinDecl == 0)
+      return ExprError();
+  }
 
   // The first argument --- the pointer --- has a fixed type; we
   // deduce the types of the rest of the arguments accordingly.  Walk

Modified: cfe/trunk/test/Sema/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/builtins.c?rev=164454&r1=164453&r2=164454&view=diff
==============================================================================
--- cfe/trunk/test/Sema/builtins.c (original)
+++ cfe/trunk/test/Sema/builtins.c Sat Sep 22 04:05:22 2012
@@ -51,6 +51,20 @@
   }
 }
 
+// overloaded atomics should be declared only once.
+void test9_1(volatile int* ptr, int val) {
+  __sync_fetch_and_add_4(ptr, val);
+}
+void test9_2(volatile int* ptr, int val) {
+  __sync_fetch_and_add(ptr, val);
+}
+void test9_3(volatile int* ptr, int val) {
+  __sync_fetch_and_add_4(ptr, val);
+  __sync_fetch_and_add(ptr, val);
+  __sync_fetch_and_add(ptr, val);
+  __sync_fetch_and_add_4(ptr, val);
+  __sync_fetch_and_add_4(ptr, val);
+}
 
 // rdar://7236819
 void test10(void) __attribute__((noreturn));





More information about the cfe-commits mailing list