]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libcody: allow non-ASCII module names [PR120458]
authorJean-Christian CÎRSTEA <jean.christian.cirstea@gmail.com>
Sun, 22 Mar 2026 17:57:42 +0000 (19:57 +0200)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Thu, 28 May 2026 23:24:11 +0000 (16:24 -0700)
Before this commit, attempting to use non-ASCII characters in quoted
words failed, even though the protocol allows the usage of such
characters in quoted words. To fix this:

1. Remove `c >= 0x7f` comparison when parsing a quoted word.
2. Use `unsigned char` instead of `char` such that `c < 0x20` fails for
   non-ASCII characters.

PR c++/120458

libcody/ChangeLog:

* buffer.cc (S2C): Allow non-ASCII chars in quoted words.
* cody.hh: Use unsigned char for S2C().

gcc/testsuite/ChangeLog:

* g++.dg/README: Explain purpose of modules/ dir.
* g++.dg/modules/pr120458-1_a.C: Define non-ASCII module with
default mapper.
* g++.dg/modules/pr120458-1_b.C: Import non-ASCII module with
default mapper.
* g++.dg/modules/pr120458-2_a.C: Define non-ASCII module with
a file as mapper.
* g++.dg/modules/pr120458-2_b.C: Import non-ASCII module with
a file as mapper.
* g++.dg/modules/pr120458-2.map: Define mapping for pr120458-2
test case.

Signed-off-by: Jean-Christian CÎRSTEA <jean-christian.cirstea@tuta.com>
gcc/testsuite/g++.dg/README
gcc/testsuite/g++.dg/modules/pr120458-1_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr120458-1_b.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr120458-2.map [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr120458-2_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/pr120458-2_b.C [new file with mode: 0644]
libcody/buffer.cc
libcody/cody.hh

index a7b3d5b783b7a36c8ec1fd9e0f0cd900ec79f238..3301f17b4dfa34d694eb9f40c20e5dab2a77e799 100644 (file)
@@ -15,6 +15,7 @@ inherit        Tests for inheritance -- virtual functions, multiple inheritance, etc.
 init    Tests for initialization semantics, constructors/destructors, etc.
 lookup  Tests for lookup semantics, namespaces, using, etc.
 lto     Tests for Link Time Optimization.
+modules  Tests for C++20 modules.
 opt     Tests for fixes of bugs with particular optimizations.
 overload Tests for overload resolution and conversions.
 parse   Tests for parsing.
diff --git a/gcc/testsuite/g++.dg/modules/pr120458-1_a.C b/gcc/testsuite/g++.dg/modules/pr120458-1_a.C
new file mode 100644 (file)
index 0000000..89d0bb5
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-module-do link }
+// { dg-additional-options "-fmodules -finput-charset=UTF-8" }
+
+export module 영혼;
+// { dg-module-cmi }
+
+export unsigned f(unsigned x) {
+       return x + 3;
+}
diff --git a/gcc/testsuite/g++.dg/modules/pr120458-1_b.C b/gcc/testsuite/g++.dg/modules/pr120458-1_b.C
new file mode 100644 (file)
index 0000000..4b1023d
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-module-do link }
+// { dg-additional-options "-fmodules -finput-charset=UTF-8" }
+
+#include <iostream>
+
+import 영혼;
+
+int main(void) {
+       std::cout << f(13) << '\n';
+       return 0;
+}
diff --git a/gcc/testsuite/g++.dg/modules/pr120458-2.map b/gcc/testsuite/g++.dg/modules/pr120458-2.map
new file mode 100644 (file)
index 0000000..86955e4
--- /dev/null
@@ -0,0 +1,2 @@
+$root .
+灵魂 pr120458_a.gcm
diff --git a/gcc/testsuite/g++.dg/modules/pr120458-2_a.C b/gcc/testsuite/g++.dg/modules/pr120458-2_a.C
new file mode 100644 (file)
index 0000000..940f6e7
--- /dev/null
@@ -0,0 +1,11 @@
+// { dg-module-do link }
+// { dg-additional-options "-fmodules -fmodule-mapper=[srcdir]/pr120458-2.map " }
+// { dg-additional-options "-finput-charset=UTF-8 " }
+// { dg-additional-files "pr120458-2.map" }
+
+export module 灵魂;
+// { dg-module-cmi }
+
+export unsigned f(unsigned x) {
+       return x + 3;
+}
diff --git a/gcc/testsuite/g++.dg/modules/pr120458-2_b.C b/gcc/testsuite/g++.dg/modules/pr120458-2_b.C
new file mode 100644 (file)
index 0000000..dc4f665
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-module-do link }
+// { dg-additional-options "-fmodules -fmodule-mapper=[srcdir]/pr120458-2.map " }
+// { dg-additional-options "-finput-charset=UTF-8" }
+
+import 灵魂;
+
+#include <iostream>
+
+int main(void) {
+       std::cout << f(13) << '\n';
+       return 0;
+}
index 85c066fef715d54c3dd52ecb989c7605bb0f4a8d..d27882b7d4aa65591f273a71af17178493d0d60c 100644 (file)
@@ -30,7 +30,7 @@
 namespace Cody {
 namespace Detail {
 
-static const char CONTINUE = S2C(u8";");
+static const unsigned char CONTINUE = S2C(u8";");
 
 void MessageBuffer::BeginLine ()
 {
@@ -239,7 +239,7 @@ int MessageBuffer::Lex (std::vector<std::string> &result)
 
   for (std::string *word = nullptr;;)
     {
-      char c = *iter;
+      unsigned char c = *iter;
 
       ++iter;
       if (c == S2C(u8" ") || c == S2C(u8"\t"))
@@ -292,7 +292,7 @@ int MessageBuffer::Lex (std::vector<std::string> &result)
                  return EINVAL;
                }
 
-             if (c < S2C(u8" ") || c >= 0x7f)
+             if (c < S2C(u8" "))
                goto malformed;
 
              ++iter;
index 93bce93aa94db9fcc0ad97523607ba1f08171b35..7c852eb3aa1c54340f0b37c9e27e7a30482126ad 100644 (file)
@@ -49,14 +49,14 @@ namespace Detail  {
 
 #if __cpp_char8_t >= 201811
 template<unsigned I>
-constexpr char S2C (char8_t const (&s)[I])
+constexpr unsigned char S2C (char8_t const (&s)[I])
 {
   static_assert (I == 2, "only single octet strings may be converted");
   return s[0];
 }
 #else
 template<unsigned I>
-constexpr char S2C (char const (&s)[I])
+constexpr unsigned char S2C (char const (&s)[I])
 {
   static_assert (I == 2, "only single octet strings may be converted");
   return s[0];