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
10extern "C" {
11typedef struct X {
12 int *start;
13 int *end;
14 int i;
15} X;
16};
17
18#ifdef PMAIN
19int foo(struct X *);
20void bar(struct X *);
21void init(struct X *);
22
23int 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
33void 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
47void bar(struct X *x) { x->end = NULL; }
48
49#endif
50
51// CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation
52

source code of compiler-rt/test/tysan/struct-offset-multiple-compilation-units.cpp