xref: /llvm-project/compiler-rt/test/hwasan/TestCases/use-after-scope-loop-bug.cpp (revision 847fa84b3d346313bbad31d4c76b0f70d73827aa)
1 // This is the ASAN test of the same name ported to HWAsan.
2 
3 // RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O1 %s -o %t && \
4 // RUN:     not %run %t 2>&1 | FileCheck %s
5 
6 // REQUIRES: aarch64-target-arch || riscv64-target-arch
7 // REQUIRES: stable-runtime
8 
9 volatile int *p;
10 
11 int main() {
12   // Variable goes in and out of scope.
13   for (int i = 0; i < 3; ++i) {
14     int x[3] = {i, i, i};
15     p = x + i;
16   }
17   return *p; // BOOM
18   // CHECK: ERROR: HWAddressSanitizer: tag-mismatch
19   // CHECK:  #0 0x{{.*}} in main {{.*}}use-after-scope-loop-bug.cpp:[[@LINE-2]]
20   // CHECK: Cause: stack tag-mismatch
21 }
22