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