xref: /llvm-project/compiler-rt/test/asan/TestCases/use-after-scope-temp2.cpp (revision cd269daf25016f7115424a51ab5e7977a80e072d)
1 // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 
3 struct IntHolder {
SelfIntHolder4   __attribute__((noinline)) const IntHolder &Self() const {
5     return *this;
6   }
7   int val = 3;
8 };
9 
10 const IntHolder *saved;
11 
main(int argc,char * argv[])12 int main(int argc, char *argv[]) {
13   saved = &IntHolder().Self();
14   int x = saved->val;  // BOOM
15   // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
16   // CHECK:  #0 0x{{.*}} in main {{.*}}use-after-scope-temp2.cpp:[[@LINE-2]]
17   return x;
18 }
19