Skip to content

Commit a43e25e

Browse files
committed
[compiler-rt][nsan] Add test for NaN dectection
1 parent 3a70ccb commit a43e25e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

compiler-rt/test/nsan/nan.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clangxx_nsan -O0 -g %s -o %t
2+
// RUN: NSAN_OPTIONS=check_nan=true %run %t 2>&1 | FileCheck %s
3+
4+
5+
#include<cmath>
6+
#include<cstdio>
7+
8+
// This function returns a NaN value for triggering the NaN detection.
9+
__attribute__((noinline))
10+
float ReturnNaN() {
11+
float ret = 0.0 / 0.0;
12+
return ret;
13+
// CHECK: WARNING: NumericalStabilitySanitizer: NaN detected
14+
}
15+
16+
17+
int main() {
18+
float val = ReturnNaN();
19+
printf("val: %f\n", val);
20+
// CHECK: WARNING: NumericalStabilitySanitizer: NaN detected
21+
return 0;
22+
}

0 commit comments

Comments
 (0)