]>
Commit | Line | Data |
---|---|---|
5bcae85e | 1 | // RUN: %clangxx_asan -O1 -fsanitize-address-use-after-scope %s -o %t && \ |
1a4d82fc | 2 | // RUN: not %run %t 2>&1 | FileCheck %s |
5bcae85e | 3 | |
1a4d82fc JJ |
4 | #include <stdio.h> |
5 | ||
6 | struct IntHolder { | |
7 | explicit IntHolder(int *val = 0) : val_(val) { } | |
8 | ~IntHolder() { | |
9 | printf("Value: %d\n", *val_); // BOOM | |
10 | // CHECK: ERROR: AddressSanitizer: stack-use-after-scope | |
5bcae85e | 11 | // CHECK: #0 0x{{.*}} in IntHolder::~IntHolder{{.*}}.cc:[[@LINE-2]] |
1a4d82fc JJ |
12 | } |
13 | void set(int *val) { val_ = val; } | |
14 | int *get() { return val_; } | |
15 | ||
16 | int *val_; | |
17 | }; | |
18 | ||
19 | int main(int argc, char *argv[]) { | |
20 | // It is incorrect to use "x" int IntHolder destructor, because "x" is | |
21 | // "destroyed" earlier as it's declared later. | |
22 | IntHolder holder; | |
23 | int x = argc; | |
24 | holder.set(&x); | |
25 | return 0; | |
26 | } |