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 4 5 // REQUIRES: stable-runtime 6 USE(void * x)7void USE(void *x) { // pretend_to_do_something(void *x) 8 __asm__ __volatile__("" : : "r" (x) : "memory"); 9 } 10 11 __attribute__((noinline)) buggy()12char *buggy() { 13 char zzz[0x1000]; 14 char *volatile p = zzz; 15 return p; 16 } 17 Unrelated1()18__attribute__((noinline)) void Unrelated1() { int A[2]; USE(&A[0]); } Unrelated2()19__attribute__((noinline)) void Unrelated2() { int BB[3]; USE(&BB[0]); } Unrelated3()20__attribute__((noinline)) void Unrelated3() { int CCC[4]; USE(&CCC[0]); } 21 main()22int main() { 23 char *p = buggy(); 24 Unrelated1(); 25 Unrelated2(); 26 Unrelated3(); 27 return *p; 28 // CHECK: READ of size 1 at 29 // CHECK: #0 {{.*}} in main{{.*}}stack-uar.c:[[@LINE-2]] 30 // CHECK: is located in stack of thread 31 // CHECK: Potentially referenced stack objects: 32 // CHECK-NEXT: zzz in buggy {{.*}}stack-uar.c:[[@LINE-19]] 33 // CHECK-NEXT: Memory tags around the buggy address 34 35 // NOSYM: Previously allocated frames: 36 // NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uar.c.tmp+0x{{.*}}){{$}} 37 // NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uar.c.tmp+0x{{.*}}){{$}} 38 // NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uar.c.tmp+0x{{.*}}){{$}} 39 // NOSYM-NEXT: record_addr:0x{{.*}} record:0x{{.*}} ({{.*}}/stack-uar.c.tmp+0x{{.*}}){{$}} 40 // NOSYM-NEXT: Memory tags around the buggy address 41 42 // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main 43 } 44