From patchwork Sun Aug 18 12:11:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1973564 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=fysDpWXw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wmvjw175dz1yXf for ; Sun, 18 Aug 2024 22:12:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6CC133861828 for ; Sun, 18 Aug 2024 12:12:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 159E8385840C for ; Sun, 18 Aug 2024 12:11:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 159E8385840C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 159E8385840C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723983116; cv=none; b=M4uLvcO2qV+OQtvj/j1FZhn4jKXyrtE8mOmef06tg9lEcrdCzKJ9R8/LO2lvhwhmR5q3jC+jYb8H0DHWqb/zRwBqLJWJ7nFFotsUJxPWFj+kuWmYgqITKcopcwBDguaf+BMphFVBfUdU/UlD+AcScPYt269r2O1jMh86ReUIlro= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723983116; c=relaxed/simple; bh=eFiYS0jLRVgm9q4yI8lsjBaTEOM8TetG5qnu9uL1Wbc=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=XiZeWA9Ek5cpVJZBpLB1/xgdb9usZVxY1a02EfxVghp8d6f6h+3WUCq4svfhlLZFec/9Gz8FR/Rg8F2/2gC3GheiQ9sU848HH1J03QrBULh0z9N1QS4dwMMfQbSe6fbQVQl2jbho8YIwIb6VsV2Xt/OFMY9tdY2UlkQKBZvrjk0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-70d199fb3dfso2888110b3a.3 for ; Sun, 18 Aug 2024 05:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723983113; x=1724587913; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=eo0A4I5j5Tu6tEIrgkEK0D2Uxi1jK36eXQPZc19LYwM=; b=fysDpWXwNS0zn+t+ahBxG7HTUNLQtgA0imUdablni8XbHS9LN1jHumEzTInwVEJSoi Mz30siSMSvE152Ic7iZviwYrgu2rGNqcAn9LtI8OImVxMU0gNflClb7hPC9q8n5cRGaK 07uEYl61RJUYtowtS3833TVlcfTb8TRR+11EOVfxt945Dh3+znEO0/sen/ZvvnxaxEI6 6le0WoBnsEV9nT2N+0SyJ7CUlS5Ia0KN5ItsIbifJ2v6pZtHpE0O5T070vgdYDqUGBLm OI253JYZA3z6DYZAnma8mMi9Ysh3wKT+XDl5DaNu7cS0FfpmyzbvQao+Ltt3GBynX9bT C4Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723983113; x=1724587913; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eo0A4I5j5Tu6tEIrgkEK0D2Uxi1jK36eXQPZc19LYwM=; b=DdIdZ30ASJD66vanDco5Xe292nlZ2j1mxkEUc0bV3FLnhS4mvQJ+M8E1aMN9QaM//2 mX1PY7ryQh34ElGd2GmfAwz1I0afWAZvkfNE4LXTq8i2sSaTH1ClTdaXvpc7OfvjuVSX qf6gMu2Ar34stYvNXq/ltBmpfFoPQbceDtfQwsZZcnpBkx+RQltjIcgUZfQhTxIFWHV0 fODeh76iHko8v9Mdb4MtV3CZNGAVhy3/LGDRnLk7it78P1x4zObC9sTYP21B2QDLz3yM UNf/u+PkxmFLCpsEhi3AqKkufJBPxiIiY2NlmWyglmRQk5IoixW4rYQKFr6lZCBW2eQc eH3Q== X-Gm-Message-State: AOJu0Yw4YLRBSZI6XOmHRSXt/8ygaH1syW6YiQhwNe8Uy62Im970s9sf fh2fIK8ZzPrguoCO+JSkMJtJCJbOwaYix8mEeRkSRJzUOGvb4ldqzYOS8A== X-Google-Smtp-Source: AGHT+IHGpcACoSefZvTdgis50qL+EpFWREm/csH5Dy39+OTZxw8fU4775djz6C2LRRm+d0MscKqrPg== X-Received: by 2002:a05:6a00:cc9:b0:70d:2e24:af66 with SMTP id d2e1a72fcca58-713c4f37ecemr10974429b3a.20.1723983112710; Sun, 18 Aug 2024 05:11:52 -0700 (PDT) Received: from Thaum. (110-175-236-231.static.tpgi.com.au. [110.175.236.231]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7127ae0f224sm5155724b3a.79.2024.08.18.05.11.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Aug 2024 05:11:52 -0700 (PDT) Message-ID: <66c1e508.050a0220.31958c.0679@mx.google.com> X-Google-Original-Message-ID: Date: Sun, 18 Aug 2024 22:11:46 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: Slightly clean up error for referencing TU-local entity MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? Or should we even just remove the warning entirely? I'm not sure it really adds all that much, since it's usual AFAICT for errors to prevent the intended outputs from being generated. -- >8 -- 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; | ^~~~~~ It would probably be clearer to just emit the same warning that we do in other cases where we don't write modules due to errors. gcc/cp/ChangeLog: * module.cc (module_state::write_begin): Return a boolean to indicate errors rather than just doing to->set_error(). (finish_module_processing): Check for failed write_begin and disable module writing in that case. gcc/testsuite/ChangeLog: * g++.dg/modules/block-decl-2.C: Adjust error message. * g++.dg/modules/internal-1.C: Likewise. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 30 ++++++++++++--------- gcc/testsuite/g++.dg/modules/block-decl-2.C | 2 +- gcc/testsuite/g++.dg/modules/internal-1.C | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index f4d137b13a1..9f23feece09 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,22 +20846,27 @@ finish_module_processing (cpp_reader *reader) cookie = new module_processing_cookie (cmi_name, tmp_name, fd, e); + bool report_error = false; 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 ()); + report_error = true; 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; + else + report_error = true; } + if (report_error) + warning_at (state->loc, 0, "not writing module %qs due to errors", + state->get_flatname ()); + dump.pop (n); timevar_stop (TV_MODULE_EXPORT); diff --git a/gcc/testsuite/g++.dg/modules/block-decl-2.C b/gcc/testsuite/g++.dg/modules/block-decl-2.C index 974e26f9b7a..90f18b30945 100644 --- a/gcc/testsuite/g++.dg/modules/block-decl-2.C +++ b/gcc/testsuite/g++.dg/modules/block-decl-2.C @@ -18,4 +18,4 @@ export extern "C++" auto foo() { return X{}; } -// { dg-prune-output "failed to write compiled module" } +// { dg-prune-output "not writing module" } diff --git a/gcc/testsuite/g++.dg/modules/internal-1.C b/gcc/testsuite/g++.dg/modules/internal-1.C index 45d3bf06f28..399dd68b92e 100644 --- a/gcc/testsuite/g++.dg/modules/internal-1.C +++ b/gcc/testsuite/g++.dg/modules/internal-1.C @@ -1,6 +1,6 @@ // { dg-additional-options "-fmodules-ts" } -export module frob; // { dg-error "failed to write" } +export module frob; // { dg-warning "not writing module" } // { dg-module-cmi !frob } namespace {