xref: /llvm-project/compiler-rt/test/nsan/nan.cpp (revision 52ae891036e3ab1f668eb103c46ca57257901c6b)
1 // RUN: %clangxx_nsan -O0 -g %s -o %t
2 // RUN: env NSAN_OPTIONS=check_nan=true,halt_on_error=0 %run %t 2>&1 | FileCheck %s
3 
4 // RUN: %clangxx_nsan -O3 -g %s -o %t
5 // RUN: env NSAN_OPTIONS=check_nan=true,halt_on_error=0 %run %t 2>&1 | FileCheck %s
6 
7 // RUN: %clangxx_nsan -O0 -g %s -o %t
8 // RUN: env NSAN_OPTIONS=check_nan=true,halt_on_error=1 not %run %t
9 
10 #include <cmath>
11 #include <cstdio>
12 
13 // This function returns a NaN value for triggering the NaN detection.
14 __attribute__((noinline)) float ReturnNaN(float p, float q) {
15   float ret = p / q;
16   return ret;
17   // CHECK: WARNING: NumericalStabilitySanitizer: NaN detected
18 }
19 
20 int main() {
21   float val = ReturnNaN(0., 0.);
22   printf("%f\n", val);
23   // CHECK: WARNING: NumericalStabilitySanitizer: NaN detected
24   return 0;
25 }
26