1// Test the handle_sigfpe option.
2// RUN: %clangxx %s -o %t
3// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s
4// RUN: %env_tool_opts=handle_sigfpe=0 not --crash %run %t 2>&1 | FileCheck --check-prefix=CHECK0 %s
5// RUN: %env_tool_opts=handle_sigfpe=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK1 %s
6
7// FIXME: seems to fail on ARM
8// REQUIRES: x86_64-target-arch
9#include <assert.h>
10#include <stdio.h>
11#include <sanitizer/asan_interface.h>
12
13void death() {
14 fprintf(stderr, format: "DEATH CALLBACK\n");
15}
16
17int main(int argc, char **argv) {
18 __sanitizer_set_death_callback(callback: death);
19 volatile int one = 1;
20 volatile int zero = 0;
21 volatile int sink;
22 sink = one / zero;
23}
24
25// CHECK0-NOT: Sanitizer:DEADLYSIGNAL
26// CHECK1: ERROR: {{.*}}Sanitizer: FPE
27// CHECK1: {{#[0-9]+.* main .*fpe\.cpp}}:[[@LINE-5]]
28// CHECK1: DEATH CALLBACK
29// CHECK0-NOT: {{.*}}Sanitizer: FPE
30

source code of compiler-rt/test/sanitizer_common/TestCases/Posix/fpe.cpp