[CodeGen] add test for NAN creation; NFC
authorSanjay Patel <spatel@rotateright.com>
Wed, 30 Sep 2020 17:18:42 +0000 (13:18 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 30 Sep 2020 17:22:12 +0000 (13:22 -0400)
This goes with the APFloat change proposed in
D88238.
This is copied from the MIPS-specific test in
builtin-nan-legacy.c to verify that the normal
behavior is correct on other targets without the
complication of an inverted quiet bit.

clang/test/CodeGen/builtin-nan-exception.c [new file with mode: 0644]

diff --git a/clang/test/CodeGen/builtin-nan-exception.c b/clang/test/CodeGen/builtin-nan-exception.c
new file mode 100644 (file)
index 0000000..2acf0c4
--- /dev/null
@@ -0,0 +1,23 @@
+// RUN: %clang -target aarch64 -emit-llvm -S %s -o - | FileCheck %s
+// RUN: %clang -target lanai -emit-llvm -S %s -o - | FileCheck %s
+// RUN: %clang -target riscv64 -emit-llvm -S %s -o - | FileCheck %s
+// RUN: %clang -target x86_64 -emit-llvm -S %s -o - | FileCheck %s
+
+// Run a variety of targets to ensure there's no target-based difference.
+
+// The builtin always produces a 64-bit (double).
+// An SNaN with no payload is formed by setting the bit after the
+// the quiet bit (MSB of the significand).
+
+// CHECK: float 0x7FF8000000000000, float 0x7FF4000000000000
+// CHECK: double 0x7FF8000000000000, double 0x7FF4000000000000
+
+float f[] = {
+  __builtin_nan(""),
+  __builtin_nans(""),
+};
+
+double d[] = {
+  __builtin_nan(""),
+  __builtin_nans(""),
+};