1; Test basic address sanitizer instrumentation for Myriad.
2;
3; RUN: opt -asan -asan-module -S  < %s | FileCheck %s
4
5target triple = "sparc-myriad-rtems"
6target datalayout = "E-m:e-p:32:32-i64:64-f128:64-n32-S64"
7; CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor
8
9define i32 @test_load(i32* %a) sanitize_address {
10; CHECK-LABEL: @test_load
11; CHECK-NOT: load
12; CHECK:   ptrtoint i32* %a to i32
13; CHECK:   %[[LOAD_ADDR:[^ ]*]] = and i32 %{{.*}}, -1073741825
14; CHECK:   lshr i32 %{{.*}}, 29
15; CHECK:   icmp eq i32 %{{.*}}, 4
16; CHECK:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}!prof ![[PROF:[0-9]+]]
17;
18; This block checks whether the shadow byte is 0.
19; CHECK:   lshr i32 %[[LOAD_ADDR]], 5
20; CHECK:   add i32 %{{.*}}, -1694498816
21; CHECK:   %[[LOAD_SHADOW_PTR:[^ ]*]] = inttoptr
22; CHECK:   %[[LOAD_SHADOW:[^ ]*]] = load i8, i8* %[[LOAD_SHADOW_PTR]]
23; CHECK:   icmp ne i8
24; CHECK:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}!prof ![[PROF:[0-9]+]]
25;
26; This block refines the shadow test.
27; CHECK:   and i32 %[[LOAD_ADDR]], 31
28; CHECK:   add i32 %{{.*}}, 3
29; CHECK:   trunc i32 %{{.*}} to i8
30; CHECK:   icmp sge i8 %{{.*}}, %[[LOAD_SHADOW]]
31; CHECK:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
32;
33; The crash block reports the error.
34; CHECK:   call void @__asan_report_load4(i32 %[[LOAD_ADDR]])
35; CHECK:   unreachable
36;
37; The actual load.
38; CHECK:   %tmp1 = load i32, i32* %a
39; CHECK:   ret i32 %tmp1
40
41entry:
42  %tmp1 = load i32, i32* %a, align 4
43  ret i32 %tmp1
44}
45
46define void @test_store(i32* %a) sanitize_address {
47; CHECK-LABEL: @test_store
48; CHECK-NOT: store
49; CHECK:   ptrtoint i32* %a to i32
50; CHECK:   %[[STORE_ADDR:[^ ]*]] = and i32 %{{.*}}, -1073741825
51; CHECK:   lshr i32 %{{.*}}, 29
52; CHECK:   icmp eq i32 %{{.*}}, 4
53; CHECK:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}!prof ![[PROF:[0-9]+]]
54;
55; This block checks whether the shadow byte is 0.
56; CHECK:   lshr i32 %[[STORE_ADDR]], 5
57; CHECK:   add i32 %{{.*}}, -1694498816
58; CHECK:   %[[STORE_SHADOW_PTR:[^ ]*]] = inttoptr
59; CHECK:   %[[STORE_SHADOW:[^ ]*]] = load i8, i8* %[[STORE_SHADOW_PTR]]
60; CHECK:   icmp ne i8
61; CHECK:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
62;
63; This block refines the shadow test.
64; CHECK:   and i32 %[[STORE_ADDR]], 31
65; CHECK:   add i32 %{{.*}}, 3
66; CHECK:   trunc i32 %{{.*}} to i8
67; CHECK:   icmp sge i8 %{{.*}}, %[[STORE_SHADOW]]
68; CHECK:   br i1 %{{.*}}, label %{{.*}}, label %{{.*}}
69;
70; The crash block reports the error.
71; CHECK:   call void @__asan_report_store4(i32 %[[STORE_ADDR]])
72; CHECK:   unreachable
73; The actual store.
74; CHECK:   store i32 42, i32* %a
75; CHECK:   ret void
76;
77
78entry:
79  store i32 42, i32* %a, align 4
80  ret void
81}
82
83; CHECK: define internal void @asan.module_ctor()
84; CHECK: call void @__asan_init()
85