xref: /llvm-project/compiler-rt/test/asan/TestCases/use-after-scope-capture.cpp (revision 45e2c6c5cd52833af09c09741ec8dd7e7c925019)
1 // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 
3 #include <functional>
4 
main()5 int main() {
6   std::function<int()> f;
7   {
8     int x = 0;
9     f = [&x]() __attribute__((noinline)) {
10       return x;  // BOOM
11       // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
12       // We cannot assert the line, after the argument promotion pass this crashes
13       // in the BOOM line below instead, when the ref gets turned into a value.
14       // CHECK: #0 0x{{.*}} in {{.*}}use-after-scope-capture.cpp
15     };
16   }
17   return f();  // BOOM
18 }
19