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 6 typedef struct { 7 int i1, i1b; 8 } s1; 9 typedef struct { 10 int i2, i2b, i2c; 11 } s2; 12 13 void f(s1 *s1p, s2 *s2p) { 14 s1p->i1 = 2; 15 s2p->i2 = 3; 16 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation 17 // CHECK: WRITE of size 4 at {{.*}} with type int (in <anonymous type> at offset 0) accesses an existing object of type int (in <anonymous type> at offset 0) 18 // CHECK: {{#0 0x.* in f .*anon-struct.c:}}[[@LINE-3]] 19 printf("%i\n", s1p->i1); 20 } 21 22 int main() { 23 s1 s = {.i1 = 1, .i1b = 5}; 24 f(&s, (s2 *)&s); 25 } 26 27 // CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation 28