[llvm] r254541 - Don't copy information from aliasee to alias.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 2 12:03:18 PST 2015


Author: rafael
Date: Wed Dec  2 14:03:17 2015
New Revision: 254541

URL: http://llvm.org/viewvc/llvm-project?rev=254541&view=rev
Log:
Don't copy information from aliasee to alias.

They are independent.

Modified:
    llvm/trunk/lib/IR/Function.cpp
    llvm/trunk/lib/IR/Globals.cpp
    llvm/trunk/lib/Linker/LinkModules.cpp
    llvm/trunk/test/Linker/Inputs/comdat14.ll
    llvm/trunk/test/Linker/comdat14.ll

Modified: llvm/trunk/lib/IR/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Function.cpp?rev=254541&r1=254540&r2=254541&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Function.cpp (original)
+++ llvm/trunk/lib/IR/Function.cpp Wed Dec  2 14:03:17 2015
@@ -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())

Modified: llvm/trunk/lib/IR/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Globals.cpp?rev=254541&r1=254540&r2=254541&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Globals.cpp (original)
+++ llvm/trunk/lib/IR/Globals.cpp Wed Dec  2 14:03:17 2015
@@ -97,10 +97,11 @@ void GlobalObject::setGlobalObjectSubCla
 }
 
 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(Cons
   }
 }
 
-/// 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());
+  }
 }
 
 

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=254541&r1=254540&r2=254541&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Wed Dec  2 14:03:17 2015
@@ -593,12 +593,7 @@ static void forceRenaming(GlobalValue *G
 /// 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));
 }
 

Modified: llvm/trunk/test/Linker/Inputs/comdat14.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/comdat14.ll?rev=254541&r1=254540&r2=254541&view=diff
==============================================================================
--- llvm/trunk/test/Linker/Inputs/comdat14.ll (original)
+++ llvm/trunk/test/Linker/Inputs/comdat14.ll Wed Dec  2 14:03:17 2015
@@ -1,6 +1,6 @@
 $c = comdat any
 
- at v2 = weak global i32 0, comdat ($c)
+ at v2 = weak dllexport global i32 0, comdat ($c)
 define i32* @f2() {
   ret i32* @v2
 }

Modified: llvm/trunk/test/Linker/comdat14.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/comdat14.ll?rev=254541&r1=254540&r2=254541&view=diff
==============================================================================
--- llvm/trunk/test/Linker/comdat14.ll (original)
+++ llvm/trunk/test/Linker/comdat14.ll Wed Dec  2 14:03:17 2015
@@ -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




More information about the llvm-commits mailing list