[llvm] 76b3f0b - [ORC] Drop Comdat when discarding IR symbol
Jonas Hahnfeld via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 2 23:42:21 PST 2023
Author: Jonas Hahnfeld
Date: 2023-02-03T08:41:58+01:00
New Revision: 76b3f0b4d5a0b8c54147c4c73a30892bbca76467
URL: https://github.com/llvm/llvm-project/commit/76b3f0b4d5a0b8c54147c4c73a30892bbca76467
DIFF: https://github.com/llvm/llvm-project/commit/76b3f0b4d5a0b8c54147c4c73a30892bbca76467.diff
LOG: [ORC] Drop Comdat when discarding IR symbol
According to the IR verifier, "Declaration[s] may not be in a Comdat!"
Differential Revision: https://reviews.llvm.org/D142443
Added:
llvm/test/ExecutionEngine/Orc/Inputs/weak-comdat-def.ll
llvm/test/ExecutionEngine/Orc/weak-comdat.ll
Modified:
llvm/lib/ExecutionEngine/Orc/Layer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ExecutionEngine/Orc/Layer.cpp b/llvm/lib/ExecutionEngine/Orc/Layer.cpp
index 95380d912392e..3368d3276cb37 100644
--- a/llvm/lib/ExecutionEngine/Orc/Layer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Layer.cpp
@@ -125,6 +125,10 @@ void IRMaterializationUnit::discard(const JITDylib &JD,
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);
}
diff --git a/llvm/test/ExecutionEngine/Orc/Inputs/weak-comdat-def.ll b/llvm/test/ExecutionEngine/Orc/Inputs/weak-comdat-def.ll
new file mode 100644
index 0000000000000..9c308a3c9a1a5
--- /dev/null
+++ b/llvm/test/ExecutionEngine/Orc/Inputs/weak-comdat-def.ll
@@ -0,0 +1,6 @@
+$c = comdat any
+
+define i32 @f() comdat($c) {
+entry:
+ ret i32 0
+}
diff --git a/llvm/test/ExecutionEngine/Orc/weak-comdat.ll b/llvm/test/ExecutionEngine/Orc/weak-comdat.ll
new file mode 100644
index 0000000000000..d11e46246f6a4
--- /dev/null
+++ b/llvm/test/ExecutionEngine/Orc/weak-comdat.ll
@@ -0,0 +1,14 @@
+; 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
+}
More information about the llvm-commits
mailing list