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