aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathaniel Shead <nathanieloshead@gmail.com>2024-08-22 21:04:11 +1000
committerNathaniel Shead <nathanieloshead@gmail.com>2024-08-27 11:03:14 +1000
commit98608342932e8951a4c8db3e9df79f9187424d53 (patch)
treeb80e661d6dd60592fbd56957cd5d9350215684b0
parent9522fc8bb7812f2ad50eb038e0938bfd958e730f (diff)
downloadgcc-98608342932e8951a4c8db3e9df79f9187424d53.zip
gcc-98608342932e8951a4c8db3e9df79f9187424d53.tar.gz
gcc-98608342932e8951a4c8db3e9df79f9187424d53.tar.bz2
c++/modules: Clean up include translation [PR110980]
Currently the handling of include translation is confusing to read, using a tri-state integer without much clarity on what different states mean. This patch cleans this up to use explicit enumerators indicating the different possible states instead, and fixes a bug where the option '-flang-info-include-translate' ended being accidentally unusable. PR c++/110980 gcc/cp/ChangeLog: * module.cc (maybe_translate_include): Clean up. gcc/testsuite/ChangeLog: * g++.dg/modules/inc-xlate-2_a.H: New test. * g++.dg/modules/inc-xlate-2_b.H: New test. * g++.dg/modules/inc-xlate-3.h: New test. * g++.dg/modules/inc-xlate-3_a.H: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
-rw-r--r--gcc/cp/module.cc23
-rw-r--r--gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H3
-rw-r--r--gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H5
-rw-r--r--gcc/testsuite/g++.dg/modules/inc-xlate-3.h2
-rw-r--r--gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H5
5 files changed, 29 insertions, 9 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 07477d3..4cd7e1c 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -20118,15 +20118,19 @@ maybe_translate_include (cpp_reader *reader, line_maps *lmaps, location_t loc,
size_t len = strlen (path);
path = canonicalize_header_name (NULL, loc, true, path, len);
auto packet = mapper->IncludeTranslate (path, Cody::Flags::None, len);
- int xlate = false;
+
+ enum class xlate_kind {
+ unknown, text, import,
+ } translate = xlate_kind::unknown;
+
if (packet.GetCode () == Cody::Client::PC_BOOL)
- xlate = -int (packet.GetInteger ());
+ translate = packet.GetInteger () ? xlate_kind::text : xlate_kind::unknown;
else if (packet.GetCode () == Cody::Client::PC_PATHNAME)
{
/* Record the CMI name for when we do the import. */
module_state *import = get_module (build_string (len, path));
import->set_filename (packet);
- xlate = +1;
+ translate = xlate_kind::import;
}
else
{
@@ -20136,9 +20140,9 @@ maybe_translate_include (cpp_reader *reader, line_maps *lmaps, location_t loc,
}
bool note = false;
- if (note_include_translate_yes && xlate > 1)
+ if (note_include_translate_yes && translate == xlate_kind::import)
note = true;
- else if (note_include_translate_no && xlate == 0)
+ else if (note_include_translate_no && translate == xlate_kind::unknown)
note = true;
else if (note_includes)
/* We do not expect the note_includes vector to be large, so O(N)
@@ -20148,15 +20152,16 @@ maybe_translate_include (cpp_reader *reader, line_maps *lmaps, location_t loc,
note = true;
if (note)
- inform (loc, xlate
+ inform (loc, translate == xlate_kind::import
? G_("include %qs translated to import")
- : G_("include %qs processed textually") , path);
+ : G_("include %qs processed textually"), path);
- dump () && dump (xlate ? "Translating include to import"
+ dump () && dump (translate == xlate_kind::import
+ ? "Translating include to import"
: "Keeping include as include");
dump.pop (0);
- if (!(xlate > 0))
+ if (translate != xlate_kind::import)
return nullptr;
/* Create the translation text. */
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H b/gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H
new file mode 100644
index 0000000..d6a4866
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H
@@ -0,0 +1,3 @@
+// PR c++/110980
+// { dg-additional-options "-fmodule-header" }
+// { dg-module-cmi {} }
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H b/gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H
new file mode 100644
index 0000000..f04dd43
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H
@@ -0,0 +1,5 @@
+// PR c++/110980
+// { dg-additional-options "-fmodule-header -flang-info-include-translate" }
+// { dg-module-cmi {} }
+
+#include "inc-xlate-2_a.H" // { dg-message "translated to import" }
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-3.h b/gcc/testsuite/g++.dg/modules/inc-xlate-3.h
new file mode 100644
index 0000000..c0584ba
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-3.h
@@ -0,0 +1,2 @@
+// PR c++/110980
+// Just an empty file to be an include target.
diff --git a/gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H b/gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H
new file mode 100644
index 0000000..4777208
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H
@@ -0,0 +1,5 @@
+// PR c++/110980
+// { dg-additional-options "-fmodule-header -flang-info-include-translate-not" }
+// { dg-module-cmi {} }
+
+#include "inc-xlate-3.h" // { dg-message "processed textually" }