[compiler-rt] [compiler-rt][nsan] Add support for nan detection (PR #101531)

Alexander Shaposhnikov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 11:51:20 PDT 2024


alexander-shaposhnikov wrote:

@cseslowpoke 
I've applied locally your patch on top the current trunk and tried the example
```
#include <iostream>
#include <cmath>

typedef float v8sf __attribute__ ((vector_size(32)));

v8sf simd_sqrt(v8sf a) {
  return __builtin_elementwise_sqrt(a);
}

int main() {
  v8sf a = {1.0, -2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
  a = simd_sqrt(a);

  // This prevents DCE.
  for (size_t i = 0; i < 8; ++i) {
    std::cout << a[i] << std::endl;
  }

  return 0;
}

```

```
clang++ -fsanitize=numerical -mavx -O3 -g ~/simd.cpp -o ~/simd.exe
NSAN_OPTIONS=check_nan=true,halt_on_error=0 ~/simd.exe
```
works as expected.
Let's use it as a test for now.

https://github.com/llvm/llvm-project/pull/101531


More information about the llvm-commits mailing list