[clang] d7e06d5 - Update the status of some more C99 features
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 17 05:12:05 PDT 2022
Author: Aaron Ballman
Date: 2022-08-17T08:11:56-04:00
New Revision: d7e06d5675b62b5d3d89e6d6210c34b74a1a8356
URL: https://github.com/llvm/llvm-project/commit/d7e06d5675b62b5d3d89e6d6210c34b74a1a8356
DIFF: https://github.com/llvm/llvm-project/commit/d7e06d5675b62b5d3d89e6d6210c34b74a1a8356.diff
LOG: Update the status of some more C99 features
This also adds some test coverage to demonstrate we implement what was
standardized.
Added:
clang/test/C/C99/n617.c
clang/test/C/C99/n629.c
clang/test/C/C99/n636.c
clang/test/C/C99/n736.c
Modified:
clang/www/c_status.html
Removed:
################################################################################
diff --git a/clang/test/C/C99/n617.c b/clang/test/C/C99/n617.c
new file mode 100644
index 0000000000000..be263cc05f3e8
--- /dev/null
+++ b/clang/test/C/C99/n617.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -verify %s
+
+// expected-no-diagnostics
+
+/* WG14 N617: yes
+ * reliable integer division
+ */
+void test(void) {
+ _Static_assert(59 / 4 == 14, "we didn't truncate properly");
+ _Static_assert(59 / -4 == -14, "we didn't truncate properly");
+ _Static_assert(-59 / 4 == -14, "we didn't truncate properly");
+ _Static_assert(-59 / -4 == 14, "we didn't truncate properly");
+
+ // Might as well test % for the quotient.
+ _Static_assert(59 % 4 == 3, "we didn't truncate properly");
+ _Static_assert(59 % -4 == 3, "we didn't truncate properly");
+ _Static_assert(-59 % 4 == -3, "we didn't truncate properly");
+ _Static_assert(-59 % -4 == -3, "we didn't truncate properly");
+
+ // Test the idiom for rounding up.
+ _Static_assert((59 + (4 - 1)) / 4 == 15, "failed to 'round up' with the usual idiom");
+ _Static_assert((59 + (4 - 1)) % 4 == 2, "failed to 'round up' with the usual idiom");
+}
+
diff --git a/clang/test/C/C99/n629.c b/clang/test/C/C99/n629.c
new file mode 100644
index 0000000000000..01e32fb084fb6
--- /dev/null
+++ b/clang/test/C/C99/n629.c
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify %s
+// RUN: %clang_cc1 -triple i686-unknown-linux -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-win32 -verify %s
+// RUN: %clang_cc1 -triple i686-unknown-win32 -verify %s
+
+/* WG14 N629: yes
+ * integer constant type rules
+ */
+
+// expected-no-diagnostics
+
+void test_decimal_constants(void) {
+ // Easy cases where the value fits into the type you'd expect.
+ (void)_Generic(2, int : 1);
+ (void)_Generic(2u, unsigned int : 1);
+ (void)_Generic(2l, long : 1);
+ (void)_Generic(2ul, unsigned long : 1);
+ (void)_Generic(2ll, long long : 1);
+ (void)_Generic(2ull, unsigned long long : 1);
+
+#if __INT_WIDTH__ == 16
+ #if __LONG_WIDTH__ > 16
+ (void)_Generic(65536, long : 1);
+ (void)_Generic(65536U, unsigned long : 1);
+ #else
+ (void)_Generic(65536, long long : 1);
+ (void)_Generic(65536U, unsigned long : 1);
+ #endif // __LONG_WIDTH__ > 16
+#elif __INT_WIDTH__ == 32
+ #if __LONG_WIDTH__ > 32
+ (void)_Generic(4294967296, long : 1);
+ (void)_Generic(4294967296U, unsigned long : 1);
+ #else
+ (void)_Generic(4294967296, long long : 1);
+ (void)_Generic(4294967296U, unsigned long long : 1);
+ #endif // __LONG_WIDTH__ > 32
+#endif
+
+#if __LONG_WIDTH__ > 32
+ (void)_Generic(4294967296L, long : 1);
+ (void)_Generic(4294967296U, unsigned long : 1);
+#else
+ (void)_Generic(4294967296L, long long : 1);
+ (void)_Generic(4294967296U, unsigned long long : 1);
+#endif
+}
+
+void test_octal_constants(void) {
+ (void)_Generic(02, int : 1);
+ (void)_Generic(02u, unsigned int : 1);
+ (void)_Generic(02l, long : 1);
+ (void)_Generic(02ul, unsigned long : 1);
+ (void)_Generic(02ll, long long : 1);
+ (void)_Generic(02ull, unsigned long long : 1);
+
+#if __INT_WIDTH__ == 16
+ #if __LONG_WIDTH__ > 16
+ (void)_Generic(0200000, long : 1);
+ (void)_Generic(0200000U, unsigned long : 1);
+ #else
+ (void)_Generic(0200000, long long : 1);
+ (void)_Generic(0200000U, unsigned long : 1);
+ #endif // __LONG_WIDTH__ > 16
+#elif __INT_WIDTH__ == 32
+ #if __LONG_WIDTH__ > 32
+ (void)_Generic(040000000000, long : 1);
+ (void)_Generic(040000000000U, unsigned long : 1);
+ #else
+ (void)_Generic(040000000000, long long : 1);
+ (void)_Generic(040000000000U, unsigned long long : 1);
+ #endif // __LONG_WIDTH__ > 32
+#endif
+
+#if __LONG_WIDTH__ > 32
+ (void)_Generic(040000000000L, long : 1);
+ (void)_Generic(040000000000U, unsigned long : 1);
+#else
+ (void)_Generic(040000000000L, long long : 1);
+ (void)_Generic(040000000000U, unsigned long long : 1);
+#endif
+}
+
+void test_hexadecimal_constants(void) {
+ (void)_Generic(0x2, int : 1);
+ (void)_Generic(0x2u, unsigned int : 1);
+ (void)_Generic(0x2l, long : 1);
+ (void)_Generic(0x2ul, unsigned long : 1);
+ (void)_Generic(0x2ll, long long : 1);
+ (void)_Generic(0x2ull, unsigned long long : 1);
+
+#if __INT_WIDTH__ == 16
+ #if __LONG_WIDTH__ > 16
+ (void)_Generic(0x10000, long : 1);
+ (void)_Generic(0x10000U, unsigned long : 1);
+ #else
+ (void)_Generic(0x10000, long long : 1);
+ (void)_Generic(0x10000U, unsigned long : 1);
+ #endif // __LONG_WIDTH__ > 16
+#elif __INT_WIDTH__ == 32
+ #if __LONG_WIDTH__ > 32
+ (void)_Generic(0x100000000, long : 1);
+ (void)_Generic(0x100000000U, unsigned long : 1);
+ #else
+ (void)_Generic(0x100000000, long long : 1);
+ (void)_Generic(0x100000000U, unsigned long long : 1);
+ #endif // __LONG_WIDTH__ > 32
+#endif
+
+#if __LONG_WIDTH__ > 32
+ (void)_Generic(0x100000000L, long : 1);
+ (void)_Generic(0x100000000U, unsigned long : 1);
+#else
+ (void)_Generic(0x100000000L, long long : 1);
+ (void)_Generic(0x100000000U, unsigned long long : 1);
+#endif
+}
diff --git a/clang/test/C/C99/n636.c b/clang/test/C/C99/n636.c
new file mode 100644
index 0000000000000..fb69b2857dfac
--- /dev/null
+++ b/clang/test/C/C99/n636.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify=c2x -std=c2x %s
+
+/* WG14 N636: yes
+ * remove implicit function declaration
+ */
+
+void test(void) {
+ frobble(); // expected-error {{call to undeclared function 'frobble'; ISO C99 and later do not support implicit function declarations}} \
+ c2x-error {{undeclared identifier 'frobble'}}
+}
+
diff --git a/clang/test/C/C99/n736.c b/clang/test/C/C99/n736.c
new file mode 100644
index 0000000000000..df912d21ca27e
--- /dev/null
+++ b/clang/test/C/C99/n736.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -verify %s
+
+/* WG14 N736: yes
+ * preprocessor arithmetic done in intmax_t/uintmax_t
+ */
+
+// There is not a standard requirement that this relationships holds. If these
+// asserts fail, it means we have another test scenario to consider.
+_Static_assert(__INTMAX_MAX__ == __LONG_LONG_MAX__,
+ "intmax_t is not the same width as long long?");
+_Static_assert((-__INTMAX_MAX__ - 1) == (-__LONG_LONG_MAX__ - 1LL),
+ "intmax_t is not the same width as long long?");
+_Static_assert(__UINTMAX_MAX__ == (__LONG_LONG_MAX__ * 2ULL + 1ULL),
+ "uintmax_t is not the same width as unsigned long long?");
+
+// Test that arithmetic on the largest positive signed intmax_t works.
+#if 9223372036854775807LL + 0LL != 9223372036854775807LL
+#error "uh oh"
+#endif
+
+// Same for negative.
+#if -9223372036854775807LL - 1LL + 0LL != -9223372036854775807LL - 1LL
+#error "uh oh"
+#endif
+
+// Then test the same for unsigned
+#if 18446744073709551615ULL + 0ULL != 18446744073709551615ULL
+#error "uh oh"
+#endif
+
+// Test that unsigned overflow causes silent wraparound.
+#if 18446744073709551615ULL + 1ULL != 0 // Silently wraps to 0.
+#error "uh oh"
+#endif
+
+#if 0ULL - 1ULL != 18446744073709551615ULL // Silently wraps to 0xFFFF'FFFF'FFFF'FFFF.
+#error "uh oh"
+#endif
+
+// Now test that signed arithmetic that pushes us over a limit is properly
+// diagnosed.
+#if 9223372036854775807LL + 1LL // expected-warning {{integer overflow in preprocessor expression}}
+#endif
+
+#if -9223372036854775807LL - 2LL // expected-warning {{integer overflow in preprocessor expression}}
+#endif
+
diff --git a/clang/www/c_status.html b/clang/www/c_status.html
index 50509476c5181..8d4dbe2612749 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -198,7 +198,7 @@ <h2 id="c99">C99 implementation status</h2>
<tr>
<td>reliable integer division</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n617.htm">N617</a></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr>
<td>universal character names (\u and \U)</td>
@@ -245,12 +245,12 @@ <h2 id="c99">C99 implementation status</h2>
<tr>
<td>remove implicit function declaration</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n636.htm">N636</a></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr>
<td>preprocessor arithmetic done in intmax_t/uintmax_t</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n736.htm">N736</a></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr>
<td>mixed declarations and code</td>
@@ -265,7 +265,7 @@ <h2 id="c99">C99 implementation status</h2>
<tr>
<td>integer constant type rules</td>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n629.htm">N629</a></td>
- <td class="unknown" align="center">Unknown</td>
+ <td class="full" align="center">Yes</td>
</tr>
<tr>
<td>integer promotion rules</td>
More information about the cfe-commits
mailing list