xref: /llvm-project/llvm/test/Instrumentation/BoundsChecking/many-traps-2.ll (revision e87afb9730d4cf8cd8c6f9c2f45e8e5f040bb8e9)
1; RUN: opt < %s -passes=bounds-checking -S | FileCheck %s
2@array = internal global [1819 x i16] zeroinitializer, section ".bss,bss"
3@offsets = external dso_local global [10 x i16]
4
5; CHECK-LABEL: @test
6define dso_local void @test() {
7bb1:
8  br label %bb19
9
10bb20:
11  %_tmp819 = load i16, ptr null
12; CHECK: br {{.*}} %trap
13  %_tmp820 = sub nsw i16 9, %_tmp819
14  %_tmp821 = sext i16 %_tmp820 to i64
15  %_tmp822 = getelementptr [10 x i16], ptr @offsets, i16 0, i64 %_tmp821
16  %_tmp823 = load i16, ptr %_tmp822
17  br label %bb33
18
19bb34:
20  %_tmp907 = zext i16 %i__7.107.0 to i64
21  %_tmp908 = getelementptr [1819 x i16], ptr @array, i16 0, i64 %_tmp907
22  store i16 0, ptr %_tmp908
23; CHECK: br {{.*}} %trap
24  %_tmp910 = add i16 %i__7.107.0, 1
25  br label %bb33
26
27bb33:
28  %i__7.107.0 = phi i16 [ undef, %bb20 ], [ %_tmp910, %bb34 ]
29  %_tmp913 = add i16 %_tmp823, 191
30  %_tmp914 = icmp ult i16 %i__7.107.0, %_tmp913
31  br i1 %_tmp914, label %bb34, label %bb19
32
33bb19:
34  %_tmp976 = icmp slt i16 0, 10
35  br i1 %_tmp976, label %bb20, label %bb39
36
37bb39:
38  ret void
39}
40
41@e = dso_local local_unnamed_addr global [1 x i16] zeroinitializer, align 1
42
43; CHECK-LABEL: @test2
44define dso_local void @test2() local_unnamed_addr {
45entry:
46  br label %while.cond1.preheader
47
48while.cond1.preheader:
49  %0 = phi i16 [ undef, %entry ], [ %inc, %while.end ]
50  %1 = load i16, ptr undef, align 1
51; CHECK: br {{.*}} %trap
52  br label %while.end
53
54while.end:
55  %inc = add nsw i16 %0, 1
56  %arrayidx = getelementptr inbounds [1 x i16], ptr @e, i16 0, i16
57 %0
58  %2 = load i16, ptr %arrayidx, align 1
59; CHECK: or i1
60; CHECK-NEXT: br {{.*}} %trap
61  br i1 false, label %while.end6, label %while.cond1.preheader
62
63while.end6:
64  ret void
65}
66