24 lines · cpp
1// This is the ASAN test of the same name ported to HWAsan.2 3// RUN: %clangxx_hwasan --std=c++11 -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s4 5// REQUIRES: aarch64-target-arch || riscv64-target-arch6 7#include <functional>8 9int main() {10 std::function<int()> f;11 {12 volatile int x = 0;13 f = [&x]() __attribute__((noinline)) {14 return x; // BOOM15 // CHECK: ERROR: HWAddressSanitizer: tag-mismatch16 // We cannot assert the line, after the argument promotion pass this crashes17 // in the BOOM line below instead, when the ref gets turned into a value.18 // CHECK: 0x{{.*}} in {{.*}}use-after-scope-capture.cpp19 // CHECK: Cause: stack tag-mismatch20 };21 }22 return f(); // BOOM23}24