According to the IR verifier, "Declaration[s] may not be in a Comdat!"
Differential Revision: https://reviews.llvm.org/
D142443
assert(!I->second->isDeclaration() &&
"Discard should only apply to definitions");
I->second->setLinkage(GlobalValue::AvailableExternallyLinkage);
+ // According to the IR verifier, "Declaration[s] may not be in a Comdat!"
+ // Remove it, if this is a GlobalObject.
+ if (auto *GO = dyn_cast<GlobalObject>(I->second))
+ GO->setComdat(nullptr);
SymbolToDefinition.erase(I);
}
--- /dev/null
+$c = comdat any
+
+define i32 @f() comdat($c) {
+entry:
+ ret i32 0
+}
--- /dev/null
+; RUN: lli -extra-module %p/Inputs/weak-comdat-def.ll %s
+
+$c = comdat any
+
+define weak i32 @f() comdat($c) {
+entry:
+ ret i32 0
+}
+
+define i32 @main() {
+entry:
+ %0 = call i32 @f()
+ ret i32 %0
+}