summaryrefslogtreecommitdiff
path: root/test/sanitizer_common/TestCases/Posix/sanitizer_set_report_fd_test.cc
blob: 416944fa6d1024ec78bf7562f191a04b033032a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Test __sanitizer_set_report_fd:
// RUN: %clangxx -O2 %s -o %t
// RUN: not %run %t 2>&1   | FileCheck %s
// RUN: not %run %t stdout | FileCheck %s
// RUN: not %run %t %t-out && FileCheck < %t-out %s

// REQUIRES: stable-runtime
// XFAIL: android && i386-target-arch && asan
// FIXME: implement SEGV handler in other sanitizers, not just asan.
// XFAIL: msan
// XFAIL: tsan

#include <sanitizer/common_interface_defs.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>

volatile int *null = 0;

int main(int argc, char **argv) {
  if (argc == 2) {
    if (!strcmp(argv[1], "stdout")) {
      __sanitizer_set_report_fd(reinterpret_cast<void*>(1));
    } else {
      int fd = open(argv[1], O_CREAT | O_WRONLY | O_TRUNC, S_IRWXU);
      assert(fd > 0);
      __sanitizer_set_report_fd(reinterpret_cast<void*>(fd));
    }
  }
  *null = 0;
}

// CHECK: ERROR: {{.*}} SEGV on unknown address