1 // RUN: %clangxx_asan %stdcxx11 -O1 -fsanitize-address-use-after-scope %s -o %t && \
2 // RUN:     not %run %t 2>&1 | FileCheck %s
3 //
4 // Not expected to work yet with HWAsan.
5 // XFAIL: *
6 
7 struct IntHolder {
8   int val;
9 };
10 
11 const IntHolder *saved;
12 
13 __attribute__((noinline)) void save(const IntHolder &holder) {
14   saved = &holder;
15 }
16 
17 int main(int argc, char *argv[]) {
18   save({argc});
19   int x = saved->val; // BOOM
20   // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
21   // CHECK:  #0 0x{{.*}} in main {{.*}}use-after-scope-temp.cpp:[[@LINE-2]]
22   return x;
23 }
24