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// Violation reported in https://github.com/llvm/llvm-project/issues/86685.
8void foo(int *s, float *f, long n) {
9 for (long i = 0; i < n; ++i) {
10 *f = 2;
11 if (i == 1)
12 break;
13
14 // CHECK: TypeSanitizer: type-aliasing-violation on address
15 // CHECK-NEXT: WRITE of size 4 at {{.+}} with type int accesses an existing object of type float
16 // CHECK-NEXT: #0 {{.+}} in foo {{.*/?}}violation-pr86685.c:17
17 *s = 4;
18 }
19}
20
21int main(void) {
22 union {
23 int s;
24 float f;
25 } u = {0};
26 foo(s: &u.s, f: &u.f, n: 2);
27 printf(format: "%.f\n", u.f);
28 return 0;
29}
30

source code of compiler-rt/test/tysan/violation-pr86685.c