-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthew Nagy
committed
Jul 22, 2024
1 parent
4563fab
commit 9a00ffd
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |