Files
clang-p2996/compiler-rt/test/asan/TestCases/use-after-scope-capture.cpp
Paul Kirth 45e2c6c5cd [asan][test] Fix use-after-scope-capture test after D148269
After enabling ArgPromotion at lower opt levels, the body of this test
was optimized away, and the CHECK lines no longer functioned.

Setting -O0 is a hammer, but gets the test passing again, until code owners
can find a better solution.

Reviewed By: fmayer

Differential Revision: https://reviews.llvm.org/D148396
2023-04-15 00:10:49 +00:00

19 lines
547 B
C++

// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
#include <functional>
int main() {
std::function<int()> f;
{
int x = 0;
f = [&x]() __attribute__((noinline)) {
return x; // BOOM
// CHECK: ERROR: AddressSanitizer: stack-use-after-scope
// We cannot assert the line, after the argument promotion pass this crashes
// in the BOOM line below instead, when the ref gets turned into a value.
// CHECK: #0 0x{{.*}} in {{.*}}use-after-scope-capture.cpp
};
}
return f(); // BOOM
}