Move MSan lit-tests under test/msan
[blocksruntime.git] / lib / asan / lit_tests / TestCases / use-after-scope-dtor-order.cc
blob32fa6ad8a46446c3ded4df623da45a38250fb882
1 // RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \
2 // RUN: not %t 2>&1 | FileCheck %s
3 #include <stdio.h>
5 struct IntHolder {
6 explicit IntHolder(int *val = 0) : val_(val) { }
7 ~IntHolder() {
8 printf("Value: %d\n", *val_); // BOOM
9 // CHECK: ERROR: AddressSanitizer: stack-use-after-scope
10 // CHECK: #0 0x{{.*}} in IntHolder::~IntHolder{{.*}}use-after-scope-dtor-order.cc:[[@LINE-2]]
12 void set(int *val) { val_ = val; }
13 int *get() { return val_; }
15 int *val_;
18 int main(int argc, char *argv[]) {
19 // It is incorrect to use "x" int IntHolder destructor, because "x" is
20 // "destroyed" earlier as it's declared later.
21 IntHolder holder;
22 int x = argc;
23 holder.set(&x);
24 return 0;