]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc
New upstream version 1.12.0+dfsg1
[rustc.git] / src / compiler-rt / test / sanitizer_common / TestCases / Posix / sanitizer_set_report_fd_test.cc
1 // Test __sanitizer_set_report_fd:
2 // RUN: %clangxx -O2 %s -o %t
3 // RUN: not %run %t 2>&1 | FileCheck %s
4 // RUN: not %run %t stdout | FileCheck %s
5 // RUN: not %run %t %t-out && FileCheck < %t-out %s
6
7 // REQUIRES: stable-runtime
8 // FIXME: implement SEGV handler in other sanitizers, not just asan.
9 // XFAIL: msan
10 // XFAIL: lsan
11 // XFAIL: tsan
12
13 #include <sanitizer/common_interface_defs.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <stdlib.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <fcntl.h>
20 #include <assert.h>
21
22 volatile int *null = 0;
23
24 int main(int argc, char **argv) {
25 if (argc == 2) {
26 if (!strcmp(argv[1], "stdout")) {
27 __sanitizer_set_report_fd(reinterpret_cast<void*>(1));
28 } else {
29 int fd = open(argv[1], O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU);
30 assert(fd > 0);
31 __sanitizer_set_report_fd(reinterpret_cast<void*>(fd));
32 }
33 }
34 *null = 0;
35 }
36
37 // CHECK: ERROR: {{.*}} SEGV on unknown address