1 // Tests use-after-return detection and reporting.
2 // RUN: %clang_hwasan -g %s -o %t && not %run %t 2>&1 | FileCheck %s
3 // RUN: %clang_hwasan -g %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
5 // Run the same test as above, but using the __hwasan_add_frame_record libcall.
6 // The output should be the exact same.
7 // RUN: %clang_hwasan -g %s -o %t -mllvm -hwasan-record-stack-history=libcall && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
9 // REQUIRES: stable-runtime
11 // Stack histories currently are not recorded on x86.
14 void USE(void *x
) { // pretend_to_do_something(void *x)
15 __asm__
__volatile__("" : : "r" (x
) : "memory");
18 __attribute__((noinline
))
21 char *volatile p
= zzz
;
25 __attribute__((noinline
)) void Unrelated1() { int A
[2]; USE(&A
[0]); }
26 __attribute__((noinline
)) void Unrelated2() { int BB
[3]; USE(&BB
[0]); }
27 __attribute__((noinline
)) void Unrelated3() { int CCC
[4]; USE(&CCC
[0]); }
35 // CHECK: READ of size 1 at
36 // CHECK: #0 {{.*}} in main{{.*}}stack-uar.c:[[@LINE-2]]
37 // CHECK: Cause: stack tag-mismatch
38 // CHECK: is located in stack of thread
39 // CHECK: Potentially referenced stack objects:
40 // CHECK-NEXT: zzz in buggy {{.*}}stack-uar.c:[[@LINE-20]]
41 // CHECK-NEXT: Memory tags around the buggy address
43 // NOSYM: Previously allocated frames:
44 // NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uar.c.tmp+0x{{.*}}){{$}}
45 // NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uar.c.tmp+0x{{.*}}){{$}}
46 // NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uar.c.tmp+0x{{.*}}){{$}}
47 // NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uar.c.tmp+0x{{.*}}){{$}}
48 // NOSYM-NEXT: Memory tags around the buggy address
50 // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main