1 ; Verify that ASan properly catches and reports bugs
3 ; REQUIRES: no_minimal_build
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
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
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
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
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
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
36 declare external void @exit(i32)
39 @array = internal constant [12 x i8] zeroinitializer
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
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
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*
59 ; perform the bad access
60 %result = load i8, i8* %badptr, align 1
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]
76 ; Access one past the end of a local
77 call void @access(i32 1, i32 0)
80 ; Access five past the end of a local
81 call void @access(i32 1, i32 4)
84 ; Access one before the beginning of a local
85 call void @access(i32 1, i32 -1)
88 ; Access one past the end of a global
89 call void @access(i32 0, i32 0)
92 ; Access five past the end of a global
93 call void @access(i32 0, i32 4)
96 ; Access one before the beginning of a global
97 call void @access(i32 0, i32 -1)
100 call void @exit(i32 1)
104 ; CHECK: Illegal access of 1 bytes at