aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/module.cc
diff options
context:
space:
mode:
authorNathaniel Shead <nathanieloshead@gmail.com>2024-08-18 21:35:23 +1000
committerNathaniel Shead <nathanieloshead@gmail.com>2024-08-21 09:45:54 +1000
commite668771ff0dcc3c72937768e5c37b6f287b97799 (patch)
treeda8c89c05c73bc929cb1426cd7493ebe72843178 /gcc/cp/module.cc
parentc7b76a076cb2c6ded7ae208464019b04cb0531a2 (diff)
downloadgcc-e668771ff0dcc3c72937768e5c37b6f287b97799.zip
gcc-e668771ff0dcc3c72937768e5c37b6f287b97799.tar.gz
gcc-e668771ff0dcc3c72937768e5c37b6f287b97799.tar.bz2
c++/modules: Remove unnecessary errors when not writing compiled module
It was pointed out to me that the current error referencing an internal linkage entity reads almost like an ICE message, with the message finishing with the unhelpful: m.cpp:1:8: error: failed to write compiled module: Bad file data 1 | export module M; | ^~~~~~ Similarly, whenever we decide not to emit a module CMI due to other errors we currently emit the following message: m.cpp:1:8: warning: not writing module ‘M’ due to errors 1 | export module M; | ^~~~~~ Neither of these messages really add anything useful; users already understand that when an error is reported then the normal outputs will not be created, so these messages are just noise. There is one case we still need this latter message, however; when an error in a template has been silenced with '-Wno-template-body' we still don't want to write a module CMI, so emit an error now instead. This patch also removes a number of dg-prune-output directives in the testsuite that are no longer needed with this change. gcc/cp/ChangeLog: * module.cc (module_state::write_begin): Return a boolean to indicate errors rather than just doing set_error(). (finish_module_processing): Prevent emission of unnecessary errors; only indicate module writing occurred if write_begin succeeds. gcc/testsuite/ChangeLog: * g++.dg/modules/export-1.C: Remove message. * g++.dg/modules/internal-1.C: Remove message. * g++.dg/modules/ambig-2_b.C: Remove unnecessary pruning. * g++.dg/modules/atom-decl-2.C: Likewise. * g++.dg/modules/atom-pragma-3.C: Likewise. * g++.dg/modules/atom-preamble-2_f.C: Likewise. * g++.dg/modules/block-decl-2.C: Likewise. * g++.dg/modules/dir-only-4.C: Likewise. * g++.dg/modules/enum-12.C: Likewise. * g++.dg/modules/exp-xlate-1_b.C: Likewise. * g++.dg/modules/export-3.C: Likewise. * g++.dg/modules/friend-3.C: Likewise. * g++.dg/modules/friend-5_b.C: Likewise. * g++.dg/modules/inc-xlate-1_e.C: Likewise. * g++.dg/modules/linkage-2.C: Likewise. * g++.dg/modules/local-extern-1.C: Likewise. * g++.dg/modules/main-1.C: Likewise. * g++.dg/modules/map-2.C: Likewise. * g++.dg/modules/mod-decl-1.C: Likewise. * g++.dg/modules/mod-decl-3.C: Likewise. * g++.dg/modules/pr99174.H: Likewise. * g++.dg/modules/pr99468.H: Likewise. * g++.dg/modules/token-1.C: Likewise. * g++.dg/modules/token-3.C: Likewise. * g++.dg/modules/token-4.C: Likewise. * g++.dg/modules/token-5.C: Likewise. * g++.dg/modules/using-10.C: Likewise. * g++.dg/modules/using-12.C: Likewise. * g++.dg/modules/using-3.C: Likewise. * g++.dg/modules/using-9.C: Likewise. * g++.dg/modules/using-enum-2.C: Likewise. * g++.dg/modules/permissive-error-1.C: New test. * g++.dg/modules/permissive-error-2.C: New test. Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com> Reviewed-by: Jason Merrill <jason@redhat.com>
Diffstat (limited to 'gcc/cp/module.cc')
-rw-r--r--gcc/cp/module.cc42
1 files changed, 25 insertions, 17 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 7c42aea..07477d3 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -3681,7 +3681,7 @@ class GTY((chain_next ("%h.parent"), for_user)) module_state {
public:
/* Read and write module. */
- void write_begin (elf_out *to, cpp_reader *,
+ bool write_begin (elf_out *to, cpp_reader *,
module_state_config &, unsigned &crc);
void write_end (elf_out *to, cpp_reader *,
module_state_config &, unsigned &crc);
@@ -18317,7 +18317,7 @@ ool_cmp (const void *a_, const void *b_)
MOD_SNAME_PFX.cfg : config data
*/
-void
+bool
module_state::write_begin (elf_out *to, cpp_reader *reader,
module_state_config &config, unsigned &crc)
{
@@ -18395,10 +18395,7 @@ module_state::write_begin (elf_out *to, cpp_reader *reader,
table.find_dependencies (this);
if (!table.finalize_dependencies ())
- {
- to->set_error ();
- return;
- }
+ return false;
#if CHECKING_P
/* We're done verifying at-most once reading, reset to verify
@@ -18595,6 +18592,8 @@ module_state::write_begin (elf_out *to, cpp_reader *reader,
// so-controlled.
if (false)
write_env (to);
+
+ return true;
}
// Finish module writing after we've emitted all dynamic initializers.
@@ -20847,20 +20846,29 @@ finish_module_processing (cpp_reader *reader)
cookie = new module_processing_cookie (cmi_name, tmp_name, fd, e);
- if (errorcount
- /* Don't write the module if it contains an erroneous template. */
- || (erroneous_templates
- && !erroneous_templates->is_empty ()))
- warning_at (state->loc, 0, "not writing module %qs due to errors",
- state->get_flatname ());
+ if (errorcount)
+ /* Don't write the module if we have reported errors. */;
+ else if (erroneous_templates
+ && !erroneous_templates->is_empty ())
+ {
+ /* Don't write the module if it contains an erroneous template.
+ Also emit notes about where errors occurred in case
+ -Wno-template-body was passed. */
+ auto_diagnostic_group d;
+ error_at (state->loc, "not writing module %qs due to errors "
+ "in template bodies", state->get_flatname ());
+ if (!warn_template_body)
+ inform (state->loc, "enable %<-Wtemplate-body%> for more details");
+ for (auto e : *erroneous_templates)
+ inform (e.second, "first error in %qD appeared here", e.first);
+ }
else if (cookie->out.begin ())
{
- cookie->began = true;
- auto loc = input_location;
/* So crashes finger-point the module decl. */
- input_location = state->loc;
- state->write_begin (&cookie->out, reader, cookie->config, cookie->crc);
- input_location = loc;
+ iloc_sentinel ils = state->loc;
+ if (state->write_begin (&cookie->out, reader, cookie->config,
+ cookie->crc))
+ cookie->began = true;
}
dump.pop (n);