1 // Test __sanitizer_set_report_fd:
2 // Fails with debug checks: https://bugs.llvm.org/show_bug.cgi?id=46860
3 // XFAIL: !compiler-rt-optimized && tsan
4 // RUN: %clangxx -O2 %s -o %t
5 // RUN: not %run %t 2>&1   | FileCheck %s
6 // RUN: not %run %t stdout | FileCheck %s
7 // RUN: not %run %t %t-out && FileCheck < %t-out %s
8 
9 // REQUIRES: stable-runtime
10 // XFAIL: android && asan
11 
12 #include <sanitizer/common_interface_defs.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <fcntl.h>
19 #include <assert.h>
20 
21 volatile int *null = 0;
22 
main(int argc,char ** argv)23 int main(int argc, char **argv) {
24   if (argc == 2) {
25     if (!strcmp(argv[1], "stdout")) {
26       __sanitizer_set_report_fd(reinterpret_cast<void*>(1));
27     } else {
28       int fd = open(argv[1], O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU);
29       assert(fd > 0);
30       __sanitizer_set_report_fd(reinterpret_cast<void*>(fd));
31     }
32   }
33   *null = 0;
34 }
35 
36 // CHECK: ERROR: {{.*}} SEGV on unknown address
37