Skip to content

Commit 42a3a3b

Browse files
authored
[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.
1 parent e38c8bd commit 42a3a3b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void splitAndWriteThinLTOBitcode(
329329
// comdat in MergedM to keep the comdat together.
330330
DenseSet<const Comdat *> MergedMComdats;
331331
for (GlobalVariable &GV : M.globals())
332-
if (HasTypeMetadata(&GV)) {
332+
if (!GV.isDeclaration() && HasTypeMetadata(&GV)) {
333333
if (const auto *C = GV.getComdat())
334334
MergedMComdats.insert(C);
335335
forEachVirtualFunction(GV.getInitializer(), [&](Function *F) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
;; Generating bitcode files with split LTO modules should not crash if there are
2+
;; typed declarations in sources.
3+
4+
; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o - %s
5+
6+
@_ZTV3Foo = external constant { [3 x ptr] }, !type !0
7+
8+
define void @Bar() {
9+
ret void
10+
}
11+
12+
!0 = !{i64 16, !"_ZTS3Foo"}

0 commit comments

Comments
 (0)