Skip to content

Commit ec290a4

Browse files
authored
llvm-reduce: Reduce externally_initialized (#133859)
Not sure this is the right place to put it. This is a property of GlobalVariable, not GlobalValue. But the ReduceGlobalVars reduction tries to delete the value entirely.
1 parent dd1d41f commit ec290a4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; RUN: llvm-reduce -abort-on-invalid-reduction --delta-passes=global-values --test FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t.0
2+
; RUN: FileCheck --implicit-check-not=define --check-prefix=RESULT %s < %t.0
3+
4+
; INTERESTING: @externally_initialized_keep = externally_initialized global i32 0
5+
; INTERESTING: @externally_initialized_drop
6+
7+
; RESULT: @externally_initialized_keep = externally_initialized global i32 0, align 4
8+
; RESULT: @externally_initialized_drop = global i32 1, align 4
9+
@externally_initialized_keep = externally_initialized global i32 0, align 4
10+
@externally_initialized_drop = externally_initialized global i32 1, align 4
11+

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,13 @@ void llvm::reduceGlobalValuesDeltaPass(Oracle &O, ReducerWorkItem &Program) {
6464
if (IsImplicitDSOLocal)
6565
GV.setDSOLocal(false);
6666
}
67+
68+
// TODO: Should this go in a separate reduction?
69+
if (auto *GVar = dyn_cast<GlobalVariable>(&GV)) {
70+
if (GVar->isExternallyInitialized() && !O.shouldKeep())
71+
GVar->setExternallyInitialized(false);
72+
73+
// TODO: Reduce code model
74+
}
6775
}
6876
}

0 commit comments

Comments
 (0)