[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / use-after-scope-dtor-order.cpp
blobcd2ed4b82fd6edc6d1615fd31bcb825634029a9b
1 // This is the ASAN test of the same name ported to HWAsan.
3 // RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O1 %s -o %t && \
4 // RUN: not %run %t 2>&1 | FileCheck %s
6 // REQUIRES: aarch64-target-arch
7 // REQUIRES: stable-runtime
9 #include <stdio.h>
11 struct IntHolder {
12 explicit IntHolder(int *val = 0) : val_(val) {}
13 __attribute__((noinline)) ~IntHolder() {
14 printf("Value: %d\n", *val_); // BOOM
15 // CHECK: ERROR: HWAddressSanitizer: tag-mismatch
16 // CHECK: #0 0x{{.*}} in IntHolder::~IntHolder{{.*}}.cpp:[[@LINE-2]]
18 void set(int *val) { val_ = val; }
19 int *get() { return val_; }
21 int *val_;
24 int main(int argc, char *argv[]) {
25 // It is incorrect to use "x" int IntHolder destructor, because "x" is
26 // "destroyed" earlier as it's declared later.
27 IntHolder holder;
28 int x = argc;
29 holder.set(&x);
30 return 0;