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
20int main() {
21 float val = ReturnNaN(p: 0., q: 0.);
22 printf("%f\n", val);
23 // CHECK: WARNING: NumericalStabilitySanitizer: NaN detected
24 return 0;
25}
26

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of compiler-rt/test/nsan/nan.cpp