[llvm] [ThinLTOBitcodeWriter] Do not crash on a typed declaration (PR #69564)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 18 23:59:52 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lto
Author: Igor Kudrin (igorkudrin)
<details>
<summary>Changes</summary>
This fixes a crash when `splitAndWriteThinLTOBitcode()` hits a declaration with type metadata. For example, such declarations can be generated by the `EliminateAvailableExternally` pass.
---
Full diff: https://github.com/llvm/llvm-project/pull/69564.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp (+1-1)
- (added) llvm/test/Transforms/ThinLTOBitcodeWriter/split-typed-decl.ll (+12)
``````````diff
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..033d2d0cbd50b39
--- /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 -passes=elim-avail-extern --thinlto-bc --thinlto-split-lto-unit -o - %s
+
+ at _ZTV3Foo = available_externally constant { [3 x ptr] } zeroinitializer, align 8, !type !0
+
+define void @Bar() {
+ ret void
+}
+
+!0 = !{i64 16, !"_ZTS3Foo"}
``````````
</details>
https://github.com/llvm/llvm-project/pull/69564
More information about the llvm-commits
mailing list