2021-08-02 15:58:49 +08:00
|
|
|
// This is the ASAN test of the same name ported to HWAsan.
|
|
|
|
|
|
|
|
// RUN: %clangxx_hwasan -mllvm -hwasan-use-after-scope -O1 %s -o %t && \
|
2021-07-16 23:30:37 +08:00
|
|
|
// RUN: not %run %t 2>&1 | FileCheck %s
|
2021-08-02 15:58:49 +08:00
|
|
|
|
|
|
|
// REQUIRES: aarch64-target-arch
|
|
|
|
// REQUIRES: stable-runtime
|
2021-07-16 23:30:37 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
struct IntHolder {
|
2021-07-19 18:16:38 +08:00
|
|
|
explicit IntHolder(int *val = 0) : val_(val) {}
|
2021-07-16 23:30:37 +08:00
|
|
|
__attribute__((noinline)) ~IntHolder() {
|
2021-07-19 18:16:38 +08:00
|
|
|
printf("Value: %d\n", *val_); // BOOM
|
2021-08-02 15:58:49 +08:00
|
|
|
// CHECK: ERROR: HWAddressSanitizer: tag-mismatch
|
2021-07-16 23:30:37 +08:00
|
|
|
// CHECK: #0 0x{{.*}} in IntHolder::~IntHolder{{.*}}.cpp:[[@LINE-2]]
|
|
|
|
}
|
|
|
|
void set(int *val) { val_ = val; }
|
|
|
|
int *get() { return val_; }
|
|
|
|
|
|
|
|
int *val_;
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
// It is incorrect to use "x" int IntHolder destructor, because "x" is
|
|
|
|
// "destroyed" earlier as it's declared later.
|
|
|
|
IntHolder holder;
|
|
|
|
int x = argc;
|
|
|
|
holder.set(&x);
|
|
|
|
return 0;
|
|
|
|
}
|