-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[ThinLTOBitcodeWriter] Do not crash on a typed declaration #69564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-lto Author: Igor Kudrin (igorkudrin) ChangesThis fixes a crash when Full diff: https://github.com/llvm/llvm-project/pull/69564.diff 2 Files Affected:
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
+
+@_ZTV3Foo = available_externally constant { [3 x ptr] } zeroinitializer, align 8, !type !0
+
+define void @Bar() {
+ ret void
+}
+
+!0 = !{i64 16, !"_ZTS3Foo"}
|
Normally we explicitly disable the EliminateAvailableExternally pass before writing ThinLTO bitcode as we do not want these eliminated before LTO (see llvm-project/llvm/lib/Passes/PassBuilderPipelines.cpp Lines 1304 to 1314 in 6b8a142
What configuration provoked this failure? |
The problem is probably not something that can be seen in the standard usage. We came across it while working on a downstream tool that runs some optimizations, including the LTO pipeline, and saves bitcode output files for later use. In our case, we can avoid the issue by excluding the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm but a suggestion for simplifying the test
This fixes a crash when `splitAndWriteThinLTOBitcode()` hits a declaration with type metadata. For example, such declarations can be generated by the `EliminateAvailableExternally` pass.
03a4453
to
2221e59
Compare
This fixes a crash when
splitAndWriteThinLTOBitcode()
hits a declaration with type metadata. For example, such declarations can be generated by theEliminateAvailableExternally
pass.