diff mbox series

[2/3] : C N2653 char8_t: New tests​

Message ID b2bb0168-23eb-dbd6-8822-e7791eb77918@honermann.net
State New
Headers show
Series : C N2653 char8_t implementation | expand

Commit Message

Tom Honermann June 7, 2021, 2:32 a.m. UTC
This patch provides new tests for the core language and compiler 
dependent library changes proposed in WG14 N2653 [1] for C.

Most of the tests are provided in both a positive (-fchar8_t) and 
negative (-fno-char8_t) form to ensure behaviors are appropriately 
present or absent in each mode.

Tested on Linux x86_64.

gcc/testsuite/ChangeLog:

2021-05-31  Tom Honermann  <tom@honermann.net>

         * gcc.dg/atomic/stdatomic-lockfree-char8_t.c: New test.
         * gcc.dg/char8_t-init-string-literal-1.c: New test.
         * gcc.dg/char8_t-predefined-macros-1.c: New test.
         * gcc.dg/char8_t-predefined-macros-2.c: New test.
         * gcc.dg/char8_t-string-literal-1.c: New test.
         * gcc.dg/char8_t-string-literal-2.c: New test.

Tom.

[1]: WG14 N2653
      "char8_t: A type for UTF-8 characters and strings (Revision 1)"
      http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2653.htm
diff mbox series

Patch

commit 900aa3507defd80339828e5791c215a28efd9fea
Author: Tom Honermann <tom@honermann.net>
Date:   Sat Feb 13 10:02:41 2021 -0500

    N2653 char8_t for C: New tests
    
    This change provides new tests for the core language and compiler
    dependent library changes proposed in WG14 N2653 for C.
    
    Some of the tests are provided in both a positive (-fchar8_t) and
    negative (-fno-char8_t) form to ensure behaviors are appropriately
    present or absent in each mode.

diff --git a/gcc/testsuite/gcc.dg/atomic/stdatomic-lockfree-char8_t.c b/gcc/testsuite/gcc.dg/atomic/stdatomic-lockfree-char8_t.c
new file mode 100644
index 00000000000..bb9eae84e83
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/atomic/stdatomic-lockfree-char8_t.c
@@ -0,0 +1,42 @@ 
+/* Test atomic_is_lock_free for char8_t.  */
+/* { dg-do run } */
+/* { dg-options "-std=c11 -fchar8_t -pedantic-errors" } */
+
+#include <stdatomic.h>
+#include <stdint.h>
+
+extern void abort (void);
+
+_Atomic __CHAR8_TYPE__ ac8a;
+atomic_char8_t ac8t;
+
+#define CHECK_TYPE(MACRO, V1, V2)		\
+  do						\
+    {						\
+      int r1 = MACRO;				\
+      int r2 = atomic_is_lock_free (&V1);	\
+      int r3 = atomic_is_lock_free (&V2);	\
+      if (r1 != 0 && r1 != 1 && r1 != 2)	\
+	abort ();				\
+      if (r2 != 0 && r2 != 1)			\
+	abort ();				\
+      if (r3 != 0 && r3 != 1)			\
+	abort ();				\
+      if (r1 == 2 && r2 != 1)			\
+	abort ();				\
+      if (r1 == 2 && r3 != 1)			\
+	abort ();				\
+      if (r1 == 0 && r2 != 0)			\
+	abort ();				\
+      if (r1 == 0 && r3 != 0)			\
+	abort ();				\
+    }						\
+  while (0)
+
+int
+main ()
+{
+  CHECK_TYPE (ATOMIC_CHAR8_T_LOCK_FREE, ac8a, ac8t);
+
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/char8_t-init-string-literal-1.c b/gcc/testsuite/gcc.dg/char8_t-init-string-literal-1.c
new file mode 100644
index 00000000000..4d587e90a26
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/char8_t-init-string-literal-1.c
@@ -0,0 +1,13 @@ 
+/* Test that char, signed char, and unsigned char arrays can still be
+   initialized by UTF-8 string literals if -fchar8_t is enabled.  */
+/* { dg-do compile } */
+/* { dg-options "-fchar8_t" } */
+
+char cbuf1[] = u8"text";
+char cbuf2[] = { u8"text" };
+
+signed char scbuf1[] = u8"text";
+signed char scbuf2[] = { u8"text" };
+
+unsigned char ucbuf1[] = u8"text";
+unsigned char ucbuf2[] = { u8"text" };
diff --git a/gcc/testsuite/gcc.dg/char8_t-predefined-macros-1.c b/gcc/testsuite/gcc.dg/char8_t-predefined-macros-1.c
new file mode 100644
index 00000000000..884c634990d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/char8_t-predefined-macros-1.c
@@ -0,0 +1,16 @@ 
+// Test that char8_t related predefined macros are not present when -fchar8_t is
+// not enabled.
+// { dg-do compile }
+// { dg-options "-fno-char8_t" }
+
+#if defined(_CHAR8_T_SOURCE)
+# error _CHAR8_T_SOURCE is defined!
+#endif
+
+#if defined(__CHAR8_TYPE__)
+# error __CHAR8_TYPE__ is defined!
+#endif
+
+#if defined(__GCC_ATOMIC_CHAR8_T_LOCK_FREE)
+# error __GCC_ATOMIC_CHAR8_T_LOCK_FREE is defined!
+#endif
diff --git a/gcc/testsuite/gcc.dg/char8_t-predefined-macros-2.c b/gcc/testsuite/gcc.dg/char8_t-predefined-macros-2.c
new file mode 100644
index 00000000000..7f425357f57
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/char8_t-predefined-macros-2.c
@@ -0,0 +1,16 @@ 
+// Test that char8_t related predefined macros are present when -fchar8_t is
+// enabled.
+// { dg-do compile }
+// { dg-options "-fchar8_t" }
+
+#if !defined(_CHAR8_T_SOURCE)
+# error _CHAR8_T_SOURCE is not defined!
+#endif
+
+#if !defined(__CHAR8_TYPE__)
+# error __CHAR8_TYPE__ is not defined!
+#endif
+
+#if !defined(__GCC_ATOMIC_CHAR8_T_LOCK_FREE)
+# error __GCC_ATOMIC_CHAR8_T_LOCK_FREE is not defined!
+#endif
diff --git a/gcc/testsuite/gcc.dg/char8_t-string-literal-1.c b/gcc/testsuite/gcc.dg/char8_t-string-literal-1.c
new file mode 100644
index 00000000000..df94582ac1d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/char8_t-string-literal-1.c
@@ -0,0 +1,6 @@ 
+// Test that UTF-8 string literals have type char[] if -fchar8_t is not enabled.
+// { dg-do compile }
+// { dg-options "-std=c11 -fno-char8_t" }
+
+_Static_assert (_Generic (u8"text", char*: 1, unsigned char*: 2) == 1, "UTF-8 string literals have an unexpected type");
+_Static_assert (_Generic (u8"x"[0], char:  1, unsigned char:  2) == 1, "UTF-8 string literal elements have an unexpected type");
diff --git a/gcc/testsuite/gcc.dg/char8_t-string-literal-2.c b/gcc/testsuite/gcc.dg/char8_t-string-literal-2.c
new file mode 100644
index 00000000000..e7fd21f1067
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/char8_t-string-literal-2.c
@@ -0,0 +1,6 @@ 
+// Test that UTF-8 string literals have type unsigned char[] if -fchar8_t is enabled.
+// { dg-do compile }
+// { dg-options "-std=c11 -fchar8_t" }
+
+_Static_assert (_Generic (u8"text", char*: 1, unsigned char*: 2) == 2, "UTF-8 string literals have an unexpected type");
+_Static_assert (_Generic (u8"x"[0], char:  1, unsigned char:  2) == 2, "UTF-8 string literal elements have an unexpected type");