31 lines · cpp
1// RUN: %clangxx_asan -std=c++11 -O0 %s -o %t2// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=READ3// RUN: not %run %t write 2>&1 | FileCheck %s --check-prefix=WRITE4 5#include "../defines.h"6#include <stdio.h>7#include <windows.h>8 9static volatile int sink;10ATTRIBUTE_NOINLINE void Read(int *ptr) { sink = *ptr; }11ATTRIBUTE_NOINLINE void Write(int *ptr) { *ptr = 0; }12int main(int argc, char **argv) {13 // Writes to shadow are detected as reads from shadow gap (because of how the14 // shadow mapping works). This is kinda hard to fix. Test a random address in15 // the application part of the address space.16 void *volatile p = VirtualAlloc(0, 4096, MEM_COMMIT, PAGE_READONLY);17 bool ok = VirtualFree(p, 0, MEM_RELEASE);18 if (!ok) {19 printf("VirtualFree failed\n");20 return 0;21 }22 if (argc == 1)23 Read((int *)p);24 else25 Write((int *)p);26}27// READ: AddressSanitizer: access-violation on unknown address28// READ: The signal is caused by a READ memory access.29// WRITE: AddressSanitizer: access-violation on unknown address30// WRITE: The signal is caused by a WRITE memory access.31