[cfe-commits] r166032 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/attr-weakref.c

Joerg Sonnenberger joerg at bec.de
Tue Oct 16 10:45:28 PDT 2012


Author: joerg
Date: Tue Oct 16 12:45:27 2012
New Revision: 166032

URL: http://llvm.org/viewvc/llvm-project?rev=166032&view=rev
Log:
When using a symbol with attribute weakref, search for it first and
don't try the normal GetOrCreateLLVM. The latter could drop the weak
atrtibute on the second reference, if there is no explicit declaration
of the aliasee.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/attr-weakref.c

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=166032&r1=166031&r2=166032&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Oct 16 12:45:27 2012
@@ -884,6 +884,10 @@
 
   // See if there is already something with the target's name in the module.
   llvm::GlobalValue *Entry = GetGlobalValue(AA->getAliasee());
+  if (Entry) {
+    unsigned AS = getContext().getTargetAddressSpace(VD->getType());
+    return llvm::ConstantExpr::getBitCast(Entry, DeclTy->getPointerTo(AS));
+  }
 
   llvm::Constant *Aliasee;
   if (isa<llvm::FunctionType>(DeclTy))
@@ -893,11 +897,10 @@
   else
     Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
                                     llvm::PointerType::getUnqual(DeclTy), 0);
-  if (!Entry) {
-    llvm::GlobalValue* F = cast<llvm::GlobalValue>(Aliasee);
-    F->setLinkage(llvm::Function::ExternalWeakLinkage);    
-    WeakRefReferences.insert(F);
-  }
+
+  llvm::GlobalValue* F = cast<llvm::GlobalValue>(Aliasee);
+  F->setLinkage(llvm::Function::ExternalWeakLinkage);
+  WeakRefReferences.insert(F);
 
   return Aliasee;
 }

Modified: cfe/trunk/test/CodeGen/attr-weakref.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-weakref.c?rev=166032&r1=166031&r2=166032&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/attr-weakref.c (original)
+++ cfe/trunk/test/CodeGen/attr-weakref.c Tue Oct 16 12:45:27 2012
@@ -53,6 +53,12 @@
   test6_f();
 }
 
+// CHECK: declare extern_weak void @test8_f()
+static void test8_g(void) __attribute__((weakref("test8_f")));
+void test8_h(void) {
+  if (test8_g)
+    test8_g();
+}
 // CHECK: declare extern_weak void @test7_f()
 void test7_f(void);
 static void test7_g(void) __attribute__((weakref("test7_f")));





More information about the cfe-commits mailing list