[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / llvm / test / Transforms / DeadStoreElimination / out-of-bounds-stores.ll
blob949ab781b4961ec582fffb270a3178e08ea11ce1
1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -dse -S %s | FileCheck %s
4 declare void @use_pointer(i32*)
6 ; Out-of-bounds stores can be considered killing any other stores to the same
7 ; object in the same BB, because they are UB and guaranteed to execute. Note
8 ; that cases in which the BB is exited through unwinding are handled separately
9 ; by DSE and the unwinding call will be considered as clobber.
10 define i32 @test_out_of_bounds_store_local(i1 %c) {
11 ; CHECK-LABEL: @test_out_of_bounds_store_local(
12 ; CHECK-NEXT:    [[D:%.*]] = alloca [1 x i32], align 4
13 ; CHECK-NEXT:    [[ARRAYIDX_1:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[D]], i64 0, i64 1
14 ; CHECK-NEXT:    store i32 20, i32* [[ARRAYIDX_1]], align 4
15 ; CHECK-NEXT:    [[BC:%.*]] = bitcast [1 x i32]* [[D]] to i32*
16 ; CHECK-NEXT:    call void @use_pointer(i32* [[BC]])
17 ; CHECK-NEXT:    ret i32 0
19   %d = alloca [1 x i32], align 4
20   %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 0
21   store i32 10, i32* %arrayidx, align 4
22   %arrayidx.1 = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 1
23   store i32 20, i32* %arrayidx.1, align 4
24   %bc = bitcast [1 x i32]* %d to i32*
25   call void @use_pointer(i32* %bc)
26   ret i32 0
29 ; Similar to @test_out_of_bounds_store_local, but with multiple in-bounds
30 ; stores to a larger object, followed by an out-of-bounds store.
31 ; FIXME: the 2 inbounds stores could be removed by applying the same
32 ; reasoning as for @test_out_of_bounds_store_local.
33 define i32 @test_out_of_bounds_store_local_larger_object(i1 %c) {
34 ; CHECK-LABEL: @test_out_of_bounds_store_local_larger_object(
35 ; CHECK-NEXT:    [[D:%.*]] = alloca [2 x i32], align 4
36 ; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[D]], i64 0, i64 0
37 ; CHECK-NEXT:    store i32 10, i32* [[ARRAYIDX]], align 4
38 ; CHECK-NEXT:    [[ARRAYIDX_1:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[D]], i64 0, i64 1
39 ; CHECK-NEXT:    store i32 20, i32* [[ARRAYIDX_1]], align 4
40 ; CHECK-NEXT:    [[ARRAYIDX_2:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[D]], i64 0, i64 2
41 ; CHECK-NEXT:    store i32 30, i32* [[ARRAYIDX_2]], align 4
42 ; CHECK-NEXT:    [[BC:%.*]] = bitcast [2 x i32]* [[D]] to i32*
43 ; CHECK-NEXT:    call void @use_pointer(i32* [[BC]])
44 ; CHECK-NEXT:    ret i32 0
46   %d = alloca [2 x i32], align 4
47   %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %d, i64 0, i64 0
48   store i32 10, i32* %arrayidx, align 4
49   %arrayidx.1 = getelementptr inbounds [2 x i32], [2 x i32]* %d, i64 0, i64 1
50   store i32 20, i32* %arrayidx.1, align 4
51   %arrayidx.2 = getelementptr inbounds [2 x i32], [2 x i32]* %d, i64 0, i64 2
52   store i32 30, i32* %arrayidx.2, align 4
53   %bc = bitcast [2 x i32]* %d to i32*
54   call void @use_pointer(i32* %bc)
55   ret i32 0
58 ; Make sure that out-of-bound stores are not considered killing other stores to
59 ; the same underlying object, if they are in different basic blocks. The
60 ; out-of-bounds store may not be executed.
62 ; Test case from PR48279. FIXME.
63 define i32 @test_out_of_bounds_store_nonlocal(i1 %c) {
64 ; CHECK-LABEL: @test_out_of_bounds_store_nonlocal(
65 ; CHECK-NEXT:    [[D:%.*]] = alloca [1 x i32], align 4
66 ; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
67 ; CHECK:       for.body:
68 ; CHECK-NEXT:    [[ARRAYIDX:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[D]], i64 0, i64 0
69 ; CHECK-NEXT:    store i32 10, i32* [[ARRAYIDX]], align 4
70 ; CHECK-NEXT:    br label [[FOR_INC:%.*]]
71 ; CHECK:       for.inc:
72 ; CHECK-NEXT:    br i1 [[C:%.*]], label [[FOR_BODY_1:%.*]], label [[FOR_END:%.*]]
73 ; CHECK:       for.body.1:
74 ; CHECK-NEXT:    ret i32 1
75 ; CHECK:       for.end:
76 ; CHECK-NEXT:    [[BC:%.*]] = bitcast [1 x i32]* [[D]] to i32*
77 ; CHECK-NEXT:    call void @use_pointer(i32* [[BC]])
78 ; CHECK-NEXT:    ret i32 0
80   %d = alloca [1 x i32], align 4
81   br label %for.body
83 for.body:                                         ; preds = %for.cond
84   %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 0
85   store i32 10, i32* %arrayidx, align 4
86   br label %for.inc
88 for.inc:                                          ; preds = %for.body
89   br i1 %c, label %for.body.1, label %for.end
91 for.body.1:                                       ; preds = %for.inc
92   %arrayidx.1 = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 1
93   store i32 20, i32* %arrayidx.1, align 4
94   ret i32 1
96 for.end:                                          ; preds = %for.inc
97   %bc = bitcast [1 x i32]* %d to i32*
98   call void @use_pointer(i32* %bc)
99   ret i32 0