xref: /llvm-project/compiler-rt/test/hwasan/TestCases/use-after-scope-temp.cpp (revision 6cc9244baa63fcb7c6f35f46dab9fa17a421a6ce)
1 // This is the ASAN test of the same name ported to HWAsan.
2 
3 // RUN: %clangxx_hwasan -std=c++11 -O1 %s -o %t && \
4 // RUN:     not %run %t 2>&1 | FileCheck %s
5 
6 // REQUIRES: aarch64-target-arch || riscv64-target-arch
7 
8 struct IntHolder {
9   int val;
10 };
11 
12 const IntHolder *saved;
13 
save(const IntHolder & holder)14 __attribute__((noinline)) void save(const IntHolder &holder) {
15   saved = &holder;
16 }
17 
main(int argc,char * argv[])18 int main(int argc, char *argv[]) {
19   save({argc});
20   int x = saved->val; // BOOM
21   // CHECK: ERROR: HWAddressSanitizer: tag-mismatch
22   // CHECK:  #0 0x{{.*}} in main {{.*}}use-after-scope-temp.cpp:[[@LINE-2]]
23   // CHECK: Cause: stack tag-mismatch
24   return x;
25 }
26