Don't copy information from aliasee to alias.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 2 Dec 2015 20:03:17 +0000 (20:03 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 2 Dec 2015 20:03:17 +0000 (20:03 +0000)
They are independent.

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

lib/IR/Function.cpp
lib/IR/Globals.cpp
lib/Linker/LinkModules.cpp
test/Linker/Inputs/comdat14.ll
test/Linker/comdat14.ll

index 97e2a84a5cef98cb4ab7d1707b0a89872aebea33..5e4d2d2054eb54ef46bab7d45697d02b9984314a 100644 (file)
@@ -411,12 +411,14 @@ void Function::clearGC() {
   }
 }
 
-/// copyAttributesFrom - copy all additional attributes (those not needed to
-/// create a Function) from the Function Src to this one.
+/// Copy all additional attributes (those not needed to create a Function) from
+/// the Function Src to this one.
 void Function::copyAttributesFrom(const GlobalValue *Src) {
-  assert(isa<Function>(Src) && "Expected a Function!");
   GlobalObject::copyAttributesFrom(Src);
-  const Function *SrcF = cast<Function>(Src);
+  const Function *SrcF = dyn_cast<Function>(Src);
+  if (!SrcF)
+    return;
+
   setCallingConv(SrcF->getCallingConv());
   setAttributes(SrcF->getAttributes());
   if (SrcF->hasGC())
index 8fde4b8e9d77546875e1596b2884bd00ed019552..c538c7baa1feba5928ecc86a0176a5253ea3a216 100644 (file)
@@ -97,10 +97,11 @@ void GlobalObject::setGlobalObjectSubClassData(unsigned Val) {
 }
 
 void GlobalObject::copyAttributesFrom(const GlobalValue *Src) {
-  const auto *GV = cast<GlobalObject>(Src);
-  GlobalValue::copyAttributesFrom(GV);
-  setAlignment(GV->getAlignment());
-  setSection(GV->getSection());
+  GlobalValue::copyAttributesFrom(Src);
+  if (const auto *GV = dyn_cast<GlobalObject>(Src)) {
+    setAlignment(GV->getAlignment());
+    setSection(GV->getSection());
+  }
 }
 
 const char *GlobalValue::getSection() const {
@@ -216,14 +217,14 @@ void GlobalVariable::setInitializer(Constant *InitVal) {
   }
 }
 
-/// copyAttributesFrom - copy all additional attributes (those not needed to
-/// create a GlobalVariable) from the GlobalVariable Src to this one.
+/// Copy all additional attributes (those not needed to create a GlobalVariable)
+/// from the GlobalVariable Src to this one.
 void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) {
-  assert(isa<GlobalVariable>(Src) && "Expected a GlobalVariable!");
   GlobalObject::copyAttributesFrom(Src);
-  const GlobalVariable *SrcVar = cast<GlobalVariable>(Src);
-  setThreadLocalMode(SrcVar->getThreadLocalMode());
-  setExternallyInitialized(SrcVar->isExternallyInitialized());
+  if (const GlobalVariable *SrcVar = dyn_cast<GlobalVariable>(Src)) {
+    setThreadLocalMode(SrcVar->getThreadLocalMode());
+    setExternallyInitialized(SrcVar->isExternallyInitialized());
+  }
 }
 
 
index 1a82bbc7c90e7462180ece687b027bf250b643ce..3e54e279573e249b457d7b148d829172b9a60f50 100644 (file)
@@ -593,12 +593,7 @@ static void forceRenaming(GlobalValue *GV, StringRef Name) {
 /// from the SrcGV to the DestGV.
 void ModuleLinker::copyGVAttributes(GlobalValue *NewGV,
                                     const GlobalValue *SrcGV) {
-  auto *GA = dyn_cast<GlobalAlias>(SrcGV);
-  if (GA && !dyn_cast<GlobalAlias>(NewGV)) {
-    // FIXME: this is likelly bogus:
-    NewGV->copyAttributesFrom(GA->getBaseObject());
-  } else
-    NewGV->copyAttributesFrom(SrcGV);
+  NewGV->copyAttributesFrom(SrcGV);
   forceRenaming(NewGV, getName(SrcGV));
 }
 
index 7243ff864441a458d495fbb726991c8f503d1c1a..5e79fbcdacc17f061fc988e88d6cfc6d500f4505 100644 (file)
@@ -1,6 +1,6 @@
 $c = comdat any
 
-@v2 = weak global i32 0, comdat ($c)
+@v2 = weak dllexport global i32 0, comdat ($c)
 define i32* @f2() {
   ret i32* @v2
 }
index 70d1142bdf924008187555c629ff31dcbe46cf0a..793f8573a1f578b6c3adca8e1b131eca820b3f86 100644 (file)
@@ -5,5 +5,5 @@ $c = comdat any
 @v = global i32 0, comdat ($c)
 
 ; CHECK: @v = global i32 0, comdat($c)
-; CHECK: @v2 = extern_weak global i32
+; CHECK: @v2 = extern_weak dllexport global i32
 ; CHECK: @v3 = extern_weak global i32