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