1 ; RUN: opt < %s -basicaa -gvn -asan -asan-module -S | FileCheck %s
2 ; ASAN conflicts with load widening iff the widened load accesses data out of bounds
3 ; (while the original unwidened loads do not).
4 ; https://github.com/google/sanitizers/issues/20#issuecomment-136381262
7 ; 32-bit little endian target.
8 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
10 %struct_of_7_bytes_4_aligned = type { i32, i8, i8, i8}
12 @f = external global %struct_of_7_bytes_4_aligned , align 4
14 ; Accessing bytes 4 and 6, not ok to widen to i32 if sanitize_address is set.
16 define i32 @test_widening_bad(i8* %P) nounwind ssp noredzone sanitize_address {
18 %tmp = load i8, i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned, %struct_of_7_bytes_4_aligned* @f, i64 0, i32 1), align 4
19 %conv = zext i8 %tmp to i32
20 %tmp1 = load i8, i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned, %struct_of_7_bytes_4_aligned* @f, i64 0, i32 3), align 1
21 %conv2 = zext i8 %tmp1 to i32
22 %add = add nsw i32 %conv, %conv2
24 ; CHECK: @test_widening_bad
25 ; CHECK: __asan_report_load1
26 ; CHECK: __asan_report_load1
27 ; CHECK-NOT: __asan_report
28 ; We can not use check for "ret" here because __asan_report_load1 calls live after ret.
29 ; CHECK: end_test_widening_bad
32 define void @end_test_widening_bad() {
37 ;; Accessing bytes 4 and 5. No widen to i16.
39 define i32 @test_widening_ok(i8* %P) nounwind ssp noredzone sanitize_address {
41 %tmp = load i8, i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned, %struct_of_7_bytes_4_aligned* @f, i64 0, i32 1), align 4
42 %conv = zext i8 %tmp to i32
43 %tmp1 = load i8, i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned, %struct_of_7_bytes_4_aligned* @f, i64 0, i32 2), align 1
44 %conv2 = zext i8 %tmp1 to i32
45 %add = add nsw i32 %conv, %conv2
47 ; CHECK: @test_widening_ok
48 ; CHECK: __asan_report_load1
49 ; CHECK: __asan_report_load1
50 ; CHECK-NOT: __asan_report
51 ; CHECK: end_test_widening_ok
54 define void @end_test_widening_ok() {