Skip to content

Commit 58211f5

Browse files
authored
[llvm-reduce] Fix incorrectly ignored null MD in ReduceDIMetadata (llvm#108541)
Commit c2e62c7 updated the ReduceDIMetadata pass to be able to remove DIGlobalVariableExpressions from MDNode operands; it also accidentally prevented null operands from being preserved, which results in an assertion being triggered: `Targets == NoChunksCounter.count() && "number of chunks changes when reducing"' This patch allows us to correctly preserve null operands once again. I've not got a test case for this yet - I'm hoping this patch is just trivially correct as-is, because I've not got the hang of reducing a test case for llvm-reduce yet, but I can get a test case generated if needed.
1 parent 12fe15f commit 58211f5

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; RUN: llvm-reduce %s -o %t --delta-passes=di-metadata --test FileCheck --test-arg %s --test-arg --input-file --abort-on-invalid-reduction
2+
; CHECK: , !dbg !11
3+
4+
;; Tests for the bug fixed in PR#108541, where the presence of null metadata
5+
;; could result in a crash.
6+
7+
define i1 @ham() {
8+
bb:
9+
%call = call fastcc i32 @hoge()
10+
ret i1 false
11+
}
12+
13+
define fastcc i32 @hoge() {
14+
bb:
15+
br i1 poison, label %bb1, label %bb2
16+
17+
bb1: ; preds = %bb
18+
br i1 false, label %bb2, label %bb2, !dbg !11
19+
20+
bb2: ; preds = %bb1, %bb1, %bb
21+
ret i32 0
22+
}
23+
24+
!llvm.dbg.cu = !{!0}
25+
!llvm.module.flags = !{!10}
26+
27+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, globals: !2, imports: !3, splitDebugInlining: false, nameTableKind: None)
28+
!1 = !DIFile(filename: "108541-metadata-crash.cpp", directory: "/tmp")
29+
!2 = !{}
30+
!3 = !{!4}
31+
!4 = !DIImportedEntity(tag: DW_TAG_imported_declaration, scope: !5, entity: !6, file: !7, line: 134)
32+
!5 = !DINamespace(name: "std", scope: null)
33+
!6 = !DISubprogram(name: "abort", scope: !7, file: !7, line: 730, type: !8, flags: DIFlagPrototyped | DIFlagNoReturn, spFlags: DISPFlagOptimized)
34+
!7 = !DIFile(filename: "108541-metadata-crash.cpp", directory: "")
35+
!8 = !DISubroutineType(types: !9)
36+
!9 = !{null}
37+
!10 = !{i32 2, !"Debug Info Version", i32 3}
38+
!11 = !DILocation(line: 26, column: 11, scope: !12)
39+
!12 = distinct !DILexicalBlock(scope: !14, file: !13, line: 26, column: 11)
40+
!13 = !DIFile(filename: "108541-metadata-crash.cpp", directory: "/tmp")
41+
!14 = distinct !DILexicalBlock(scope: !15, file: !13, line: 25, column: 5)
42+
!15 = distinct !DILexicalBlock(scope: !16, file: !13, line: 24, column: 9)
43+
!16 = distinct !DILexicalBlock(scope: !17, file: !13, line: 14, column: 3)
44+
!17 = distinct !DILexicalBlock(scope: !18, file: !13, line: 13, column: 3)
45+
!18 = distinct !DILexicalBlock(scope: !19, file: !13, line: 13, column: 3)
46+
!19 = distinct !DISubprogram(name: "hoge", linkageName: "hoge", scope: !13, file: !13, line: 10, type: !20, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
47+
!20 = distinct !DISubroutineType(types: !2)

llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ void identifyUninterestingMDNodes(Oracle &O, MDNodeList &MDs) {
6767
// Don't add uninteresting operands to the tuple.
6868
if (!O.shouldKeep())
6969
continue;
70-
TN.push_back(Op);
7170
}
71+
TN.push_back(Tup->getOperand(I));
7272
}
7373
if (TN.size() != Tup->getNumOperands())
7474
DbgNode->replaceOperandWith(OpIdx, DbgNode->get(DbgNode->getContext(), TN));

0 commit comments

Comments
 (0)