Skip to content

Commit d43b4ed

Browse files
authored
llvm-reduce: Do not remove appending linkage from intrinsic globals (#131713)
1 parent 24fbf9d commit d43b4ed

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; Test that invalid reductions are not introduced by stripping the
2+
; required appending linkage from intrinsic global variables.
3+
;
4+
; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=global-values --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
5+
; RUN: FileCheck --check-prefix=CHECK-FINAL %s < %t
6+
7+
; CHECK-INTERESTINGNESS: @llvm.global_ctors
8+
; CHECK-INTERESTINGNESS: @llvm.global_dtors
9+
; CHECK-INTERESTINGNESS: @llvm.used
10+
11+
; CHECK-INTERESTINGNESS: define
12+
; CHECK-INTERESTINGNESS-SAME: void @f
13+
14+
; CHECK-FINAL: define void @f()
15+
16+
17+
@llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @f, ptr null }, { i32, ptr, ptr } { i32 1, ptr @g, ptr null }]
18+
@llvm.global_dtors = appending global [2 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @f, ptr null }, { i32, ptr, ptr } { i32 1, ptr @g, ptr null }]
19+
@llvm.used = appending global [1 x ptr] [ptr @h], section "llvm.metadata"
20+
21+
define void @f() {
22+
ret void
23+
}
24+
25+
; CHECK-INTERESTINGNESS: define
26+
; CHECK-INTERESTINGNESS-SAME: void @g
27+
28+
; CHECK-FINAL: define void @g()
29+
30+
define internal void @g() {
31+
ret void
32+
}
33+
34+
; CHECK-INTERESTINGNESS: define
35+
; CHECK-INTERESTINGNESS-SAME: void @h
36+
37+
define internal void @h() {
38+
ret void
39+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static bool shouldReduceThreadLocal(GlobalValue &GV) {
3838
}
3939

4040
static bool shouldReduceLinkage(GlobalValue &GV) {
41-
return !GV.hasExternalLinkage();
41+
return !GV.hasExternalLinkage() && !GV.hasAppendingLinkage();
4242
}
4343

4444
static void reduceGVs(Oracle &O, ReducerWorkItem &Program) {

0 commit comments

Comments
 (0)