1// RUN: %clangxx_asan %if MSVC %{ /Od %} %else %{ -O1 %} \
2// RUN: %s -o %t && not %run %t 2>&1 | FileCheck %s
3
4#include "defines.h"
5struct IntHolder {
6 int val;
7};
8
9const IntHolder *saved;
10
11ATTRIBUTE_NOINLINE void save(const IntHolder &holder) { saved = &holder; }
12
13int main(int argc, char *argv[]) {
14 save(holder: {.val: argc});
15 int x = saved->val; // BOOM
16 // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
17 // CHECK: #0 0x{{.*}} in main {{.*}}use-after-scope-temp.cpp:[[@LINE-2]]
18 return x;
19}
20

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of compiler-rt/test/asan/TestCases/use-after-scope-temp.cpp