From patchwork Tue Dec 8 20:37:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1412989 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=P/4Bd7FT; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CrBnp6STZz9sW8 for ; Wed, 9 Dec 2020 07:37:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56BDD385041F; Tue, 8 Dec 2020 20:37:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by sourceware.org (Postfix) with ESMTPS id D1DB43854805 for ; Tue, 8 Dec 2020 20:37:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D1DB43854805 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qt1-x82b.google.com with SMTP id f14so4408552qto.12 for ; Tue, 08 Dec 2020 12:37:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=q2zcn096oy+FRXr/6QPsLjxzvxHqaVnraBTCCf3R1gg=; b=P/4Bd7FTut7huZPpl2AOCrumebKV0lOv+wpB8wC7R7dScrdxpaMCer8ap0VFZmVbai iz1H5wBf33qbQraPVb1sMPCDNcJGZonv2HkpC4ZsUXKo7gWY4C4jhVyJKRZk8hZsLQWn 0XVii6rI0xC2DNfWeIuMuksorsmD9ICXd7De9W9UxH03x/MuWL2W66L2/WzWgFbQivs6 01OS6uR6E+IIwe7HSZAfuz0cqDEIG95gs6PHpQMrdnsL++DRL7l2RvFOVtKIF2L01K6C ErIaSKbIi1IesqkYTd94fQWfz8kckXuNBzpYxZwNSV9cwmlA3jevzuZmDMkMVRHbUpEX MPRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=q2zcn096oy+FRXr/6QPsLjxzvxHqaVnraBTCCf3R1gg=; b=k0vEEsqusDKkUAHoJq37SE7PN9pcPXbl+XYsDxZk2Agy7ZxC/vzewh5PaQJnQK7373 aHoIDTD4kTZPrPWX8yBQEzzCFm7WcCEXPJH6nSUkNEDzpXuIB/vMPnoZZN8Y89stTbJy a84LzsPo79AFJ503LTxZKj+NHJZnl0XYxh4tOYe6Bg30f/LkjxZuOcWcSm4Z+fmp+Q3i x/F80DNk4ppVbiMy6UGpr9Sx6UBlR6VuLVDaRI9aPW6PpxqNHNsEHX9LiJHyopZGDF6u sQkj5CixsBvxFinwROFpFKdAIUs1mcXwe2Se/TOscEPc890RC6+urxfK5M9B97jK41/m Xf9g== X-Gm-Message-State: AOAM531OBC+keJLpPodo3NlpMTfyl9KpvPkSH1bD+8kX5UfOiVVsZ3PN FTU4D1C3iJlXvK8mj+U9cvs= X-Google-Smtp-Source: ABdhPJwqvsRSqcsOCW92mDnE0J8nIQVv1spw4VJ/O+FJoIme7g/u/1FFEh7g4778V1V2voo7XeMTyg== X-Received: by 2002:ac8:7b33:: with SMTP id l19mr13533921qtu.251.1607459862111; Tue, 08 Dec 2020 12:37:42 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:f56f:caec:7790:ed9f? ([2620:10d:c091:480::1:5154]) by smtp.googlemail.com with ESMTPSA id a28sm4213537qtm.80.2020.12.08.12.37.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 12:37:40 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: Originating and instantiating module Message-ID: <7d17ecc0-b179-63db-e8a5-1b650f0cc098@acm.org> Date: Tue, 8 Dec 2020 15:37:39 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" With modules streamed entities have two new properties -- the module that declares them and the module that instantiates them. Here 'instantiate' applies to more than just templates -- for instance an implicit member fn. These may well be the same module. This adds the calls to places that need it. gcc/cp/ * class.c (layout_class_type): Call set_instantiating_module. (build_self_reference): Likewise. * decl.c (grokfndecl): Call set_originating_module. (grokvardecl): Likewise. (grokdeclarator): Likewise. * pt.c (maybe_new_partial_specialization): Call set_instantiating_module, propagate DECL_MODULE_EXPORT_P. (lookup_template_class_1): Likewise. (tsubst_function_decl): Likewise. (tsubst_decl, instantiate_template_1): Likewise. (build_template_decl): Propagate module flags. (tsubst_template_dcl): Likewise. (finish_concept_definition): Call set_originating_module. * module.c (set_instantiating_module, set_originating_module): Stubs. diff --git i/gcc/cp/class.c w/gcc/cp/class.c index 2ab123d6ccf..bc0d3d6bf86 100644 --- i/gcc/cp/class.c +++ w/gcc/cp/class.c @@ -6759,6 +6759,8 @@ layout_class_type (tree t, tree *virtuals_p) TYPE_CONTEXT (base_t) = t; DECL_CONTEXT (base_d) = t; + set_instantiating_module (base_d); + /* If the ABI version is not at least two, and the last field was a bit-field, RLI may not be on a byte boundary. In particular, rli_size_unit_so_far might @@ -8738,6 +8740,7 @@ build_self_reference (void) DECL_ARTIFICIAL (decl) = 1; SET_DECL_SELF_REFERENCE_P (decl); set_underlying_type (decl); + set_instantiating_module (decl); if (processing_template_decl) decl = push_template_decl (decl); diff --git i/gcc/cp/decl.c w/gcc/cp/decl.c index 7da8c65e984..bb5bb2f1a18 100644 --- i/gcc/cp/decl.c +++ w/gcc/cp/decl.c @@ -9878,6 +9878,8 @@ grokfndecl (tree ctype, && !processing_template_decl) deduce_noexcept_on_destructor (decl); + set_originating_module (decl); + decl = check_explicit_specialization (orig_declarator, decl, template_count, 2 * funcdef_flag + @@ -10122,6 +10124,8 @@ grokvardecl (tree type, TREE_PUBLIC (decl) = DECL_EXTERNAL (decl); } + set_originating_module (decl); + if (decl_spec_seq_has_spec_p (declspecs, ds_thread)) { if (DECL_EXTERNAL (decl) || TREE_STATIC (decl)) @@ -12965,6 +12969,8 @@ grokdeclarator (const cp_declarator *declarator, revert this subsequently if it determines that the clones should share a common implementation. */ DECL_ABSTRACT_P (decl) = true; + + set_originating_module (decl); } else if (current_class_type && constructor_name_p (unqualified_id, current_class_type)) @@ -13499,6 +13505,8 @@ grokdeclarator (const cp_declarator *declarator, ; /* We already issued a permerror. */ else if (decl && DECL_NAME (decl)) { + set_originating_module (decl, true); + if (initialized) /* Kludge: We need funcdef_flag to be true in do_friend for in-class defaulted functions, but that breaks grokfndecl. diff --git i/gcc/cp/module.cc w/gcc/cp/module.cc index 705804a5515..948ca2a6cab 100644 --- i/gcc/cp/module.cc +++ w/gcc/cp/module.cc @@ -99,6 +99,16 @@ get_originating_module (tree, bool) return 0; } +void +set_instantiating_module (tree) +{ +} + +void +set_originating_module (tree, bool) +{ +} + module_state * preprocess_module (module_state *, unsigned, bool, bool, bool, cpp_reader *) { diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c index 56d7b560229..6b8e486a642 100644 --- i/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -960,6 +960,9 @@ maybe_new_partial_specialization (tree type) TREE_PRIVATE (d) = (current_access_specifier == access_private_node); TREE_PROTECTED (d) = (current_access_specifier == access_protected_node); + set_instantiating_module (d); + DECL_MODULE_EXPORT_P (d) = DECL_MODULE_EXPORT_P (tmpl); + return t; } @@ -4922,6 +4925,17 @@ build_template_decl (tree decl, tree parms, bool member_template_p) DECL_SOURCE_LOCATION (tmpl) = DECL_SOURCE_LOCATION (decl); DECL_MEMBER_TEMPLATE_P (tmpl) = member_template_p; + if (modules_p ()) + { + /* Propagate module information from the decl. */ + DECL_MODULE_EXPORT_P (tmpl) = DECL_MODULE_EXPORT_P (decl); + if (DECL_LANG_SPECIFIC (decl)) + { + DECL_MODULE_PURVIEW_P (tmpl) = DECL_MODULE_PURVIEW_P (decl); + gcc_checking_assert (!DECL_MODULE_IMPORT_P (decl)); + } + } + return tmpl; } @@ -9994,6 +10008,12 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context, = DECL_SOURCE_LOCATION (TYPE_STUB_DECL (template_type)); } + set_instantiating_module (type_decl); + /* Although GEN_TMPL is the TEMPLATE_DECL, it has the same value + of export flag. We want to propagate this because it might + be a friend declaration that pushes a new hidden binding. */ + DECL_MODULE_EXPORT_P (type_decl) = DECL_MODULE_EXPORT_P (gen_tmpl); + if (CLASS_TYPE_P (template_type)) { TREE_PRIVATE (type_decl) @@ -13912,6 +13932,7 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain, if (!DECL_DELETED_FN (r)) DECL_INITIAL (r) = NULL_TREE; DECL_CONTEXT (r) = ctx; + set_instantiating_module (r); /* Handle explicit(dependent-expr). */ if (DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (t)) @@ -14235,6 +14256,24 @@ tsubst_template_decl (tree t, tree args, tsubst_flags_t complain, TREE_TYPE (r) = TREE_TYPE (inner); DECL_CONTEXT (r) = DECL_CONTEXT (inner); + if (modules_p ()) + { + /* Propagate module information from the decl. */ + DECL_MODULE_EXPORT_P (r) = DECL_MODULE_EXPORT_P (inner); + if (DECL_LANG_SPECIFIC (inner)) + { + DECL_MODULE_PURVIEW_P (r) = DECL_MODULE_PURVIEW_P (inner); + /* If this is a constrained template, the above tsubst of + inner can find the unconstrained template, which may have + come from an import. This is ok, because we don't + register this instantiation (see below). */ + gcc_checking_assert (!DECL_MODULE_IMPORT_P (inner) + || (TEMPLATE_PARMS_CONSTRAINTS + (DECL_TEMPLATE_PARMS (t)))); + DECL_MODULE_IMPORT_P (r) = false; + } + } + DECL_TEMPLATE_INSTANTIATIONS (r) = NULL_TREE; DECL_TEMPLATE_SPECIALIZATIONS (r) = NULL_TREE; @@ -14789,6 +14828,8 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) SET_DECL_ASSEMBLER_NAME (r, NULL_TREE); if (CODE_CONTAINS_STRUCT (TREE_CODE (t), TS_DECL_WRTL)) SET_DECL_RTL (r, NULL); + set_instantiating_module (r); + /* The initializer must not be expanded until it is required; see [temp.inst]. */ DECL_INITIAL (r) = NULL_TREE; @@ -20951,6 +20992,8 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain) DECL_TI_TEMPLATE (fndecl) = tmpl; DECL_TI_ARGS (fndecl) = targ_ptr; + set_instantiating_module (fndecl); + /* Now we know the specialization, compute access previously deferred. Do no access control for inheriting constructors, as we already checked access for the inherited constructor. */ @@ -28037,6 +28080,8 @@ finish_concept_definition (cp_expr id, tree init) DECL_CONTEXT (decl) = current_scope (); DECL_INITIAL (decl) = init; + set_originating_module (decl, false); + /* Push the enclosing template. */ return push_template_decl (decl); }