From 769efe621ab318cb9e245c613dad5da695316557 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 2 Dec 2015 20:03:17 +0000 Subject: [PATCH] Don't copy information from aliasee to alias. They are independent. llvm-svn: 254541 --- llvm/lib/IR/Function.cpp | 10 ++++++---- llvm/lib/IR/Globals.cpp | 21 +++++++++++---------- llvm/lib/Linker/LinkModules.cpp | 7 +------ llvm/test/Linker/Inputs/comdat14.ll | 2 +- llvm/test/Linker/comdat14.ll | 2 +- 5 files changed, 20 insertions(+), 22 deletions(-) diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 97e2a84a5cef..5e4d2d2054eb 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -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(Src) && "Expected a Function!"); GlobalObject::copyAttributesFrom(Src); - const Function *SrcF = cast(Src); + const Function *SrcF = dyn_cast(Src); + if (!SrcF) + return; + setCallingConv(SrcF->getCallingConv()); setAttributes(SrcF->getAttributes()); if (SrcF->hasGC()) diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index 8fde4b8e9d77..c538c7baa1fe 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -97,10 +97,11 @@ void GlobalObject::setGlobalObjectSubClassData(unsigned Val) { } void GlobalObject::copyAttributesFrom(const GlobalValue *Src) { - const auto *GV = cast(Src); - GlobalValue::copyAttributesFrom(GV); - setAlignment(GV->getAlignment()); - setSection(GV->getSection()); + GlobalValue::copyAttributesFrom(Src); + if (const auto *GV = dyn_cast(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(Src) && "Expected a GlobalVariable!"); GlobalObject::copyAttributesFrom(Src); - const GlobalVariable *SrcVar = cast(Src); - setThreadLocalMode(SrcVar->getThreadLocalMode()); - setExternallyInitialized(SrcVar->isExternallyInitialized()); + if (const GlobalVariable *SrcVar = dyn_cast(Src)) { + setThreadLocalMode(SrcVar->getThreadLocalMode()); + setExternallyInitialized(SrcVar->isExternallyInitialized()); + } } diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 1a82bbc7c90e..3e54e279573e 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -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(SrcGV); - if (GA && !dyn_cast(NewGV)) { - // FIXME: this is likelly bogus: - NewGV->copyAttributesFrom(GA->getBaseObject()); - } else - NewGV->copyAttributesFrom(SrcGV); + NewGV->copyAttributesFrom(SrcGV); forceRenaming(NewGV, getName(SrcGV)); } diff --git a/llvm/test/Linker/Inputs/comdat14.ll b/llvm/test/Linker/Inputs/comdat14.ll index 7243ff864441..5e79fbcdacc1 100644 --- a/llvm/test/Linker/Inputs/comdat14.ll +++ b/llvm/test/Linker/Inputs/comdat14.ll @@ -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 } diff --git a/llvm/test/Linker/comdat14.ll b/llvm/test/Linker/comdat14.ll index 70d1142bdf92..793f8573a1f5 100644 --- a/llvm/test/Linker/comdat14.ll +++ b/llvm/test/Linker/comdat14.ll @@ -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