1 // RUN: %clang_tysan -O0 %s -o %t && %run %t >%t.out 2>&1 2 // RUN: FileCheck %s < %t.out 3 4 #include <stdio.h> 5 #include <stdlib.h> 6 7 struct X { 8 int i; 9 int j; 10 }; 11 12 int foo(struct X *p, struct X *q) { 13 q->j = 1; 14 p->i = 0; 15 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation 16 // CHECK: WRITE of size 4 at {{.*}} with type int (in X at offset 0) accesses an existing object of type int (in X at offset 4) 17 // CHECK: {{#0 0x.* in foo .*struct-offset.c:}}[[@LINE-3]] 18 return q->j; 19 } 20 21 int main() { 22 unsigned char *p = malloc(3 * sizeof(int)); 23 printf("%i\n", foo((struct X *)(p + sizeof(int)), (struct X *)p)); 24 } 25 26 // CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation 27