[libc] [llvm] [libc][math] Implement nan(f|l) functions (PR #76690)

Nishant Mittal via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 23:56:19 PST 2024


================
@@ -0,0 +1,40 @@
+//===-- Unittests for nan -------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "src/math/nan.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+class LlvmLibcNanTest : public LIBC_NAMESPACE::testing::Test {
+public:
+  using StorageType = LIBC_NAMESPACE::fputil::FPBits<double>::StorageType;
+
+  void run_test(const char *input_str, StorageType bits) {
+    double result = LIBC_NAMESPACE::nan(input_str);
+    auto actual_fp = LIBC_NAMESPACE::fputil::FPBits<double>(result);
+    auto expected_fp = LIBC_NAMESPACE::fputil::FPBits<double>(bits);
+    EXPECT_EQ(actual_fp.bits, expected_fp.bits);
+  };
+};
+
+TEST_F(LlvmLibcNanTest, NCharSeq) {
+  run_test("", 0x7ff8000000000000);
----------------
nishantwrp wrote:

It will crash with a segmentation fault, added death tests for it. 

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


More information about the llvm-commits mailing list