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