1 // RUN: %clang_tysan -O0 %s -o %t && %run %t >%t.out 2>&1 2 // RUN: FileCheck %s < %t.out 3 #include <stdlib.h> 4 #include <string.h> 5 6 float P; 7 long L; 8 9 int main() { 10 *(int *)&P = 5; 11 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation 12 // CHECK: WRITE of size 4 at {{.*}} with type int accesses an existing object of type float 13 // CHECK: {{#0 0x.* in main .*global.c:}}[[@LINE-3]] 14 15 void *mem = malloc(sizeof(long)); 16 *(int *)mem = 6; 17 memcpy(mem, &L, sizeof(L)); 18 *(int *)mem = 8; 19 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation 20 // CHECK: WRITE of size 4 at {{.*}} with type int accesses an existing object of type long 21 // CHECK: {{#0 0x.* in main .*global.c:}}[[@LINE-3]] 22 int r = *(((int *)mem) + 1); 23 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation 24 // CHECK: READ of size 4 at {{.*}} with type int accesses part of an existing object of type long that starts at offset -4 25 // CHECK: {{#0 0x.* in main .*global.c:}}[[@LINE-3]] 26 free(mem); 27 28 return r; 29 } 30 31 // CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation 32