From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 58151384DEC8 for ; Fri, 15 Dec 2023 01:26:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58151384DEC8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 58151384DEC8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702603594; cv=none; b=DycqWnhLERFPsvQWFvE1497DUQ1ee1Ohru7DDNOwUZN9lpry4Eu6Xfh5lEhY9NAlzbVErAdrgiDRRwcvz9hHpElh0H2/aF+kfHTLHDpEHQoRjecCSLk0/8LX+P5cFGiUyui+eYifkwn2idqeMTJ/kOF5Nvamjei7K5aFwAsO/V8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702603594; c=relaxed/simple; bh=TM1nXZj7EUee4FFZ3ezZmwVaga6zPNOWps0qIQnr56I=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=CFAnfrufB9DeNVCc0tkYylkvaZjQvL5fhU/2XK6Rr1ydrFn8joZWgYLMG37Q67E34X/rhD8ILtphzo4iUGUvV6tvioDtTv1hxdeEpViO9oIUa5cUMF0djX0w3wFXD9E2ejrseUL7P76Uj4qoCSIRAWXy4lDyLN7w2G5HmSi7ub4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702603591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aT945xcyctX6ON3sgmK8Dr3QPYqk2C9Ff9MWNqAk0X4=; b=I3yr1owAv5pTWurZ8oHin/feo7UW4oUMZwO1fZVSJov7maRTGLUgXAr7gzJuKDKJIH79Hh HP82PGJl0LFZcxikjzBHNFsPOSX/mAg6a6D4jqVwqVym0BiD8I3y3m6aaIORo49v9uCUEB KRnvvFNaBtMtGenxO/x3AEAc6qWtGM4= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-478-W_OfmnX2OPyhEHNSUm13tw-1; Thu, 14 Dec 2023 20:26:29 -0500 X-MC-Unique: W_OfmnX2OPyhEHNSUm13tw-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-425f0ab06a2so2291691cf.3 for ; Thu, 14 Dec 2023 17:26:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702603588; x=1703208388; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aT945xcyctX6ON3sgmK8Dr3QPYqk2C9Ff9MWNqAk0X4=; b=cSBDDe6pN5tI1D1UtYnOVJfJrMlyIzqyu6pN5VIVKJXzVyvrRm4c3C8/o7D66Oui7C vmONwUALOc4WSxktjQqDrbSq5voIJAco9sntaChnMi6PPK3MdzuQB097BaFz+h3GmbAm t6aTb4oqP68X2/T/aT95y3Y76HiHKPj3GkL2QJc8L/9ha5pq8Je3r87EYzK/gJx0Bbf6 HAfvKipDTeZsjdZl7frI/Jh26UtmgBF4hSM2OBueHntBN4IjUztkPDupUwLaWfGdCtEf fZ5tlu5ogLJem89qNblJ+wivAS7/Q4tBf+95JOxTU0r4T9JyJIsP4lvlpqt3W50y4nSa GdRQ== X-Gm-Message-State: AOJu0YxYXMjteS/T2Glvjzw/P7hRHSBb/ldp8Y3DAATf7ZphV3v3ffxs i7X8io2csbS2PaVxIF1PlALcs1bYM/TpfpWAiiTPxBe66aJXXRAKrsZE/P5mNz5DObVa09vq5cd do5zOXCwByL+CQA/M+ShQQ1i7BA== X-Received: by 2002:ac8:7e88:0:b0:425:971f:7d81 with SMTP id w8-20020ac87e88000000b00425971f7d81mr17418201qtj.9.1702603588628; Thu, 14 Dec 2023 17:26:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIx706F/nKDt7YBbbUmifTZ6M6FW1DQiZETqCfO/76GaGD6wS7w0pyku8Yxh/BBgd6Q8TdZA== X-Received: by 2002:ac8:7e88:0:b0:425:971f:7d81 with SMTP id w8-20020ac87e88000000b00425971f7d81mr17418193qtj.9.1702603588329; Thu, 14 Dec 2023 17:26:28 -0800 (PST) Received: from [192.168.1.146] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id f21-20020ac84995000000b00423890096afsm6240505qtq.2.2023.12.14.17.26.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Dec 2023 17:26:27 -0800 (PST) Message-ID: <4060c674-a8f8-480b-9c48-4fe2001c4cfc@redhat.com> Date: Thu, 14 Dec 2023 20:26:27 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++: abi_tag attribute on templates [PR109715] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org References: <20231214191719.1941342-1-ppalka@redhat.com> <7ded5b9e-4718-4a48-9d18-5a88321d2163@redhat.com> <49477513-edfe-7ab6-95d6-7ea3496707ac@idea> <168ac308-cc1e-43af-8f96-19fab9dddfa8@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: On 12/14/23 19:59, Patrick Palka wrote: > On Thu, 14 Dec 2023, Jason Merrill wrote: > >> On 12/14/23 16:08, Patrick Palka wrote: >>> On Thu, 14 Dec 2023, Jason Merrill wrote: >>> >>>> On 12/14/23 14:17, Patrick Palka wrote: >>>>> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for >>>>> trunk? Do we want to condition this on abi_check (19)? >>>> >>>> I think we do, sadly. >>> >>> Sounds good, like so? Bootstrap and regtest in progress. >>> >>> -- >8 -- >>> >>> Subject: [PATCH] c++: abi_tag attribute on templates [PR109715] >>> >>> As with other declaration attributes, we need to look through >>> TEMPLATE_DECL when looking up the abi_tag attribute. >>> >>> PR c++/109715 >>> >>> gcc/cp/ChangeLog: >>> >>> * mangle.cc (get_abi_tags): Look through TEMPLATE_DECL. >>> >>> gcc/testsuite/ChangeLog: >>> >>> * g++.dg/abi/abi-tag25.C: New test. >>> * g++.dg/abi/abi-tag25a.C: New test. >>> --- >>> gcc/cp/mangle.cc | 6 ++++++ >>> gcc/testsuite/g++.dg/abi/abi-tag25.C | 17 +++++++++++++++++ >>> gcc/testsuite/g++.dg/abi/abi-tag25a.C | 11 +++++++++++ >>> 3 files changed, 34 insertions(+) >>> create mode 100644 gcc/testsuite/g++.dg/abi/abi-tag25.C >>> create mode 100644 gcc/testsuite/g++.dg/abi/abi-tag25a.C >>> >>> diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc >>> index 0684f0e6038..e3383df1836 100644 >>> --- a/gcc/cp/mangle.cc >>> +++ b/gcc/cp/mangle.cc >>> @@ -530,6 +530,12 @@ get_abi_tags (tree t) >>> if (DECL_P (t) && DECL_DECLARES_TYPE_P (t)) >>> t = TREE_TYPE (t); >>> + if (TREE_CODE (t) == TEMPLATE_DECL >>> + && DECL_TEMPLATE_RESULT (t) >>> + /* We used to ignore abi_tag on function and variable templates. */ >>> + && abi_check (19)) >>> + t = DECL_TEMPLATE_RESULT (t); >> >> Generally I try to call abi_check only when we know that there's something >> that will change the mangling, so here only if the template has ABI tags. I >> suppose the only downside is a second mangling that produces the same name and >> gets ignored in mangle_decl so we don't need to be too strict about it, but it >> shouldn't be too hard to do that here? > > D'oh, good point.. Otherwise IIUC we'd wastefully mangle most function > and variable templates (and perhaps their instantiations) twice when ABI > checks are enabled. > > So like the following then? Implemented using a recurse call but > we could easily implement it without recursion if anything. OK, thanks. > -- >8 -- > > We need to look through TEMPLATE_DECL when looking up the abi_tag > attribute (as with other function and variable declaration attributes). > > PR c++/109715 > > gcc/cp/ChangeLog: > > * mangle.cc (get_abi_tags): Strip TEMPLATE_DECL before looking > up the abi_tag attribute. > > gcc/testsuite/ChangeLog: > > * g++.dg/abi/abi-tag25.C: New test. > * g++.dg/abi/abi-tag25a.C: New test. > --- > gcc/cp/mangle.cc | 10 ++++++++++ > gcc/testsuite/g++.dg/abi/abi-tag25.C | 17 +++++++++++++++++ > gcc/testsuite/g++.dg/abi/abi-tag25a.C | 11 +++++++++++ > 3 files changed, 38 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/abi/abi-tag25.C > create mode 100644 gcc/testsuite/g++.dg/abi/abi-tag25a.C > > diff --git a/gcc/cp/mangle.cc b/gcc/cp/mangle.cc > index 0684f0e6038..365d470f46e 100644 > --- a/gcc/cp/mangle.cc > +++ b/gcc/cp/mangle.cc > @@ -530,6 +530,16 @@ get_abi_tags (tree t) > if (DECL_P (t) && DECL_DECLARES_TYPE_P (t)) > t = TREE_TYPE (t); > > + if (TREE_CODE (t) == TEMPLATE_DECL && DECL_TEMPLATE_RESULT (t)) > + { > + tree tags = get_abi_tags (DECL_TEMPLATE_RESULT (t)); > + /* We used to overlook abi_tag on function and variable templates. */ > + if (tags && abi_check (19)) > + return tags; > + else > + return NULL_TREE; > + } > + > tree attrs; > if (TYPE_P (t)) > attrs = TYPE_ATTRIBUTES (t); > diff --git a/gcc/testsuite/g++.dg/abi/abi-tag25.C b/gcc/testsuite/g++.dg/abi/abi-tag25.C > new file mode 100644 > index 00000000000..9847f0dccc8 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/abi/abi-tag25.C > @@ -0,0 +1,17 @@ > +// PR c++/109715 > +// { dg-do compile { target c++11 } } > + > +template > +[[gnu::abi_tag("foo")]] void fun() { } > + > +template void fun(); > + > +#if __cpp_variable_templates > +template > +[[gnu::abi_tag("foo")]] int var = 0; > + > +template int var; > +#endif > + > +// { dg-final { scan-assembler "_Z3funB3fooIiEvv" } } > +// { dg-final { scan-assembler "_Z3varB3fooIiE" { target c++14 } } } > diff --git a/gcc/testsuite/g++.dg/abi/abi-tag25a.C b/gcc/testsuite/g++.dg/abi/abi-tag25a.C > new file mode 100644 > index 00000000000..9499b5614cd > --- /dev/null > +++ b/gcc/testsuite/g++.dg/abi/abi-tag25a.C > @@ -0,0 +1,11 @@ > +// PR c++/109715 > +// { dg-do compile { target c++11 } } > +// { dg-additional-options "-fabi-version=18 -fabi-compat-version=18 -Wabi=0" } > + > +#include "abi-tag25.C" > + > +// { dg-warning "mangled name" "" { target *-*-* } 5 } > +// { dg-warning "mangled name" "" { target *-*-* } 11 } > + > +// { dg-final { scan-assembler "_Z3funIiEvv" } } > +// { dg-final { scan-assembler "_Z3varIiE" { target c++14 } } }