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