[clang] 7955bde - [C11] Add test coverage for N1310 and claim conformance

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 20 12:08:55 PDT 2024


Author: Aaron Ballman
Date: 2024-03-20T15:08:43-04:00
New Revision: 7955bde64ef9aebbcaf6b6308a25fac31041ea9a

URL: https://github.com/llvm/llvm-project/commit/7955bde64ef9aebbcaf6b6308a25fac31041ea9a
DIFF: https://github.com/llvm/llvm-project/commit/7955bde64ef9aebbcaf6b6308a25fac31041ea9a.diff

LOG: [C11] Add test coverage for N1310 and claim conformance

This is about the best I could do for testing that `signed char` does
not have any padding bits.

Added: 
    clang/test/C/C11/n1310.c

Modified: 
    clang/www/c_status.html

Removed: 
    


################################################################################
diff  --git a/clang/test/C/C11/n1310.c b/clang/test/C/C11/n1310.c
new file mode 100644
index 00000000000000..7f8dd754f74631
--- /dev/null
+++ b/clang/test/C/C11/n1310.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -verify -std=c89 %s
+// RUN: %clang_cc1 -verify -std=c99 %s
+// RUN: %clang_cc1 -verify -std=c11 %s
+// RUN: %clang_cc1 -verify -std=c17 %s
+// RUN: %clang_cc1 -verify -std=c23 %s
+// expected-no-diagnostics
+
+/* WG14 N1310: Yes
+ * Requiring signed char to have no padding bits
+ */
+
+/* This is shockingly hard to test, but we're trying our best by checking that
+ * setting each bit of an unsigned char, then bit-casting it to signed char,
+ * results in a value we expect to see. If we have padding bits, then it's
+ * possible (but not mandatory) for the value to not be as we expect, so a
+ * failing assertion means the implementation is broken but a passing test does
+ * not *prove* there aren't padding bits.
+ */
+_Static_assert(__CHAR_BIT__ == 8, "");
+_Static_assert(sizeof(signed char) == 1, "");
+
+#define TEST(Bit, Expected) __builtin_bit_cast(signed char, (unsigned char)(1 << Bit)) == Expected
+_Static_assert(TEST(0, 1), "");
+_Static_assert(TEST(1, 2), "");
+_Static_assert(TEST(2, 4), "");
+_Static_assert(TEST(3, 8), "");
+_Static_assert(TEST(4, 16), "");
+_Static_assert(TEST(5, 32), "");
+_Static_assert(TEST(6, 64), "");
+_Static_assert(TEST(7, (signed char)128), "");
+

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 9e4600b3e66acb..b1f5ab4cbc4f07 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -411,7 +411,7 @@ <h2 id="c11">C11 implementation status</h2>
     <tr>
       <td>Requiring signed char to have no padding bits</td>
       <td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1310.htm">N1310</a></td>
-      <td class="unknown" align="center">Unknown</td>
+      <td class="full" align="center">Yes</td>
     </tr>
     <tr>
       <td>Initializing static or external variables</td>


        


More information about the cfe-commits mailing list