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