36 lines · c
1// RUN: %clang_tysan %s -o %t && %run %t 10 >%t.out.0 2>&12// RUN: FileCheck --check-prefixes=CHECK,CHECK-BOTH %s < %t.out.03// RUN: echo "fun:typeViolationignored" > %tmp4// RUN: echo "src:*ignorelist.h" > %tmp5// RUN: %clang_tysan -fsanitize-ignorelist=%tmp %s -o %t && %run %t 10 >%t.out 2>&16// RUN: FileCheck --check-prefixes=CHECK-IGNORELIST,CHECK-BOTH %s < %t.out7 8#include "ignorelist.h"9#include <stdio.h>10#include <stdlib.h>11 12void typeViolationIgnored(float *fPtr) { printf("As int: %d\n", *(int *)fPtr); }13 14void typeViolation(int *fPtr) { printf("As float: %f\n", *(float *)fPtr); }15 16int 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 float22 // 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 int29 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