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/47137 |
5 | #include <stdint.h> |
6 | #include <stdio.h> |
7 | #include <stdlib.h> |
8 | |
9 | void f(int m) { |
10 | int n = (4 * m + 2) / 3; |
11 | uint64_t *a = malloc(size: n * sizeof(uint64_t)); |
12 | uint64_t *b = malloc(size: n * sizeof(uint64_t)); |
13 | uint64_t aa[] = {0xffff3e0000000001, 0x22eaf0b680a88c16, 0x5a65d25ac40e20f3, |
14 | 0x34e7ac346236953e, 0x9dea3e0a26c6ba89, 0x0000000000000000, |
15 | 0x0000000000000000, 0x0000000000000000}; |
16 | uint64_t bb[] = {0x0000000024c0ffff, 0x000000004634d940, 0x00000000219d18ef, |
17 | 0x0000000000154519, 0x000000000000035f, 0x0000000000000000, |
18 | 0x0000000000000000, 0x0000000000000000}; |
19 | char l[20]; |
20 | l[0] = 0; |
21 | for (int i = 0; i < n; i++) { |
22 | a[i] = aa[i] + l[0] - '0'; |
23 | b[i] = bb[i] + l[0] - '0'; |
24 | } |
25 | |
26 | // CHECK: TypeSanitizer: type-aliasing-violation on address |
27 | // CHECK-NEXT: READ of size 2 at {{.+}} with type short accesses an existing object of type long |
28 | // CHECK-NEXT: in f {{.*/?}}violation-pr47137.c:31 |
29 | for (int i = 0, j = 0; j < 4 * m; i += 4, j += 3) { |
30 | for (int k = 0; k < 3; k++) { |
31 | ((uint16_t *)a)[j + k] = ((uint16_t *)a)[i + k]; |
32 | ((uint16_t *)b)[j + k] = ((uint16_t *)b)[i + k]; |
33 | } |
34 | } |
35 | |
36 | printf(format: "a: %016llx\n" , a[0]); |
37 | free(ptr: a); |
38 | free(ptr: b); |
39 | } |
40 | |
41 | int main() { f(m: 6); } |
42 | |