Skip to content

Commit e2caf4e

Browse files
committed
!fixup Add tests from bugtracker.
1 parent d8bac7b commit e2caf4e

7 files changed

+243
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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/45282
5+
6+
#include <stdio.h>
7+
8+
int main(void) {
9+
10+
double a[29], b[20];
11+
int i, j;
12+
13+
for (i = 0; i < 20; ++i) {
14+
b[i] = 2.01f + 1.f;
15+
((float *)a)[i] = 2.01f * 2.0145f;
16+
((float *)a + 38)[i] = 2.01f * 1.0123f;
17+
}
18+
19+
// CHECK: TypeSanitizer: type-aliasing-violation on address
20+
// CHECK-NEXT: WRITE of size 8 at {{.+}} with type double accesses an existing object of type float
21+
// CHECK-NEXT: in main violation-pr45282.c:25
22+
23+
// loop of problems
24+
for (j = 2; j <= 4; ++j) {
25+
a[j - 1] = ((float *)a)[j] * ((float *)a + 38)[j - 1];
26+
((float *)a + 38)[j - 1] = ((float *)a)[j - 1] + b[j - 1];
27+
}
28+
29+
printf("((float *)a + 38)[2] = %f\n", ((float *)a + 38)[2]);
30+
31+
return 0;
32+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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); }
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clang_tysan -O0 %s -o %t && %run %t >%t.out 2>&1
2+
// RUN: FileCheck %s < %t.out
3+
4+
#include <stdint.h>
5+
#include <stdio.h>
6+
7+
// CHECK-NOT: TypeSanitizer
8+
9+
union a {
10+
int16_t b;
11+
uint64_t c;
12+
} d;
13+
14+
uint64_t *e = &d.c;
15+
static uint16_t f(int16_t a, int32_t b, uint64_t c);
16+
static int64_t g(int32_t aa, uint8_t h, union a bb) {
17+
int16_t *i = &d.b;
18+
f(0, h, 0);
19+
*i = h;
20+
return 0;
21+
}
22+
uint16_t f(int16_t a, int32_t b, uint64_t c) {
23+
for (d.c = 0; 0;)
24+
;
25+
*e = 0;
26+
return 0;
27+
}
28+
29+
int main() {
30+
uint32_t j = 8;
31+
g(1, j, d);
32+
printf("%d\n", d.b);
33+
return 0;
34+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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/62544
5+
6+
int printf(const char *, ...);
7+
int a, b, c;
8+
long d;
9+
int main() {
10+
short *e = &a;
11+
int *f = &a;
12+
*f = 0;
13+
for (; b <= 9; b++) {
14+
int **g = &f;
15+
*f = d;
16+
*g = &c;
17+
}
18+
19+
// CHECK: TypeSanitizer: type-aliasing-violation on address
20+
// CHECK-NEXT: WRITE of size 2 at {{.+}} with type short accesses an existing object of type int
21+
// CHECK-NEXT: in main violation-pr62544.c:22
22+
*e = 3;
23+
printf("%d\n", a);
24+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
7+
typedef int int_v8[8];
8+
typedef short short_v8[8];
9+
short *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+
34+
int main() {
35+
int_v8 in[4] = {{4, 4, 4, 4}};
36+
short_v8 out[4] = {{0}};
37+
int ptr[8] = {2};
38+
test1(in, out, ptr);
39+
short *p = reinterpret_cast<short *>(out);
40+
for (int i = 0; i < 32; i++) {
41+
printf("%d ", p[i]);
42+
}
43+
return 0;
44+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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[idx_t], &zero[srcA[idx_t]]);
33+
}
34+
35+
int main() {
36+
S1 dst = {0};
37+
int Src[2] = {0, 0};
38+
math(&dst, &Src[0], 0);
39+
return 0;
40+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %clang_tysan -O0 %s -o %t && %run %t >%t.out 2>&1
2+
// RUN: FileCheck %s < %t.out
3+
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
7+
// Violation reported in https://github.com/llvm/llvm-project/issues/86685.
8+
void foo(int *s, float *f, long n) {
9+
for (long i = 0; i < n; ++i) {
10+
*f = 2;
11+
if (i == 1)
12+
break;
13+
14+
// CHECK: TypeSanitizer: type-aliasing-violation on address
15+
// CHECK-NEXT: WRITE of size 4 at {{.+}} with type int accesses an existing object of type float
16+
// CHECK-NEXT: #0 {{.+}} in foo violation-pr86685.c:17
17+
*s = 4;
18+
}
19+
}
20+
21+
int main(void) {
22+
union {
23+
int s;
24+
float f;
25+
} u = {0};
26+
foo(&u.s, &u.f, 2);
27+
printf("%.f\n", u.f);
28+
return 0;
29+
}

0 commit comments

Comments
 (0)