Skip to content

[C2y] Add conformance test for WG14 N3364 #115332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

AaronBallman
Copy link
Collaborator

This paper is defining the translation-time behavior of initialization with a signaling NaN. Clang has always supported the correct behavior.

This paper is defining the translation-time behavior of initialization
with a signaling NaN. Clang has always supported the correct behavior.
@AaronBallman AaronBallman added clang:frontend Language frontend issues, e.g. anything involving "Sema" c2y labels Nov 7, 2024
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Nov 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2024

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

Changes

This paper is defining the translation-time behavior of initialization with a signaling NaN. Clang has always supported the correct behavior.


Full diff: https://github.com/llvm/llvm-project/pull/115332.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+5)
  • (added) clang/test/C/C2y/n3364.c (+35)
  • (modified) clang/www/c_status.html (+1-1)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3e7d8e15110f9d..ae0ec259cf52c2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -286,6 +286,11 @@ C2y Feature Support
   language modes but is now rejected (all of the other qualifiers and storage
   class specifiers were previously rejected).
 
+- Updated conformance for `N3364 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3364.pdf>`_
+  on floating-point translation-time initialization with signaling NaN. This
+  paper adopts Clang's existing practice, so there were no changes to compiler
+  behavior.
+
 C23 Feature Support
 ^^^^^^^^^^^^^^^^^^^
 
diff --git a/clang/test/C/C2y/n3364.c b/clang/test/C/C2y/n3364.c
new file mode 100644
index 00000000000000..277b2643edd6bc
--- /dev/null
+++ b/clang/test/C/C2y/n3364.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -emit-llvm -o - %s
+// RUN: %clang_cc1 -verify -Wall -pedantic -emit-llvm -o - %s
+// expected-no-diagnostics
+
+/* WG14 N3364: Yes
+ * Give consistent wording for SNAN initialization v3
+ *
+ * Ensure that initializing from a signaling NAN (optionally with a unary + or
+ * -) at translation time behaves correctly at runtime.
+ */
+
+#define FLT_SNAN __builtin_nansf("1")
+#define DBL_SNAN __builtin_nans("1")
+#define LD_SNAN __builtin_nansl("1")
+
+float f1 = FLT_SNAN;
+float f2 = +FLT_SNAN;
+float f3 = -FLT_SNAN;
+// CHECK: @f1 = {{.*}}global float 0x7FF0000020000000
+// CHECK: @f2 = {{.*}}global float 0x7FF0000020000000
+// CHECK: @f3 = {{.*}}global float 0xFFF0000020000000
+
+double d1 = DBL_SNAN;
+double d2 = +DBL_SNAN;
+double d3 = -DBL_SNAN;
+// CHECK: @d1 = {{.*}}global double 0x7FF0000000000001
+// CHECK: @d2 = {{.*}}global double 0x7FF0000000000001
+// CHECK: @d3 = {{.*}}global double 0xFFF0000000000001
+
+long double ld1 = LD_SNAN;
+long double ld2 = +LD_SNAN;
+long double ld3 = -LD_SNAN;
+// CHECK: @ld1 = {{.*}}global {{double 0x7FF0000000000001|x86_fp80 0xK7FFF8000000000000001|fp128 0xL00000000000000017FFF000000000000}}
+// CHECK: @ld2 = {{.*}}global {{double 0x7FF0000000000001|x86_fp80 0xK7FFF8000000000000001|fp128 0xL00000000000000017FFF000000000000}}
+// CHECK: @ld3 = {{.*}}global {{double 0xFFF0000000000001|x86_fp80 0xKFFFF8000000000000001|fp128 0xL0000000000000001FFFF000000000000}}
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index e66424290e6d50..989a572ae70fb6 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -231,7 +231,7 @@ <h2 id="c2y">C2y implementation status</h2>
     <tr>
       <td>Give consistent wording for SNAN initialization v3</td>
       <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3364.pdf">N3364</a></td>
-      <td class="unknown" align="center">Unknown</td>
+      <td class="full" align="center">Yes</td>
     </tr>
     <tr>
       <td>Case range expressions v3.1</td>

long double ld1 = LD_SNAN;
long double ld2 = +LD_SNAN;
long double ld3 = -LD_SNAN;
// CHECK: @ld1 = {{.*}}global {{double 0x7FF0000000000001|x86_fp80 0xK7FFF8000000000000001|fp128 0xL00000000000000017FFF000000000000}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jcranmer-intel : I recall seeing in the past that we sometimes print floats as scientific notation. Is this/the above in danger in any way because of it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are sNaN values, which can't be emitted as a regular decimal floating-point literals. There is an outstanding patch right now to emit NaNs and infinities not in this special hexadecimal syntax (instead something like nan(u0x1), syntax still somewhat TBD), but I would assume such a patch would adjust these test results as necessary.

@AaronBallman AaronBallman merged commit c1ead03 into llvm:main Nov 7, 2024
13 checks passed
@AaronBallman AaronBallman deleted the aballman-wg14-n3364 branch November 7, 2024 16:54
Groverkss pushed a commit to iree-org/llvm-project that referenced this pull request Nov 15, 2024
This paper is defining the translation-time behavior of initialization
with a signaling NaN. Clang has always supported the correct behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c2y clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants