From patchwork Wed Jan 5 12:16:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 49583 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5C8B53858010 for ; Wed, 5 Jan 2022 12:25:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by sourceware.org (Postfix) with ESMTPS id DB1FC3858437 for ; Wed, 5 Jan 2022 12:16:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DB1FC3858437 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qt1-x836.google.com with SMTP id y17so1265397qtx.9 for ; Wed, 05 Jan 2022 04:16:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:message-id:date:mime-version:user-agent:content-language:to :cc:from:subject; bh=B65tOlzqBbI43mwdP4Rj7V7Os0OW77HOTOsl7/xQ/D0=; b=AkXM7AfnLO418KfwAhadUyFJC/1K5lyjVLbr7Wkm9wv6BHKzZqVH710v96G5zHEiju qbBIzCfFoK9nWWb2vkWOw5jiZB5of9hQgC7dFPLyL3XwRlLY0Vtdo9SeMJT+8SeYatKU 1F+Nuw7CN5lI15eTjemR1LobIDgMWGjZGjnKRrjYaK7dw2/PXteBhf4/R1BEhb0VKuIj lEZngEt+8avXCuUcYPS46zCyCkiW0iPsUcxtKYYnMnJjLoZ3gf9dttyv72TyF5rMeHTf jVH5pZqg1/YxmOfpp40Fz7ODyEgnWu7APDVdCCQlX/8zScmGA7JFfV6V5S7/eDufTMlG iacw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:message-id:date:mime-version:user-agent :content-language:to:cc:from:subject; bh=B65tOlzqBbI43mwdP4Rj7V7Os0OW77HOTOsl7/xQ/D0=; b=PvNTHc4aeC7P3+ASTfgo/n4u//WnfSnRlGmKFOW/ZzgoPfxGAJC2B2rc1T+2QX+5MZ FrD/zBP6mGbugxBAQhH4jSB8bzQ9j+DkCMLKOBE/oHMBsrG9hj0rPaH8lNb9N9tzu/ha i2LWlueCkLrxnwIIE9s64mzfVwq0P3f6lgOOQPLlb/ZhWx7hE6/5CCDpSkQ3gCVadPlm W8s02JZmblXruR865BkZC8dR7OIXUh8Aeku4Cd3TMjz6heGIde79kWpSyS9qcyTb2s9+ pVZWkuVXGYwYiX3KL94pFfgAq4cmbb0Lw5F4DnY5ZyclQFG6g9mhDcVwzxTdJ5hrkhhK d59w== X-Gm-Message-State: AOAM530fyFi8RIVWxxl+e4DkRDCL7UOFiT2EOmbvTmSfKFq9083vkc0j L6E5QwWn8ZBGcVT+k/df57f7uOJcreI= X-Google-Smtp-Source: ABdhPJxYOFRIwCvGm483IHfcbmgvkDn0925Dstt7Gfj+szMHrtMggujOtTLWyEsLaqnHoNzjeSnnTg== X-Received: by 2002:ac8:7fcc:: with SMTP id b12mr48402264qtk.164.1641384975266; Wed, 05 Jan 2022 04:16:15 -0800 (PST) Received: from ?IPV6:2620:10d:c0a3:1407:af0f:3e7c:6fed:6550? ([2620:10d:c091:500::2:74eb]) by smtp.googlemail.com with ESMTPSA id u6sm34197360qki.129.2022.01.05.04.16.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 05 Jan 2022 04:16:14 -0800 (PST) Message-ID: <10058f5d-f80e-fb6f-ee6c-30a4ee343c98@acm.org> Date: Wed, 5 Jan 2022 07:16:13 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Content-Language: en-US To: GCC Patches From: Nathan Sidwell Subject: Fix PR97966 regression X-Spam-Status: No, score=-3039.0 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Cc: Marek Polacek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Marek's fix for PR97966 caused a regression with (non-template) member functions of template classes. We need to mark them used in the instantiated class's scope, rather than the scope we were in before instantiating, as the latter may itself be in template and change the behaviour of marking a function as used. pushed to trunk nathan From 10195da73618ab818b66d4d2fade1be46ea39962 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 4 Jan 2022 13:36:44 -0800 Subject: [PATCH 3/3] Adjust mark used member in instantiated class scope The fix for PR97966 caused a regression with (non-template) member functions of template classes. We need to mark them used in the instantiated class's scope, rather than the scope we were in before instantiating, as the latter may itself be in template and change the behaviour of marking a function as used. gcc/cp/ * pt.c (instantiate_class_template_1): Process attribute((used)) set in class's context. gcc/testsuite/ * g++.dg/template/attr-used.C: New. --- gcc/cp/pt.c | 13 ++++++++----- gcc/testsuite/g++.dg/template/attr-used.C | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/attr-used.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index c587966adbe..0fa4a162354 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -12277,6 +12277,14 @@ instantiate_class_template_1 (tree type) perform_instantiation_time_access_checks (pattern, args); perform_deferred_access_checks (tf_warning_or_error); + + /* Now that we've gone through all the members, instantiate those + marked with attribute used. We must do this in the context of + the class -- not the context we pushed from, as that might be + inside a template and change the behaviour of mark_used. */ + for (tree x : used) + mark_used (x); + pop_nested_class (); maximum_field_alignment = saved_maximum_field_alignment; if (!fn_context) @@ -12290,11 +12298,6 @@ instantiate_class_template_1 (tree type) if (TYPE_CONTAINS_VPTR_P (type) && CLASSTYPE_KEY_METHOD (type)) vec_safe_push (keyed_classes, type); - /* Now that we've gone through all the members, instantiate those - marked with attribute used. */ - for (tree x : used) - mark_used (x); - return type; } diff --git a/gcc/testsuite/g++.dg/template/attr-used.C b/gcc/testsuite/g++.dg/template/attr-used.C new file mode 100644 index 00000000000..e12bf4caa3f --- /dev/null +++ b/gcc/testsuite/g++.dg/template/attr-used.C @@ -0,0 +1,16 @@ +// { dg-do compile } + +template struct X { + void g () {} + void f () __attribute__((__used__)) {} +}; + +extern X x; // X incomplete here + +template +void Frob (T t) { + x.g(); // X completed here, X::f's body marked for instantiation +} + +// Make sure X::f is emitted +// { dg-final { scan-assembler "_ZN1XIiE1fEv:" } } -- 2.30.2