Fix another llvm.ctors merging bug.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 30 Nov 2015 18:54:24 +0000 (18:54 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 30 Nov 2015 18:54:24 +0000 (18:54 +0000)
We were not looking past casts to see if an element should be included
or not.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254313 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Linker/LinkModules.cpp
test/Linker/Inputs/ctors3.ll [new file with mode: 0644]
test/Linker/ctors3.ll [new file with mode: 0644]

index 6b60379803e15e367e17251954ea5a18b89a87e1..cdf1decc81319acd1f94a519590794f2e52858de 100644 (file)
@@ -410,7 +410,7 @@ class ModuleLinker {
   std::vector<AppendingVarInfo> AppendingVars;
 
   // Set of items not to link in from source.
-  SmallPtrSet<const Value *, 16> DoNotLinkFromSource;
+  SmallPtrSet<const GlobalValue *, 16> DoNotLinkFromSource;
 
   DiagnosticHandlerFunction DiagnosticHandler;
 
@@ -1512,7 +1512,8 @@ void ModuleLinker::linkAppendingVarInit(AppendingVarInfo &AVI) {
 
   for (auto *V : SrcElements) {
     if (IsNewStructor) {
-      Constant *Key = V->getAggregateElement(2);
+      auto *Key =
+          dyn_cast<GlobalValue>(V->getAggregateElement(2)->stripPointerCasts());
       if (DoNotLinkFromSource.count(Key))
         continue;
     }
diff --git a/test/Linker/Inputs/ctors3.ll b/test/Linker/Inputs/ctors3.ll
new file mode 100644 (file)
index 0000000..449ccbd
--- /dev/null
@@ -0,0 +1,7 @@
+$foo = comdat any
+%t = type { i8 }
+@foo = global %t zeroinitializer, comdat
+@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @bar, i8* getelementptr (%t, %t* @foo, i32 0, i32 0) }]
+define internal void @bar() comdat($foo) {
+  ret void
+}
diff --git a/test/Linker/ctors3.ll b/test/Linker/ctors3.ll
new file mode 100644 (file)
index 0000000..e62b92d
--- /dev/null
@@ -0,0 +1,8 @@
+; RUN: llvm-link -S %s %p/Inputs/ctors3.ll -o - | FileCheck %s
+
+$foo = comdat any
+%t = type { i8 }
+@foo = global %t zeroinitializer, comdat
+
+; CHECK: @foo = global %t zeroinitializer, comdat
+; CHECK: @llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer