xref: /llvm-project/clang/test/CodeGen/builtin-nan-exception.c (revision 149f5b573c79eac0c519ada4d2f7c50e17796cdf)
1187686beSSanjay Patel // RUN: %clang -target aarch64 -emit-llvm -S %s -o - | FileCheck %s
2187686beSSanjay Patel // RUN: %clang -target lanai -emit-llvm -S %s -o - | FileCheck %s
3187686beSSanjay Patel // RUN: %clang -target riscv64 -emit-llvm -S %s -o - | FileCheck %s
4187686beSSanjay Patel // RUN: %clang -target x86_64 -emit-llvm -S %s -o - | FileCheck %s
5187686beSSanjay Patel 
6187686beSSanjay Patel // Run a variety of targets to ensure there's no target-based difference.
7187686beSSanjay Patel 
8187686beSSanjay Patel // An SNaN with no payload is formed by setting the bit after the
9187686beSSanjay Patel // the quiet bit (MSB of the significand).
10187686beSSanjay Patel 
11187686beSSanjay Patel // CHECK: float 0x7FF8000000000000, float 0x7FF4000000000000
12187686beSSanjay Patel 
13187686beSSanjay Patel float f[] = {
1481921ebcSSanjay Patel   __builtin_nanf(""),
1581921ebcSSanjay Patel   __builtin_nansf(""),
1681921ebcSSanjay Patel };
1781921ebcSSanjay Patel 
1881921ebcSSanjay Patel 
1981921ebcSSanjay Patel // Doubles are created and converted to floats.
20*149f5b57SSanjay Patel // Converting (truncating) to float quiets the NaN (sets the MSB
21*149f5b57SSanjay Patel // of the significand) and raises the APFloat invalidOp exception
22*149f5b57SSanjay Patel // but that should not cause a compilation error in the default
23*149f5b57SSanjay Patel // (ignore FP exceptions) mode.
2481921ebcSSanjay Patel 
25*149f5b57SSanjay Patel // CHECK: float 0x7FF8000000000000, float 0x7FFC000000000000
2681921ebcSSanjay Patel 
2781921ebcSSanjay Patel float converted_to_float[] = {
28187686beSSanjay Patel   __builtin_nan(""),
29187686beSSanjay Patel   __builtin_nans(""),
30187686beSSanjay Patel };
31187686beSSanjay Patel 
3281921ebcSSanjay Patel // CHECK: double 0x7FF8000000000000, double 0x7FF4000000000000
3381921ebcSSanjay Patel 
34187686beSSanjay Patel double d[] = {
35187686beSSanjay Patel   __builtin_nan(""),
36187686beSSanjay Patel   __builtin_nans(""),
37187686beSSanjay Patel };
38