1// RUN: %clang_tysan -O0 %s -o %t && %run %t >%t.out 2>&1
2// RUN: FileCheck %s < %t.out
3
4// https://github.com/llvm/llvm-project/issues/62828
5#include <stdio.h>
6
7typedef int int_v8[8];
8typedef short short_v8[8];
9short *test1(int_v8 *cast_c_array, short_v8 *shuf_c_array1, int *ptr) {
10 int *input1 = reinterpret_cast<int *>(((int_v8 *)(cast_c_array)));
11 short *input2 = reinterpret_cast<short *>(reinterpret_cast<int_v8 *>(input1));
12
13 short *output1 = reinterpret_cast<short *>(((short_v8 *)(shuf_c_array1)));
14 short *output2 =
15 reinterpret_cast<short *>(reinterpret_cast<short_v8 *>(output1));
16
17 for (int r = 0; r < 8; ++r) {
18 int tmp = (int)((r * 4) + ptr[r]);
19 if ((ptr[r] / 4) == 0) {
20 int *input = reinterpret_cast<int *>(((int_v8 *)(cast_c_array)));
21 input[r] = tmp;
22 }
23 }
24
25 // CHECK: ERROR: TypeSanitizer: type-aliasing-violation on address
26 // CHECK-NEXT: READ of size 2 at {{.+}} with type short accesses an existing object of type int
27 // CHECK-NEXT: in test1(int (*) [8], short (*) [8], int*) {{.*/?}}violation-pr62828.cpp:29
28 for (int i3 = 0; i3 < 4; ++i3) {
29 output2[i3] = input2[(i3 * 2)];
30 }
31 return output2;
32}
33
34int main() {
35 int_v8 in[4] = {{4, 4, 4, 4}};
36 short_v8 out[4] = {{0}};
37 int ptr[8] = {2};
38 test1(cast_c_array: in, shuf_c_array1: out, ptr);
39 short *p = reinterpret_cast<short *>(out);
40 for (int i = 0; i < 32; i++) {
41 printf(format: "%d ", p[i]);
42 }
43 return 0;
44}
45

source code of compiler-rt/test/tysan/violation-pr62828.cpp