}
}
-/// 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())
}
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 {
}
}
-/// 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());
+ }
}
/// 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));
}
$c = comdat any
-@v2 = weak global i32 0, comdat ($c)
+@v2 = weak dllexport global i32 0, comdat ($c)
define i32* @f2() {
ret i32* @v2
}
@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