xref: /llvm-project/compiler-rt/test/asan/TestCases/wild_pointer.cpp (revision 6f37d18d8cb109848b16ab55b631a9bdb4956a7a)
1 // RUN: %clangxx_asan %s -o %t
2 // RUN: not %run %t 2>&1 | FileCheck %s
3 // REQUIRES: asan-64-bits
4 
5 #include <inttypes.h>
6 #include <stdarg.h>
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <string.h>
10 
main()11 int main() {
12   char *p = new char;
13   char *dest = new char;
14   const size_t offset = 0x4567890123456789;
15 
16   // The output here needs to match the output from the sanitizer runtime,
17   // which includes 0x and prints hex in lower case.
18   //
19   // On Windows, %p omits %0x and prints hex characters in upper case,
20   // so we use PRIxPTR instead of %p.
21   fprintf(stderr, "Expected bad addr: %#" PRIxPTR "\n",
22           reinterpret_cast<uintptr_t>(p + offset));
23   // Flush it so the output came out before the asan report.
24   fflush(stderr);
25 
26   memmove(dest, p, offset);
27   return 0;
28 }
29 
30 // CHECK: Expected bad addr: [[ADDR:0x[0-9,a-f]+]]
31 // CHECK: AddressSanitizer: unknown-crash on address [[ADDR]]
32 // CHECK: Address [[ADDR]] is a wild pointer inside of access range of size 0x4567890123456789
33