xref: /llvm-project/compiler-rt/test/tysan/anon-same-struct.c (revision 641fbf1524338c86c952ebb1ec8d2b497ada3cef)
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 // The two anonymous structs are structurally identical. As a result, we don't
7 // report an aliasing violation here.
8 // CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation
9 
10 typedef struct {
11   int i1;
12 } s1;
13 typedef struct {
14   int i2;
15 } s2;
16 
17 void f(s1 *s1p, s2 *s2p) {
18   s1p->i1 = 2;
19   s2p->i2 = 3;
20   printf("%i\n", s1p->i1);
21 }
22 
23 int main() {
24   s1 s = {.i1 = 1};
25   f(&s, (s2 *)&s);
26 }
27