Skip to content

Commit

Permalink
Added compiler-rt side test
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Nagy committed Jul 22, 2024
1 parent 4563fab commit 9a00ffd
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions compiler-rt/test/asan/TestCases/dormant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// RUN: %clangxx_asan -DREAD -O0 -mllvm -asan-dormant %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-READ
// RUN: %clangxx_asan -O0 -mllvm -asan-dormant %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WRITE
// REQUIRES: stable-runtime

#include <sanitizer/asan_interface.h>
int readHeapAfterFree(){
int * volatile x = new int[10];
delete[] x;
return x[5];
}

static int * volatile y;
int writeHeapAfterFree(){
y = new int[10];
delete[] y;
return y[5] = 413;
}

int main() {
#ifdef READ
readHeapAfterFree();
// CHECK-READCHECK-NOT {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
__asan_set_dormant(false);
readHeapAfterFree();
// CHECK-READ: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}

#else

writeHeapAfterFree();
// CHECK-WRITE-NOT {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
__asan_set_dormant(false);
writeHeapAfterFree();
// CHECK-WRITE: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
#endif

return 0;
}

0 comments on commit 9a00ffd

Please sign in to comment.