OSDN Git Service

Subzero: small cleanups
[android-x86/external-swiftshader.git] / tests_lit / asan_tests / errors.ll
1 ; Verify that ASan properly catches and reports bugs
2
3 ; REQUIRES: no_minimal_build
4
5 ; check with a one off the end local access
6 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \
7 ; RUN:     --fsanitize-address --sz=-allow-externally-defined-symbols \
8 ; RUN:     %t.pexe -o %t && %t 2>&1 | FileCheck %s
9
10 ; check with a many off the end local access
11 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \
12 ; RUN:     --fsanitize-address --sz=-allow-externally-defined-symbols \
13 ; RUN:     %t.pexe -o %t && %t 1 2>&1 | FileCheck %s
14
15 ; check with a one before the front local access
16 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \
17 ; RUN:     --fsanitize-address --sz=-allow-externally-defined-symbols \
18 ; RUN:     %t.pexe -o %t && %t 1 2 2>&1 | FileCheck %s
19
20 ; check with a one off the end global access
21 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \
22 ; RUN:     --fsanitize-address --sz=-allow-externally-defined-symbols \
23 ; RUN:     %t.pexe -o %t && %t 1 2 3 2>&1 | FileCheck %s
24
25 ; check with a many off the end global access
26 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \
27 ; RUN:     --fsanitize-address --sz=-allow-externally-defined-symbols \
28 ; RUN:     %t.pexe -o %t && %t 1 2 3 4 2>&1 | FileCheck %s
29
30 ; check with a one before the front global access
31 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \
32 ; RUN:     --fsanitize-address --sz=-allow-externally-defined-symbols \
33 ; RUN:     %t.pexe -o %t && %t 1 2 3 4 5 2>&1 | FileCheck %s
34
35
36 declare external void @exit(i32)
37
38 ; A global array
39 @array = internal constant [12 x i8] zeroinitializer
40
41 define void @access(i32 %is_local_i, i32 %err) {
42   ; get the base pointer to either the local or global array
43   %local = alloca i8, i32 12, align 1
44   %global = bitcast [12 x i8]* @array to i8*
45   %is_local = icmp ne i32 %is_local_i, 0
46   %arr = select i1 %is_local, i8* %local, i8* %global
47
48   ; determine the offset to access
49   %err_offset = mul i32 %err, 4
50   %pos_offset = add i32 %err_offset, 12
51   %pos = icmp sge i32 %err_offset, 0
52   %offset = select i1 %pos, i32 %pos_offset, i32 %err
53
54   ; calculate the address to access
55   %arraddr = ptrtoint i8* %arr to i32
56   %badaddr = add i32 %arraddr, %offset
57   %badptr = inttoptr i32 %badaddr to i8*
58
59   ; perform the bad access
60   %result = load i8, i8* %badptr, align 1
61   ret void
62 }
63
64 ; use argc to determine which test routine to run
65 define void @_start(i32 %arg) {
66   %argcaddr = add i32 %arg, 8
67   %argcptr = inttoptr i32 %argcaddr to i32*
68   %argc = load i32, i32* %argcptr, align 1
69   switch i32 %argc, label %error [i32 1, label %one_local
70                                   i32 2, label %many_local
71                                   i32 3, label %neg_local
72                                   i32 4, label %one_global
73                                   i32 5, label %many_global
74                                   i32 6, label %neg_global]
75 one_local:
76   ; Access one past the end of a local
77   call void @access(i32 1, i32 0)
78   br label %error
79 many_local:
80   ; Access five past the end of a local
81   call void @access(i32 1, i32 4)
82   br label %error
83 neg_local:
84   ; Access one before the beginning of a local
85   call void @access(i32 1, i32 -1)
86   br label %error
87 one_global:
88   ; Access one past the end of a global
89   call void @access(i32 0, i32 0)
90   br label %error
91 many_global:
92   ; Access five past the end of a global
93   call void @access(i32 0, i32 4)
94   br label %error
95 neg_global:
96   ; Access one before the beginning of a global
97   call void @access(i32 0, i32 -1)
98   br label %error
99 error:
100   call void @exit(i32 1)
101   unreachable
102 }
103
104 ; CHECK: Illegal access of 1 bytes at