1; RUN: %lli_mcjit -O0 -disable-lazy-compilation=false %s
2
3; The intention of this test is to verify that symbols mapped to COMMON in ELF
4; work as expected.
5;
6; Compiled from this C code:
7;
8; int zero_int;
9; double zero_double;
10; int zero_arr[10];
11;
12; int main()
13; {
14;     zero_arr[zero_int + 5] = 40;
15;
16;     if (zero_double < 1.0)
17;         zero_arr[zero_int + 2] = 70;
18;
19;     for (int i = 1; i < 10; ++i) {
20;         zero_arr[i] = zero_arr[i - 1] + zero_arr[i];
21;     }
22;     return zero_arr[9] == 110 ? 0 : -1;
23; }
24
25@zero_int = common global i32 0, align 4
26@zero_arr = common global [10 x i32] zeroinitializer, align 16
27@zero_double = common global double 0.000000e+00, align 8
28
29define i32 @main() nounwind {
30entry:
31  %retval = alloca i32, align 4
32  %i = alloca i32, align 4
33  store i32 0, i32* %retval
34  %0 = load i32* @zero_int, align 4
35  %add = add nsw i32 %0, 5
36  %idxprom = sext i32 %add to i64
37  %arrayidx = getelementptr inbounds [10 x i32]* @zero_arr, i32 0, i64 %idxprom
38  store i32 40, i32* %arrayidx, align 4
39  %1 = load double* @zero_double, align 8
40  %cmp = fcmp olt double %1, 1.000000e+00
41  br i1 %cmp, label %if.then, label %if.end
42
43if.then:                                          ; preds = %entry
44  %2 = load i32* @zero_int, align 4
45  %add1 = add nsw i32 %2, 2
46  %idxprom2 = sext i32 %add1 to i64
47  %arrayidx3 = getelementptr inbounds [10 x i32]* @zero_arr, i32 0, i64 %idxprom2
48  store i32 70, i32* %arrayidx3, align 4
49  br label %if.end
50
51if.end:                                           ; preds = %if.then, %entry
52  store i32 1, i32* %i, align 4
53  br label %for.cond
54
55for.cond:                                         ; preds = %for.inc, %if.end
56  %3 = load i32* %i, align 4
57  %cmp4 = icmp slt i32 %3, 10
58  br i1 %cmp4, label %for.body, label %for.end
59
60for.body:                                         ; preds = %for.cond
61  %4 = load i32* %i, align 4
62  %sub = sub nsw i32 %4, 1
63  %idxprom5 = sext i32 %sub to i64
64  %arrayidx6 = getelementptr inbounds [10 x i32]* @zero_arr, i32 0, i64 %idxprom5
65  %5 = load i32* %arrayidx6, align 4
66  %6 = load i32* %i, align 4
67  %idxprom7 = sext i32 %6 to i64
68  %arrayidx8 = getelementptr inbounds [10 x i32]* @zero_arr, i32 0, i64 %idxprom7
69  %7 = load i32* %arrayidx8, align 4
70  %add9 = add nsw i32 %5, %7
71  %8 = load i32* %i, align 4
72  %idxprom10 = sext i32 %8 to i64
73  %arrayidx11 = getelementptr inbounds [10 x i32]* @zero_arr, i32 0, i64 %idxprom10
74  store i32 %add9, i32* %arrayidx11, align 4
75  br label %for.inc
76
77for.inc:                                          ; preds = %for.body
78  %9 = load i32* %i, align 4
79  %inc = add nsw i32 %9, 1
80  store i32 %inc, i32* %i, align 4
81  br label %for.cond
82
83for.end:                                          ; preds = %for.cond
84  %10 = load i32* getelementptr inbounds ([10 x i32]* @zero_arr, i32 0, i64 9), align 4
85  %cmp12 = icmp eq i32 %10, 110
86  %cond = select i1 %cmp12, i32 0, i32 -1
87  ret i32 %cond
88}
89