From patchwork Fri Jan 26 11:28:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1891273 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=bAtEuELM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4TLwS74q3sz23dy for ; Fri, 26 Jan 2024 22:28:38 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 668283858C74 for ; Fri, 26 Jan 2024 11:28:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 94A7D3858C74 for ; Fri, 26 Jan 2024 11:28:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94A7D3858C74 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 94A7D3858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706268496; cv=none; b=J4agyh5zlyNLvlxyUD5y9a4+O+QWPouQXF7ueQNPInhNPGWpUZEXL7QrKVr4sv+ubndiA1tGZwbQZdrESFlN9NHo+dLCQjhkCEW2UecdT6WNwmqakZcdUjPRGSSWJLr0guSHRW1JwXxihPgub/CDP8oE/4v6VFW1Xp1g847qtGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706268496; c=relaxed/simple; bh=7s0nGBlOsigpynMUWKFgmYQgu5wAASTwgwQgWAaFgvI=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=VKfwMNEtoeARwqKeun25ju+mccZZYGfAFvk5F/PMKD7G++0lglI5XIqGSIc5m/wBPdLLMhQ7tZrw/8ekK1FFvzr91qiaEzosL9T6zZ9pVVQSxyhloC5NhD3Pnjk6QjNiLjnulhOTTwdsagAf9MnraY7miyXyfwf21pICvCQvl0I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d51ba18e1bso3696965ad.0 for ; Fri, 26 Jan 2024 03:28:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706268490; x=1706873290; 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=M5xSfn9tIFvJX93XrqKf3/36RLQ2gswVxHQRaT3Jc5Q=; b=bAtEuELM3iaHkEDrdUzlVKTk6QcAAHDYbm0kJVXSqlZrtoLD0wrv55+t+cDa9cuDav CPU0Fz2Dj9BwSNKzQqgV1ias+0KXvbWBv/M82oS+XfPdrk2HFa1YY70Dw0aS9+q1UnoF +PSnemEJ2s+fs0EompX4uhpDTNgIsbnz/yTMCl0zy+KDWM0mPJ9RgqLL0e7SlzUKx57e GhFN07ji078jVvWBwRYZceK1pM3/6KQTm3crJgdcG5pdzL9Atq3CK5WljaYJZFDMRR6L TtE+rhWa9hgaIVG0R2WnETrIzEoXjag/pZluTegdH1NSfi4fzlPIYMFfAGBzUYaHLA7L 43gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706268490; x=1706873290; 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=M5xSfn9tIFvJX93XrqKf3/36RLQ2gswVxHQRaT3Jc5Q=; b=FabcLxq1fdUoju3KG4yRLWbccqeduRATiie1/GI+Rs4s8BaMsUWCgvIskphgXZnj3C ku/K85NZy9JTD165IAcZPymwIGmQfAxxiVvLTaUr6VPG8fGxEMtVwVwYydvZA1eB754w jHVqmHx/4PSJFiIhEmWkWhLh9IIjD9a+XYXmbMmcCdIV9UC5aGqxYnKS4TZkgpCQZvcx LLmTNpgdL2N05giUsvE44Su0xuNoatUq+qGoC87Lu0uVzPwAPwtU1NVuMZQ7M4fgdkmk VjFEeAmRQ2UUb9zfaYbmoJcwuzTZnFg+oTTjlWLWY3XZ2nSzeWw2wsMWXnsxQALMCm4A a8qA== X-Gm-Message-State: AOJu0YxVJ9f/BJBysBa4bQPyDGccYd1PA1W0EuPAOifRgOAx7Elwhpxj rOR/smIYPtU2eAi+qzyLw2NF9bYOoZJGIdwJplVU9N1paeN2JScY8+fBplUB X-Google-Smtp-Source: AGHT+IGloiorNGs23WpaMNm1fqYP8D+xgFKSv4czdThgGWIVUuPIQ8S4Kan1tFCpT11JShyxGxO2Tw== X-Received: by 2002:a17:903:22c1:b0:1d7:856e:b4 with SMTP id y1-20020a17090322c100b001d7856e00b4mr1379467plg.52.1706268490405; Fri, 26 Jan 2024 03:28:10 -0800 (PST) Received: from Thaum. (123-243-206-49.tpgi.com.au. [123.243.206.49]) by smtp.gmail.com with ESMTPSA id l4-20020a170903004400b001d6ee702822sm796768pla.297.2024.01.26.03.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 03:28:10 -0800 (PST) Message-ID: <65b3974a.170a0220.2893c.1f1f@mx.google.com> X-Google-Original-Message-ID: Date: Fri, 26 Jan 2024 22:28:05 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: Stream additional fields for DECL_STRUCT_FUNCTION [PR113580] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.0 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, URIBL_BLACK 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 This patch just adds enough of the fields from 'function' to fix the ICE in the linked PR. I suppose there might be more fields from this type that should be propagated, but I don't know enough to find out which they might be yet, since a lot of them seem to be only set after gimplification. Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- Currently the DECL_STRUCT_FUNCTION for a declaration is always reconstructed from scratch. This causes issues though, as some fields used by other parts of the compiler (in this case, specifically 'function_{start,end}_locus') are then not correctly initialised. This patch makes sure that these fields are also read and written. PR c++/113580 gcc/cp/ChangeLog: * module.cc (struct post_process_data): Create. (trees_in::post_decls): Use. (trees_in::post_process): Return entire vector at once. Change overload to take post_process_data instead of tree. (trees_out::write_function_def): Write needed flags from DECL_STRUCT_FUNCTION. (trees_in::read_function_def): Read them and pass to post_process. (module_state::read_cluster): Write flags into cfun. gcc/testsuite/ChangeLog: * g++.dg/modules/pr113580_a.C: New test. * g++.dg/modules/pr113580_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 47 ++++++++++++++++++----- gcc/testsuite/g++.dg/modules/pr113580_a.C | 10 +++++ gcc/testsuite/g++.dg/modules/pr113580_b.C | 10 +++++ 3 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr113580_a.C create mode 100644 gcc/testsuite/g++.dg/modules/pr113580_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 6176801b7a7..840c7ef6dab 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -2837,6 +2837,13 @@ typedef hash_map,uintptr_t> > duplicate_hash_map; +/* Data needed for post-processing. */ +struct post_process_data { + tree decl; + location_t start_locus; + location_t end_locus; +}; + /* Tree stream reader. Note that reading a stream doesn't mark the read trees with TREE_VISITED. Thus it's quite safe to have multiple concurrent readers. Which is good, because lazy @@ -2848,7 +2855,7 @@ private: module_state *state; /* Module being imported. */ vec back_refs; /* Back references. */ duplicate_hash_map *duplicates; /* Map from existings to duplicate. */ - vec post_decls; /* Decls to post process. */ + vec post_decls; /* Decls to post process. */ unsigned unused; /* Inhibit any interior TREE_USED marking. */ @@ -2945,16 +2952,16 @@ public: tree odr_duplicate (tree decl, bool has_defn); public: - /* Return the next decl to postprocess, or NULL. */ - tree post_process () + /* Return the decls to postprocess. */ + const vec& post_process () { - return post_decls.length () ? post_decls.pop () : NULL_TREE; + return post_decls; } private: - /* Register DECL for postprocessing. */ - void post_process (tree decl) + /* Register DATA for postprocessing. */ + void post_process (post_process_data data) { - post_decls.safe_push (decl); + post_decls.safe_push (data); } private: @@ -11667,15 +11674,25 @@ trees_out::write_function_def (tree decl) tree_node (cexpr->body); } + function* f = DECL_STRUCT_FUNCTION (decl); + if (streaming_p ()) { unsigned flags = 0; + if (f) + flags |= 2; if (DECL_NOT_REALLY_EXTERN (decl)) flags |= 1; u (flags); } + + if (state && f) + { + state->write_location (*this, f->function_start_locus); + state->write_location (*this, f->function_end_locus); + } } void @@ -11692,6 +11709,8 @@ trees_in::read_function_def (tree decl, tree maybe_template) tree saved = tree_node (); tree context = tree_node (); constexpr_fundef cexpr; + post_process_data pdata {}; + pdata.decl = maybe_template; tree maybe_dup = odr_duplicate (maybe_template, DECL_SAVED_TREE (decl)); bool installing = maybe_dup && !DECL_SAVED_TREE (decl); @@ -11708,6 +11727,12 @@ trees_in::read_function_def (tree decl, tree maybe_template) unsigned flags = u (); + if (flags & 2) + { + pdata.start_locus = state->read_location (*this); + pdata.end_locus = state->read_location (*this); + } + if (get_overrun ()) return NULL_TREE; @@ -11722,7 +11747,7 @@ trees_in::read_function_def (tree decl, tree maybe_template) SET_DECL_FRIEND_CONTEXT (decl, context); if (cexpr.decl) register_constexpr_fundef (cexpr); - post_process (maybe_template); + post_process (pdata); } else if (maybe_dup) { @@ -15100,8 +15125,10 @@ module_state::read_cluster (unsigned snum) push_function_context does too much work. */ tree old_cfd = current_function_decl; struct function *old_cfun = cfun; - while (tree decl = sec.post_process ()) + for (const post_process_data& pdata : sec.post_process ()) { + tree decl = pdata.decl; + bool abstract = false; if (TREE_CODE (decl) == TEMPLATE_DECL) { @@ -15113,6 +15140,8 @@ module_state::read_cluster (unsigned snum) allocate_struct_function (decl, abstract); cfun->language = ggc_cleared_alloc (); cfun->language->base.x_stmt_tree.stmts_are_full_exprs_p = 1; + cfun->function_start_locus = pdata.start_locus; + cfun->function_end_locus = pdata.end_locus; if (abstract) ; diff --git a/gcc/testsuite/g++.dg/modules/pr113580_a.C b/gcc/testsuite/g++.dg/modules/pr113580_a.C new file mode 100644 index 00000000000..954333f5038 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr113580_a.C @@ -0,0 +1,10 @@ +// PR c++/113580 +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi A } + +export module A; + +export { + template + void fun(T x) {} +} diff --git a/gcc/testsuite/g++.dg/modules/pr113580_b.C b/gcc/testsuite/g++.dg/modules/pr113580_b.C new file mode 100644 index 00000000000..a72cd750c72 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr113580_b.C @@ -0,0 +1,10 @@ +// PR c++/113580 +// { dg-additional-options "-fmodules-ts -Wunused-parameter" } + +import A; + +int main() { + fun(42); // { dg-message "required from here" } +} + +// { dg-warning "unused parameter" "" { target *-*-* } 0 }