[llvm-branch-commits] [llvm] 055ee22 - [ORC] Drop Comdat when discarding IR symbol
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Feb 6 11:58:33 PST 2023
Author: Jonas Hahnfeld
Date: 2023-02-06T11:57:12-08:00
New Revision: 055ee2257ff2c3a9f06a25d0acc2951d0b7e2d1f
URL: https://github.com/llvm/llvm-project/commit/055ee2257ff2c3a9f06a25d0acc2951d0b7e2d1f
DIFF: https://github.com/llvm/llvm-project/commit/055ee2257ff2c3a9f06a25d0acc2951d0b7e2d1f.diff
LOG: [ORC] Drop Comdat when discarding IR symbol
According to the IR verifier, "Declaration[s] may not be in a Comdat!"
This is a re-commit of 76b3f0b4d5a0b8c54147c4c73a30892bbca76467 and
87d7838202267a011639fcbf97263556ccf091dc with updates to the test:
* Force emission of the extra-module, to trigger the bug after D138264,
by providing a second symbol @g, and making the comdat nodeduplicate.
(Technically only one is needed, but two should be safer.)
* Name the comdat $f to avoid failure on Windows:
LLVM ERROR: Associative COMDAT symbol 'c' does not exist.
* Mark the test as UNSUPPORTED on macOS, MachO doesn't support COMDATs.
Differential Revision: https://reviews.llvm.org/D142443
(cherry picked from commit 50ca8b3e8726180a74fcbc4611893f19189b97c0)
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..d35ead08ff1e7
--- /dev/null
+++ b/llvm/test/ExecutionEngine/Orc/Inputs/weak-comdat-def.ll
@@ -0,0 +1,12 @@
+define i32 @g() {
+entry:
+ ret i32 0
+}
+
+$f = comdat nodeduplicate
+
+define i32 @f() comdat {
+entry:
+ %0 = call i32 @g()
+ 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..e1e1ab02e2981
--- /dev/null
+++ b/llvm/test/ExecutionEngine/Orc/weak-comdat.ll
@@ -0,0 +1,18 @@
+; RUN: lli -extra-module %p/Inputs/weak-comdat-def.ll %s
+; UNSUPPORTED: target={{.*}}-darwin{{.*}}
+
+declare i32 @g()
+
+$f = comdat nodeduplicate
+
+define weak i32 @f() comdat {
+entry:
+ %0 = call i32 @g()
+ ret i32 %0
+}
+
+define i32 @main() {
+entry:
+ %0 = call i32 @f()
+ ret i32 %0
+}
More information about the llvm-branch-commits
mailing list