Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / set_shadow_test.c
blobf1c96502eba7eb6f9a00775fc413ede9796df85a
1 // RUN: %clang_asan -O0 %s -o %t
2 // RUN: %run %t 0x00 2>&1 | FileCheck %s -check-prefix=X00
3 // RUN: not %run %t 0xf1 2>&1 | FileCheck %s -check-prefix=XF1
4 // RUN: not %run %t 0xf2 2>&1 | FileCheck %s -check-prefix=XF2
5 // RUN: not %run %t 0xf3 2>&1 | FileCheck %s -check-prefix=XF3
6 // RUN: not %run %t 0xf5 2>&1 | FileCheck %s -check-prefix=XF5
7 // RUN: not %run %t 0xf8 2>&1 | FileCheck %s -check-prefix=XF8
9 #include <assert.h>
10 #include <sanitizer/asan_interface.h>
11 #include <stddef.h>
12 #include <stdio.h>
13 #include <stdlib.h>
15 void __asan_set_shadow_00(size_t addr, size_t size);
16 void __asan_set_shadow_01(size_t addr, size_t size);
17 void __asan_set_shadow_02(size_t addr, size_t size);
18 void __asan_set_shadow_03(size_t addr, size_t size);
19 void __asan_set_shadow_04(size_t addr, size_t size);
20 void __asan_set_shadow_05(size_t addr, size_t size);
21 void __asan_set_shadow_06(size_t addr, size_t size);
22 void __asan_set_shadow_07(size_t addr, size_t size);
23 void __asan_set_shadow_f1(size_t addr, size_t size);
24 void __asan_set_shadow_f2(size_t addr, size_t size);
25 void __asan_set_shadow_f3(size_t addr, size_t size);
26 void __asan_set_shadow_f5(size_t addr, size_t size);
27 void __asan_set_shadow_f8(size_t addr, size_t size);
29 char* a;
31 void f(long arg) {
32 size_t shadow_offset;
33 size_t shadow_scale;
34 __asan_get_shadow_mapping(&shadow_scale, &shadow_offset);
35 size_t addr = (((size_t)a) >> shadow_scale) + shadow_offset;
37 switch (arg) {
38 // X00-NOT: AddressSanitizer
39 // X00: PASS
40 case 0x00:
41 return __asan_set_shadow_00(addr, 1);
42 // X01: AddressSanitizer: stack-buffer-overflow
43 // X01: [01]
44 case 0x01:
45 return __asan_set_shadow_01(addr, 1);
46 // X02: AddressSanitizer: stack-buffer-overflow
47 // X02: [02]
48 case 0x02:
49 return __asan_set_shadow_02(addr, 1);
50 // X03: AddressSanitizer: stack-buffer-overflow
51 // X03: [03]
52 case 0x03:
53 return __asan_set_shadow_03(addr, 1);
54 // X04: AddressSanitizer: stack-buffer-overflow
55 // X04: [04]
56 case 0x04:
57 return __asan_set_shadow_04(addr, 1);
58 // X05: AddressSanitizer: stack-buffer-overflow
59 // X05: [05]
60 case 0x05:
61 return __asan_set_shadow_05(addr, 1);
62 // X06: AddressSanitizer: stack-buffer-overflow
63 // X06: [06]
64 case 0x06:
65 return __asan_set_shadow_06(addr, 1);
66 // X07: AddressSanitizer: stack-buffer-overflow
67 // X07: [07]
68 case 0x07:
69 return __asan_set_shadow_07(addr, 1);
70 // XF1: AddressSanitizer: stack-buffer-underflow
71 // XF1: [f1]
72 case 0xf1:
73 return __asan_set_shadow_f1(addr, 1);
74 // XF2: AddressSanitizer: stack-buffer-overflow
75 // XF2: [f2]
76 case 0xf2:
77 return __asan_set_shadow_f2(addr, 1);
78 // XF3: AddressSanitizer: stack-buffer-overflow
79 // XF3: [f3]
80 case 0xf3:
81 return __asan_set_shadow_f3(addr, 1);
82 // XF5: AddressSanitizer: stack-use-after-return
83 // XF5: [f5]
84 case 0xf5:
85 return __asan_set_shadow_f5(addr, 1);
86 // XF8: AddressSanitizer: stack-use-after-scope
87 // XF8: [f8]
88 case 0xf8:
89 return __asan_set_shadow_f8(addr, 1);
91 assert(0);
94 int main(int argc, char **argv) {
95 assert(argc > 1);
97 a = malloc(8);
98 long arg = strtol(argv[1], 0, 16);
99 f(arg);
100 *a = 1;
101 printf("PASS\n");
102 return 0;