1 // RUN: %clangxx_tysan -O0 %s -c -o %t.o 2 // RUN: %clangxx_tysan -O0 %s -DPMAIN -c -o %tm.o 3 // RUN: %clangxx_tysan -O0 %s -DPINIT -c -o %tinit.o 4 // RUN: %clangxx_tysan -O0 %t.o %tm.o %tinit.o -o %t 5 // RUN: %run %t 2>&1 | FileCheck %s 6 7 #include <stdio.h> 8 #include <stdlib.h> 9 10 extern "C" { 11 typedef struct X { 12 int *start; 13 int *end; 14 int i; 15 } X; 16 }; 17 18 #ifdef PMAIN 19 int foo(struct X *); 20 void bar(struct X *); 21 void init(struct X *); 22 23 int main() { 24 struct X x; 25 init(&x); 26 printf("%d\n", foo(&x)); 27 free(x.start); 28 return 0; 29 } 30 31 #elif PINIT 32 33 void init(struct X *x) { 34 x->start = (int *)calloc(100, sizeof(int)); 35 x->end = x->start + 99; 36 x->i = 0; 37 } 38 39 #else 40 41 __attribute__((noinline)) int foo(struct X *x) { 42 if (x->start < x->end) 43 return 30; 44 return 10; 45 } 46 47 void bar(struct X *x) { x->end = NULL; } 48 49 #endif 50 51 // CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation 52