Unify clang/llvm attributes for asan/tsan/msan (LLVM part)
[oota-llvm.git] / test / Instrumentation / AddressSanitizer / asan-vs-gvn.ll
1 ; RUN: opt < %s -basicaa -gvn -asan -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 ; http://code.google.com/p/address-sanitizer/issues/detail?id=20#c1
5
6
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"
9
10 %struct_of_7_bytes_4_aligned = type { i32, i8, i8, i8}
11
12 @f = global %struct_of_7_bytes_4_aligned zeroinitializer, align 4
13
14 ; Accessing bytes 4 and 6, not ok to widen to i32 if sanitize_address is set.
15
16 define i32 @test_widening_bad(i8* %P) nounwind ssp noredzone sanitize_address {
17 entry:
18   %tmp = load i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned* @f, i64 0, i32 1), align 4
19   %conv = zext i8 %tmp to i32
20   %tmp1 = load i8* getelementptr inbounds (%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
23   ret i32 %add
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
30 }
31
32 define void @end_test_widening_bad() {
33   entry:
34   ret void
35 }
36
37 ;; Accessing bytes 4 and 5. Ok to widen to i16.
38
39 define i32 @test_widening_ok(i8* %P) nounwind ssp noredzone sanitize_address {
40 entry:
41   %tmp = load i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned* @f, i64 0, i32 1), align 4
42   %conv = zext i8 %tmp to i32
43   %tmp1 = load i8* getelementptr inbounds (%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
46   ret i32 %add
47 ; CHECK: @test_widening_ok
48 ; CHECK: __asan_report_load2
49 ; CHECK-NOT: __asan_report
50 ; CHECK: end_test_widening_ok
51 }
52
53 define void @end_test_widening_ok() {
54   entry:
55   ret void
56 }