[llvm] 42a3a3b - [ThinLTOBitcodeWriter] Do not crash on a typed declaration (#69564)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 23 14:29:56 PDT 2023
Author: Igor Kudrin
Date: 2023-10-24T04:29:53+07:00
New Revision: 42a3a3b3f0e16de5b6aa2bebcb6f794668426cbe
URL: https://github.com/llvm/llvm-project/commit/42a3a3b3f0e16de5b6aa2bebcb6f794668426cbe
DIFF: https://github.com/llvm/llvm-project/commit/42a3a3b3f0e16de5b6aa2bebcb6f794668426cbe.diff
LOG: [ThinLTOBitcodeWriter] Do not crash on a typed declaration (#69564)
This fixes a crash when `splitAndWriteThinLTOBitcode()` hits a
declaration with type metadata. For example, such declarations can be
generated by the `EliminateAvailableExternally` pass.
Added:
llvm/test/Transforms/ThinLTOBitcodeWriter/split-typed-decl.ll
Modified:
llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
index fc1e70b1b3d3d81..98ef2065d6d9492 100644
--- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
+++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
@@ -329,7 +329,7 @@ void splitAndWriteThinLTOBitcode(
// comdat in MergedM to keep the comdat together.
DenseSet<const Comdat *> MergedMComdats;
for (GlobalVariable &GV : M.globals())
- if (HasTypeMetadata(&GV)) {
+ if (!GV.isDeclaration() && HasTypeMetadata(&GV)) {
if (const auto *C = GV.getComdat())
MergedMComdats.insert(C);
forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
diff --git a/llvm/test/Transforms/ThinLTOBitcodeWriter/split-typed-decl.ll b/llvm/test/Transforms/ThinLTOBitcodeWriter/split-typed-decl.ll
new file mode 100644
index 000000000000000..ec96c1632586fbf
--- /dev/null
+++ b/llvm/test/Transforms/ThinLTOBitcodeWriter/split-typed-decl.ll
@@ -0,0 +1,12 @@
+;; Generating bitcode files with split LTO modules should not crash if there are
+;; typed declarations in sources.
+
+; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o - %s
+
+ at _ZTV3Foo = external constant { [3 x ptr] }, !type !0
+
+define void @Bar() {
+ ret void
+}
+
+!0 = !{i64 16, !"_ZTS3Foo"}
More information about the llvm-commits
mailing list