Skip to content

Commit 1731bb7

Browse files
authored
llvm-reduce: Fix not checking shouldKeep in special-globals reduction (#111647)
1 parent c4d288d commit 1731bb7

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llvm-reduce -abort-on-invalid-reduction --delta-passes=special-globals --test FileCheck --test-arg --check-prefix=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t.0
2+
; RUN: FileCheck --implicit-check-not=define --check-prefix=CHECK-FINAL %s < %t.0
3+
4+
; Check that we don't hit "input module no longer interesting after
5+
; counting chunks" The special-globals reduction was not checking
6+
; shouldKeep before unconditionally erasing it.
7+
8+
; CHECK-INTERESTINGNESS: llvm.used
9+
; CHECK-FINAL: llvm.used
10+
; CHECK-FINAL: define void @kept_used
11+
; CHECK-FINAL: define void @other
12+
@llvm.used = appending global [2 x ptr] [ptr @kept_used, ptr @other ]
13+
14+
define void @kept_used() {
15+
ret void
16+
}
17+
18+
define void @other() {
19+
ret void
20+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ static void extractSpecialGlobalsFromModule(Oracle &O,
3333

3434
for (StringRef Name : SpecialGlobalNames) {
3535
if (auto *Used = Program.getNamedGlobal(Name)) {
36-
Used->replaceAllUsesWith(getDefaultValue(Used->getType()));
37-
Used->eraseFromParent();
36+
if (!O.shouldKeep()) {
37+
Used->replaceAllUsesWith(getDefaultValue(Used->getType()));
38+
Used->eraseFromParent();
39+
}
3840
}
3941
}
4042
}

0 commit comments

Comments
 (0)