xref: /llvm-project/clang/test/CodeGen/builtin-nan-exception.c (revision 149f5b573c79eac0c519ada4d2f7c50e17796cdf)
1 // RUN: %clang -target aarch64 -emit-llvm -S %s -o - | FileCheck %s
2 // RUN: %clang -target lanai -emit-llvm -S %s -o - | FileCheck %s
3 // RUN: %clang -target riscv64 -emit-llvm -S %s -o - | FileCheck %s
4 // RUN: %clang -target x86_64 -emit-llvm -S %s -o - | FileCheck %s
5 
6 // Run a variety of targets to ensure there's no target-based difference.
7 
8 // An SNaN with no payload is formed by setting the bit after the
9 // the quiet bit (MSB of the significand).
10 
11 // CHECK: float 0x7FF8000000000000, float 0x7FF4000000000000
12 
13 float f[] = {
14   __builtin_nanf(""),
15   __builtin_nansf(""),
16 };
17 
18 
19 // Doubles are created and converted to floats.
20 // Converting (truncating) to float quiets the NaN (sets the MSB
21 // of the significand) and raises the APFloat invalidOp exception
22 // but that should not cause a compilation error in the default
23 // (ignore FP exceptions) mode.
24 
25 // CHECK: float 0x7FF8000000000000, float 0x7FFC000000000000
26 
27 float converted_to_float[] = {
28   __builtin_nan(""),
29   __builtin_nans(""),
30 };
31 
32 // CHECK: double 0x7FF8000000000000, double 0x7FF4000000000000
33 
34 double d[] = {
35   __builtin_nan(""),
36   __builtin_nans(""),
37 };
38