30 lines · c
1// RUN: %clang_tysan -O0 %s -o %t && %run %t >%t.out 2>&12// RUN: FileCheck %s < %t.out3 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 address15 // CHECK-NEXT: WRITE of size 4 at {{.+}} with type int accesses an existing object of type float16 // CHECK-NEXT: #0 {{.+}} in foo {{.*/?}}violation-pr86685.c:1717 *s = 4;18 }19}20 21int main(void) {22 union {23 int s;24 float f;25 } u = {0};26 foo(&u.s, &u.f, 2);27 printf("%.f\n", u.f);28 return 0;29}30