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/68655 |
5 | struct S1 { |
6 | long long a; |
7 | long long b; |
8 | }; |
9 | |
10 | // CHECK: TypeSanitizer: type-aliasing-violation on address |
11 | // CHECK-NEXT: READ of size 4 at {{.+}} with type int accesses an existing object of type long long (in {{.*}}S1 at offset 0) |
12 | // CHECK-NEXT: in copyMem(S1*, S1*) {{.*/?}}violation-pr68655.cpp:19 |
13 | |
14 | void inline copyMem(S1 *dst, S1 *src) { |
15 | unsigned *d = reinterpret_cast<unsigned *>(dst); |
16 | unsigned *s = reinterpret_cast<unsigned *>(src); |
17 | |
18 | for (int i = 0; i < sizeof(S1) / sizeof(unsigned); i++) { |
19 | *d = *s; |
20 | d++; |
21 | s++; |
22 | } |
23 | } |
24 | |
25 | void math(S1 *dst, int *srcA, int idx_t) { |
26 | S1 zero[4]; |
27 | for (int i = 0; i < 2; i++) { |
28 | zero[i].a = i + idx_t; |
29 | zero[i].b = i * idx_t; |
30 | } |
31 | |
32 | copyMem(dst: &dst[idx_t], src: &zero[srcA[idx_t]]); |
33 | } |
34 | |
35 | int main() { |
36 | S1 dst = {.a: 0}; |
37 | int Src[2] = {0, 0}; |
38 | math(dst: &dst, srcA: &Src[0], idx_t: 0); |
39 | return 0; |
40 | } |
41 | |