1 // RUN: %clangxx_asan -O1 -fsanitize-address-use-after-scope %s -o %t && \
2 // RUN:     not %run %t 2>&1 | FileCheck %s
3 
4 // -fsanitize-address-use-after-scope is now on by default:
5 // RUN: %clangxx_asan -O1 %s -o %t && \
6 // RUN:     not %run %t 2>&1 | FileCheck %s
7 //
8 // Not expected to work yet with HWAsan.
9 // XFAIL: *
10 
11 volatile int *p = 0;
12 
13 int main() {
14   {
15     int x = 0;
16     p = &x;
17   }
18   *p = 5; // BOOM
19   // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
20   // CHECK:  #0 0x{{.*}} in main {{.*}}use-after-scope.cpp:[[@LINE-2]]
21   // CHECK: Address 0x{{.*}} is located in stack of thread T{{.*}} at offset [[OFFSET:[^ ]+]] in frame
22   // {{\[}}[[OFFSET]], {{[0-9]+}}) 'x'
23   return 0;
24 }
25