26 lines · cpp
1// RUN: %clangxx_nsan -O0 -g %s -o %t2// RUN: env NSAN_OPTIONS=check_nan=true,halt_on_error=0 %run %t 2>&1 | FileCheck %s3 4// RUN: %clangxx_nsan -O3 -g %s -o %t5// RUN: env NSAN_OPTIONS=check_nan=true,halt_on_error=0 %run %t 2>&1 | FileCheck %s6 7// RUN: %clangxx_nsan -O0 -g %s -o %t8// RUN: env NSAN_OPTIONS=check_nan=true,halt_on_error=1 not %run %t9 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 detected18}19 20int main() {21 float val = ReturnNaN(0., 0.);22 printf("%f\n", val);23 // CHECK: WARNING: NumericalStabilitySanitizer: NaN detected24 return 0;25}26