xref: /llvm-project/compiler-rt/test/tysan/ignorelist.c (revision 1c0af8dced4a38967f3cb2d93fb6576535bc748b)
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("As int: %d\n", *(int *)fPtr); }
13 
14 void typeViolation(int *fPtr) { printf("As float: %f\n", *(float *)fPtr); }
15 
16 int main() {
17   float *f = (float *)malloc(sizeof(float));
18   *f = 413.0f;
19   typeViolationIgnored(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(sizeof(int));
25   *i = 612;
26   typeViolation(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((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