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