[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / rich-stack.c
blob6787d57769f4c3f8d2f6659443ff1cad679d8110
1 // Test how stack frames are reported (not fully implemented yet).
2 // RUN: %clang_hwasan %s -o %t
3 // RUN: not %run %t 3 2 -1 2>&1 | FileCheck %s --check-prefix=R321
4 // REQUIRES: stable-runtime
5 #include <stdint.h>
6 #include <stdlib.h>
7 void USE(void *x) { // pretend_to_do_something(void *x)
8 __asm__ __volatile__("" : : "r" (x) : "memory");
10 void USE2(void *a, void *b) { USE(a); USE(b); }
11 void USE4(void *a, void *b, void *c, void *d) { USE2(a, b); USE2(c, d); }
13 void BAR(int depth, int err_depth, int offset);
15 uint64_t *leaked_ptr;
17 void FOO(int depth, int err_depth, int offset) {
18 uint8_t v1;
19 uint16_t v2;
20 uint32_t v4;
21 uint64_t v8;
22 uint64_t v16[2];
23 uint64_t v32[4];
24 uint64_t v48[3];
25 USE4(&v1, &v2, &v4, &v8); USE4(&v16, &v32, &v48, 0);
26 leaked_ptr = &v16[0];
27 if (depth)
28 BAR(depth - 1, err_depth, offset);
30 if (err_depth == depth)
31 v16[offset] = 0; // maybe OOB.
32 if (err_depth == -depth)
33 leaked_ptr[offset] = 0; // maybe UAR.
34 USE(&v16);
37 void BAR(int depth, int err_depth, int offset) {
38 uint64_t x16[2];
39 uint64_t x32[4];
40 USE2(&x16, &x32);
41 leaked_ptr = &x16[0];
42 if (depth)
43 FOO(depth - 1, err_depth, offset);
44 if (err_depth == depth)
45 x16[offset] = 0; // maybe OOB
46 if (err_depth == -depth)
47 leaked_ptr[offset] = 0; // maybe UAR
48 USE(&x16);
52 int main(int argc, char **argv) {
53 if (argc != 4) return -1;
54 int depth = atoi(argv[1]);
55 int err_depth = atoi(argv[2]);
56 int offset = atoi(argv[3]);
57 FOO(depth, err_depth, offset);
58 return 0;
61 // R321: HWAddressSanitizer: tag-mismatch
62 // R321-NEXT: WRITE of size 8
63 // R321-NEXT: in BAR
64 // R321-NEXT: in FOO
65 // R321-NEXT: in main
66 // R321: is located in stack of thread T0