1 // When we link a binary without the -debug flag, ASan should print out VAs
2 // instead of RVAs. The frames for main and do_uaf should be above 0x400000,
3 // which is the default image base of an executable.
4 
5 // RUN: rm -f %t.pdb
6 // RUN: %clangxx_asan -c -O2 %s -o %t.obj
7 // RUN: link /nologo /OUT:%t.exe %t.obj %asan_lib %asan_cxx_lib
8 // RUN: not %run %t.exe 2>&1 | FileCheck %s
9 
10 #include <stdlib.h>
11 #include <stdio.h>
12 int __attribute__((noinline)) do_uaf(void);
main()13 int main() {
14   int r = do_uaf();
15   printf("r: %d\n", r);
16   return r;
17 }
do_uaf(void)18 int do_uaf(void) {
19   char *x = (char*)malloc(10 * sizeof(char));
20   free(x);
21   return x[5];
22   // CHECK: AddressSanitizer: heap-use-after-free
23   // CHECK: #0 {{0x[a-f0-9]+ \(.*[\\/]unsymbolized.cc.*.exe\+0x40[a-f0-9]{4}\)}}
24   // CHECK: #1 {{0x[a-f0-9]+ \(.*[\\/]unsymbolized.cc.*.exe\+0x40[a-f0-9]{4}\)}}
25 }
26