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 { SelfIntHolder8 __attribute__((noinline)) const IntHolder &Self() const { 9 return *this; 10 } 11 int val = 3; 12 }; 13 14 const IntHolder *saved; 15 main(int argc,char * argv[])16int main(int argc, char *argv[]) { 17 saved = &IntHolder().Self(); 18 int x = saved->val; // BOOM 19 // CHECK: ERROR: AddressSanitizer: stack-use-after-scope 20 // CHECK: #0 0x{{.*}} in main {{.*}}use-after-scope-temp2.cpp:[[@LINE-2]] 21 return x; 22 } 23