Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Linux / cuda_test.cpp
blobe532f2ee7bf8dbb1370ab6b9ce1daae186550cf3
1 // Emulate the behavior of the NVIDIA CUDA driver
2 // that mmaps memory inside the asan's shadow gap.
3 //
4 // REQUIRES: x86_64-target-arch, shadow-scale-3
5 //
6 // RUN: %clangxx_asan %s -o %t
7 // RUN: not %env_asan_opts=protect_shadow_gap=1 %t 2>&1 | FileCheck %s --check-prefix=CHECK-PROTECT1
8 // RUN: not %t 2>&1 | FileCheck %s --check-prefix=CHECK-PROTECT1
9 // RUN: not %env_asan_opts=protect_shadow_gap=0 %t 2>&1 | FileCheck %s --check-prefix=CHECK-PROTECT0
10 #include <assert.h>
11 #include <unistd.h>
12 #include <sys/mman.h>
13 #include <stdint.h>
15 #include "sanitizer/asan_interface.h"
17 int main(void) {
18 uintptr_t Base = 0x200000000;
19 uintptr_t Size = 0x1100000000;
20 void *addr =
21 mmap((void *)Base, Size, PROT_READ | PROT_WRITE,
22 MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 0, 0);
23 assert(addr == (void*)Base);
24 // Make sure we can access memory in shadow gap.
25 // W/o protect_shadow_gap=0 we should fail here.
26 for (uintptr_t Addr = Base; Addr < Base + Size; Addr += Size / 100)
27 *(char*)Addr = 1;
28 // CHECK-PROTECT1: AddressSanitizer: SEGV on unknown address 0x0000bfff8000
30 // Poison a part of gap's shadow:
31 __asan_poison_memory_region((void*)Base, 4096);
32 // Now we should fail with use-after-poison.
33 *(char*)(Base + 1234) = 1;
34 // CHECK-PROTECT0: AddressSanitizer: use-after-poison on address 0x0002000004d2