xref: /aosp_15_r20/external/llvm/test/Transforms/MergeFunc/crash2.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt %s -mergefunc -globalopt -S -o - | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; Make sure we don't crash on this example. This test is supposed to test that
4*9880d681SAndroid Build Coastguard Worker; MergeFunctions clears its GlobalNumbers value map. If this map still contains
5*9880d681SAndroid Build Coastguard Worker; entries when running globalopt and the MergeFunctions instance is still alive
6*9880d681SAndroid Build Coastguard Worker; the optimization of @G would cause an assert because globalopt would do an
7*9880d681SAndroid Build Coastguard Worker; RAUW on @G which still exists as an entry in the GlobalNumbers ValueMap which
8*9880d681SAndroid Build Coastguard Worker; causes an assert in the ValueHandle call back because we are RAUWing with a
9*9880d681SAndroid Build Coastguard Worker; different type (AllocaInst) than its key type (GlobalValue).
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker@G = internal global i8** null
12*9880d681SAndroid Build Coastguard Worker@G2 = internal global i8** null
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Workerdefine i32 @main(i32 %argc, i8** %argv) norecurse {
15*9880d681SAndroid Build Coastguard Worker; CHECK: alloca
16*9880d681SAndroid Build Coastguard Worker  store i8** %argv, i8*** @G
17*9880d681SAndroid Build Coastguard Worker  ret i32 0
18*9880d681SAndroid Build Coastguard Worker}
19*9880d681SAndroid Build Coastguard Worker
20*9880d681SAndroid Build Coastguard Workerdefine internal i8** @dead1(i64 %p) {
21*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
22*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
23*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
24*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
25*9880d681SAndroid Build Coastguard Worker  %tmp = load i8**, i8*** @G
26*9880d681SAndroid Build Coastguard Worker  ret i8** %tmp
27*9880d681SAndroid Build Coastguard Worker}
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Workerdefine internal i8** @dead2(i64 %p) {
30*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
31*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
32*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
33*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
34*9880d681SAndroid Build Coastguard Worker  %tmp = load i8**, i8*** @G2
35*9880d681SAndroid Build Coastguard Worker  ret i8** %tmp
36*9880d681SAndroid Build Coastguard Worker}
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Workerdefine void @left(i64 %p) {
39*9880d681SAndroid Build Coastguard Workerentry-block:
40*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
41*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
42*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
43*9880d681SAndroid Build Coastguard Worker  call void @right(i64 %p)
44*9880d681SAndroid Build Coastguard Worker  ret void
45*9880d681SAndroid Build Coastguard Worker}
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Workerdefine void @right(i64 %p) {
48*9880d681SAndroid Build Coastguard Workerentry-block:
49*9880d681SAndroid Build Coastguard Worker  call void @left(i64 %p)
50*9880d681SAndroid Build Coastguard Worker  call void @left(i64 %p)
51*9880d681SAndroid Build Coastguard Worker  call void @left(i64 %p)
52*9880d681SAndroid Build Coastguard Worker  call void @left(i64 %p)
53*9880d681SAndroid Build Coastguard Worker  ret void
54*9880d681SAndroid Build Coastguard Worker}
55