1 | // RUN: %clang_tysan %s -o %t && %run %t 10 >%t.out.0 2>&1 |
2 | // RUN: FileCheck --check-prefixes=CHECK,CHECK-BOTH %s < %t.out.0 |
3 | // RUN: echo "fun:typeViolationignored" > %tmp |
4 | // RUN: echo "src:*ignorelist.h" > %tmp |
5 | // RUN: %clang_tysan -fsanitize-ignorelist=%tmp %s -o %t && %run %t 10 >%t.out 2>&1 |
6 | // RUN: FileCheck --check-prefixes=CHECK-IGNORELIST,CHECK-BOTH %s < %t.out |
7 | |
8 | #include "ignorelist.h" |
9 | #include <stdio.h> |
10 | #include <stdlib.h> |
11 | |
12 | void typeViolationIgnored(float *fPtr) { printf(format: "As int: %d\n" , *(int *)fPtr); } |
13 | |
14 | void typeViolation(int *fPtr) { printf(format: "As float: %f\n" , *(float *)fPtr); } |
15 | |
16 | int main() { |
17 | float *f = (float *)malloc(size: sizeof(float)); |
18 | *f = 413.0f; |
19 | typeViolationIgnored(fPtr: f); |
20 | // CHECK: TypeSanitizer: type-aliasing-violation on address 0x{{.*}} |
21 | // CHECK-NEXT: READ of size 4 at 0x{{.*}} with type int accesses an existing object of type float |
22 | // CHECK-IGNORELIST-NOT: TypeSanitizer: type-aliasing-violation on address 0x{{.*}} |
23 | |
24 | int *i = (int *)malloc(size: sizeof(int)); |
25 | *i = 612; |
26 | typeViolation(fPtr: i); |
27 | // CHECK-BOTH: TypeSanitizer: type-aliasing-violation on address 0x{{.*}} |
28 | // CHECK-BOTH: READ of size 4 at 0x{{.*}} with type float accesses an existing object of type int |
29 | |
30 | typeViolationMultiFile(value: (void *)i); |
31 | // CHECK: TypeSanitizer: type-aliasing-violation on address 0x{{.*}} |
32 | // CHECK-IGNORELIST-NOT: TypeSanitizer: type-aliasing-violation on address 0x{{.*}} |
33 | |
34 | return 0; |
35 | } |
36 | |