From: Tom Honermann <tom@honermann.net>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 2/3 v3] testsuite: Add tests for C2X N2653 char8_t and UTF-8 string literal changes
Date: Mon, 1 Aug 2022 18:39:45 -0400 [thread overview]
Message-ID: <20220801223945.1433166-1-tom@honermann.net> (raw)
In-Reply-To: <20220725175948.1424695-3-tom@honermann.net>
This change provides new tests for the core language and compiler
dependent library changes adopted for C2X via WG14 N2653.
gcc/testsuite/ChangeLog:
* gcc.dg/atomic/c2x-stdatomic-lockfree-char8_t.c: New test.
* gcc.dg/atomic/gnu2x-stdatomic-lockfree-char8_t.c: New test.
* gcc.dg/c2x-predefined-macros.c: New test.
* gcc.dg/c2x-utf8str-type.c: New test.
* gcc.dg/c2x-utf8str.c: New test.
* gcc.dg/gnu2x-predefined-macros.c: New test.
* gcc.dg/gnu2x-utf8str-type.c: New test.
* gcc.dg/gnu2x-utf8str.c: New test.
---
.../atomic/c2x-stdatomic-lockfree-char8_t.c | 42 +++++++++++++++++++
.../atomic/gnu2x-stdatomic-lockfree-char8_t.c | 5 +++
gcc/testsuite/gcc.dg/c11-utf8str-type.c | 6 +++
gcc/testsuite/gcc.dg/c17-utf8str-type.c | 6 +++
gcc/testsuite/gcc.dg/c2x-utf8str-type.c | 6 +++
gcc/testsuite/gcc.dg/c2x-utf8str.c | 34 +++++++++++++++
.../gcc.dg/gnu2x-predefined-macros.c | 5 +++
gcc/testsuite/gcc.dg/gnu2x-utf8str-type.c | 5 +++
gcc/testsuite/gcc.dg/gnu2x-utf8str.c | 34 +++++++++++++++
9 files changed, 143 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-lockfree-char8_t.c
create mode 100644 gcc/testsuite/gcc.dg/atomic/gnu2x-stdatomic-lockfree-char8_t.c
create mode 100644 gcc/testsuite/gcc.dg/c11-utf8str-type.c
create mode 100644 gcc/testsuite/gcc.dg/c17-utf8str-type.c
create mode 100644 gcc/testsuite/gcc.dg/c2x-utf8str-type.c
create mode 100644 gcc/testsuite/gcc.dg/c2x-utf8str.c
create mode 100644 gcc/testsuite/gcc.dg/gnu2x-predefined-macros.c
create mode 100644 gcc/testsuite/gcc.dg/gnu2x-utf8str-type.c
create mode 100644 gcc/testsuite/gcc.dg/gnu2x-utf8str.c
diff --git a/gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-lockfree-char8_t.c b/gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-lockfree-char8_t.c
new file mode 100644
index 00000000000..1b692f55ed0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/atomic/c2x-stdatomic-lockfree-char8_t.c
@@ -0,0 +1,42 @@
+/* Test atomic_is_lock_free for char8_t. */
+/* { dg-do run } */
+/* { dg-options "-std=c2x -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/atomic/gnu2x-stdatomic-lockfree-char8_t.c b/gcc/testsuite/gcc.dg/atomic/gnu2x-stdatomic-lockfree-char8_t.c
new file mode 100644
index 00000000000..27a3cfe3552
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/atomic/gnu2x-stdatomic-lockfree-char8_t.c
@@ -0,0 +1,5 @@
+/* Test atomic_is_lock_free for char8_t with -std=gnu2x. */
+/* { dg-do run } */
+/* { dg-options "-std=gnu2x -pedantic-errors" } */
+
+#include "c2x-stdatomic-lockfree-char8_t.c"
diff --git a/gcc/testsuite/gcc.dg/c11-utf8str-type.c b/gcc/testsuite/gcc.dg/c11-utf8str-type.c
new file mode 100644
index 00000000000..8be9abb9686
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c11-utf8str-type.c
@@ -0,0 +1,6 @@
+/* Test C11 UTF-8 string literal type. */
+/* { dg-do compile } */
+/* { dg-options "-std=c11" } */
+
+_Static_assert (_Generic (u8"text", char*: 1, default: 2) == 1, "UTF-8 string literals have an unexpected type");
+_Static_assert (_Generic (u8"x"[0], char: 1, default: 2) == 1, "UTF-8 string literal elements have an unexpected type");
diff --git a/gcc/testsuite/gcc.dg/c17-utf8str-type.c b/gcc/testsuite/gcc.dg/c17-utf8str-type.c
new file mode 100644
index 00000000000..515c6db3970
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c17-utf8str-type.c
@@ -0,0 +1,6 @@
+/* Test C17 UTF-8 string literal type. */
+/* { dg-do compile } */
+/* { dg-options "-std=c17" } */
+
+_Static_assert (_Generic (u8"text", char*: 1, default: 2) == 1, "UTF-8 string literals have an unexpected type");
+_Static_assert (_Generic (u8"x"[0], char: 1, default: 2) == 1, "UTF-8 string literal elements have an unexpected type");
diff --git a/gcc/testsuite/gcc.dg/c2x-utf8str-type.c b/gcc/testsuite/gcc.dg/c2x-utf8str-type.c
new file mode 100644
index 00000000000..ebdde97b57a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-utf8str-type.c
@@ -0,0 +1,6 @@
+/* Test C2X UTF-8 string literal type. */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x" } */
+
+_Static_assert (_Generic (u8"text", unsigned char*: 1, default: 2) == 1, "UTF-8 string literals have an unexpected type");
+_Static_assert (_Generic (u8"x"[0], unsigned char: 1, default: 2) == 1, "UTF-8 string literal elements have an unexpected type");
diff --git a/gcc/testsuite/gcc.dg/c2x-utf8str.c b/gcc/testsuite/gcc.dg/c2x-utf8str.c
new file mode 100644
index 00000000000..2e4c392da9f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c2x-utf8str.c
@@ -0,0 +1,34 @@
+/* Test initialization by UTF-8 string literal in C2X. */
+/* { dg-do compile } */
+/* { dg-require-effective-target wchar } */
+/* { dg-options "-std=c2x" } */
+
+typedef __CHAR8_TYPE__ char8_t;
+typedef __CHAR16_TYPE__ char16_t;
+typedef __CHAR32_TYPE__ char32_t;
+typedef __WCHAR_TYPE__ wchar_t;
+
+/* Test that char, signed char, unsigned char, and char8_t arrays can be
+ initialized by a UTF-8 string literal. */
+const char cbuf1[] = u8"text";
+const char cbuf2[] = { u8"text" };
+const signed char scbuf1[] = u8"text";
+const signed char scbuf2[] = { u8"text" };
+const unsigned char ucbuf1[] = u8"text";
+const unsigned char ucbuf2[] = { u8"text" };
+const char8_t c8buf1[] = u8"text";
+const char8_t c8buf2[] = { u8"text" };
+
+/* Test that a diagnostic is issued for attempted initialization of
+ other character types by a UTF-8 string literal. */
+const char16_t c16buf1[] = u8"text"; /* { dg-error "from a string literal with type array of .unsigned char." } */
+const char16_t c16buf2[] = { u8"text" }; /* { dg-error "from a string literal with type array of .unsigned char." } */
+const char32_t c32buf1[] = u8"text"; /* { dg-error "from a string literal with type array of .unsigned char." } */
+const char32_t c32buf2[] = { u8"text" }; /* { dg-error "from a string literal with type array of .unsigned char." } */
+const wchar_t wbuf1[] = u8"text"; /* { dg-error "from a string literal with type array of .unsigned char." } */
+const wchar_t wbuf2[] = { u8"text" }; /* { dg-error "from a string literal with type array of .unsigned char." } */
+
+/* Test that char8_t arrays can be initialized by an ordinary string
+ literal. */
+const char8_t c8buf3[] = "text";
+const char8_t c8buf4[] = { "text" };
diff --git a/gcc/testsuite/gcc.dg/gnu2x-predefined-macros.c b/gcc/testsuite/gcc.dg/gnu2x-predefined-macros.c
new file mode 100644
index 00000000000..f1906cdf73c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gnu2x-predefined-macros.c
@@ -0,0 +1,5 @@
+/* Test C2X predefined macros with -std=gnu2x. */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu2x" } */
+
+#include "c2x-predefined-macros.c"
diff --git a/gcc/testsuite/gcc.dg/gnu2x-utf8str-type.c b/gcc/testsuite/gcc.dg/gnu2x-utf8str-type.c
new file mode 100644
index 00000000000..efe16ffc28d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gnu2x-utf8str-type.c
@@ -0,0 +1,5 @@
+/* Test C2X UTF-8 string literal type with -std=gnu2x. */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu2x" } */
+
+#include "c2x-utf8str-type.c"
diff --git a/gcc/testsuite/gcc.dg/gnu2x-utf8str.c b/gcc/testsuite/gcc.dg/gnu2x-utf8str.c
new file mode 100644
index 00000000000..f3719ea8c77
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gnu2x-utf8str.c
@@ -0,0 +1,34 @@
+/* Test initialization by UTF-8 string literal in C2X with -std=gnu2x. */
+/* { dg-do compile } */
+/* { dg-require-effective-target wchar } */
+/* { dg-options "-std=gnu2x" } */
+
+typedef __CHAR8_TYPE__ char8_t;
+typedef __CHAR16_TYPE__ char16_t;
+typedef __CHAR32_TYPE__ char32_t;
+typedef __WCHAR_TYPE__ wchar_t;
+
+/* Test that char, signed char, unsigned char, and char8_t arrays can be
+ initialized by a UTF-8 string literal. */
+const char cbuf1[] = u8"text";
+const char cbuf2[] = { u8"text" };
+const signed char scbuf1[] = u8"text";
+const signed char scbuf2[] = { u8"text" };
+const unsigned char ucbuf1[] = u8"text";
+const unsigned char ucbuf2[] = { u8"text" };
+const char8_t c8buf1[] = u8"text";
+const char8_t c8buf2[] = { u8"text" };
+
+/* Test that a diagnostic is issued for attempted initialization of
+ other character types by a UTF-8 string literal. */
+const char16_t c16buf1[] = u8"text"; /* { dg-error "from a string literal with type array of .unsigned char." } */
+const char16_t c16buf2[] = { u8"text" }; /* { dg-error "from a string literal with type array of .unsigned char." } */
+const char32_t c32buf1[] = u8"text"; /* { dg-error "from a string literal with type array of .unsigned char." } */
+const char32_t c32buf2[] = { u8"text" }; /* { dg-error "from a string literal with type array of .unsigned char." } */
+const wchar_t wbuf1[] = u8"text"; /* { dg-error "from a string literal with type array of .unsigned char." } */
+const wchar_t wbuf2[] = { u8"text" }; /* { dg-error "from a string literal with type array of .unsigned char." } */
+
+/* Test that char8_t arrays can be initialized by an ordinary string
+ literal. */
+const char8_t c8buf3[] = "text";
+const char8_t c8buf4[] = { "text" };
--
2.32.0
next prev parent reply other threads:[~2022-08-01 22:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-25 17:59 [PATCH 0/3] Implement C2X N2653 (char8_t) and correct UTF-8 character literal type in preprocessor directives for C++ Tom Honermann
2022-07-25 17:59 ` [PATCH 1/3] C: Implement C2X N2653 char8_t and UTF-8 string literal changes Tom Honermann
2022-07-27 23:20 ` Joseph Myers
2022-07-30 23:17 ` Tom Honermann
2022-08-01 18:32 ` [PATCH 1/3 v2] " Tom Honermann
2022-07-25 17:59 ` [PATCH 2/3] testsuite: Add tests for " Tom Honermann
2022-07-27 23:23 ` Joseph Myers
2022-07-31 21:47 ` Tom Honermann
2022-08-01 18:34 ` [PATCH 2/3 v2] " Tom Honermann
2022-08-01 19:13 ` Joseph Myers
2022-08-01 22:36 ` Tom Honermann
2022-08-01 22:39 ` Tom Honermann [this message]
2022-08-02 16:53 ` [PATCH 2/3 v3] " Joseph Myers
2022-08-02 18:02 ` Tom Honermann
2022-07-25 17:59 ` [PATCH 3/3] c++/106426: Treat u8 character literals as unsigned in char8_t modes Tom Honermann
2022-07-25 18:05 ` Andrew Pinski
2022-07-26 1:32 ` [PATCH 3/3 v2] preprocessor/106426: " Tom Honermann
2022-07-26 1:38 ` [PATCH 3/3] c++/106426: " Tom Honermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220801223945.1433166-1-tom@honermann.net \
--to=tom@honermann.net \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).