41 lines · cpp
1// RUN: %clang_tysan -O0 %s -o %t && %run %t >%t.out 2>&12// RUN: FileCheck %s < %t.out3 4// https://github.com/llvm/llvm-project/issues/686555struct S1 {6 long long a;7 long long b;8};9 10// CHECK: TypeSanitizer: type-aliasing-violation on address11// 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:1913 14void 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 25void 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[idx_t], &zero[srcA[idx_t]]);33}34 35int main() {36 S1 dst = {0};37 int Src[2] = {0, 0};38 math(&dst, &Src[0], 0);39 return 0;40}41