Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 --
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): Replace xlate with enum, fix note_include_translate_yes. 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 <nathanielosh...@gmail.com> --- gcc/cp/module.cc | 23 ++++++++++++-------- gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H | 3 +++ gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H | 5 +++++ gcc/testsuite/g++.dg/modules/inc-xlate-3.h | 2 ++ gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H | 5 +++++ 5 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/inc-xlate-2_a.H create mode 100644 gcc/testsuite/g++.dg/modules/inc-xlate-2_b.H create mode 100644 gcc/testsuite/g++.dg/modules/inc-xlate-3.h create mode 100644 gcc/testsuite/g++.dg/modules/inc-xlate-3_a.H diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 07477d33955..4cd7e1c284b 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 00000000000..d6a4866a676 --- /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 00000000000..f04dd430fec --- /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 00000000000..c0584bada0c --- /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 00000000000..47772089149 --- /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" } -- 2.43.2