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 4F34C3858C2B for ; Fri, 4 Nov 2022 15:56:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F34C3858C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667577363; 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=sZHfNz0STt/gkGcfsy4WI7znqbNICbslv1iTx8HkVj0=; b=SGWoFLviyV5zQFFKNHmrDCsj26NUkV+U+Ya03LcpRBFaWgVscvRR6Nyl61cLQNiHCOzoUN +mXx7fYTUZXLwVILP4weYWCvcFYrtzr0kD5qijc672vTEC7249tUmKQ16vZqOOWxx6/4ii bwqTts9wtXDQZlFWAAvKjtgv/nO/aPw= 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_128_GCM_SHA256) id us-mta-76-tpGmREP7Mb6Lv_WMH8MkBQ-1; Fri, 04 Nov 2022 11:56:02 -0400 X-MC-Unique: tpGmREP7Mb6Lv_WMH8MkBQ-1 Received: by mail-qt1-f200.google.com with SMTP id i4-20020ac813c4000000b003a5044a818cso4001870qtj.11 for ; Fri, 04 Nov 2022 08:56:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=sZHfNz0STt/gkGcfsy4WI7znqbNICbslv1iTx8HkVj0=; b=wyg6/4Zmn+Dzg2gs8xIM1wsJVfbcC3kLyQ2FHKfUovYlRcelblS3GHef9pG2UNPPA1 i79LMxtcddcyyDi4wydRvwBRp/eKcgaYlrq4I337am6CUn6Wa3mr7CGfciomXrbiN8cM FS7Jl2uRThpP+TZMkiHUEoV0f348bdk7STpxf3EDE75H7X4VnJc1ovZQBUjLtQjsgIOH +hUSfVLL/I0ywVlzMtFDGqdp8o5fkrrOu8z+MncNooyRPJQeBbQozS1ADQDZDgm6gsvQ 3zr9QVnJHqUM+rXGLp0/xmBtksIFhnNrmoQSKC/djqPb339LGgq4IGTkk1u7Tse2vLzW Yoeg== X-Gm-Message-State: ACrzQf2kkztxNaOgdxr/embI30CRDJcoxzOgYj12MO0YsuW09xfYIGS4 p1KcgwyDpwvYi8+eYO0fKpVMLDNdDFt2Y9egSvW8ULXqyAVCBwcuFy+GbEs12GEpzxfuzouYwvb GLtwte1o3DzRMPEM= X-Received: by 2002:ae9:d846:0:b0:6fa:f72:66f3 with SMTP id u67-20020ae9d846000000b006fa0f7266f3mr26398853qkf.522.1667577361683; Fri, 04 Nov 2022 08:56:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4HL7NQ5NtN1ljF5kUMdJIPIxBUtPrHnPPQvRgeik8EXyD+N+VDVra1DbpZ5ins7Lk7iRt9Ww== X-Received: by 2002:ae9:d846:0:b0:6fa:f72:66f3 with SMTP id u67-20020ae9d846000000b006fa0f7266f3mr26398832qkf.522.1667577361349; Fri, 04 Nov 2022 08:56:01 -0700 (PDT) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id z6-20020a05622a060600b003998bb7b83asm2656133qta.90.2022.11.04.08.56.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Nov 2022 08:56:00 -0700 (PDT) Message-ID: <9952e423-4e25-4ba5-8236-5fbb3b027c9d@redhat.com> Date: Fri, 4 Nov 2022 11:55:59 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH 1/2] c++: correct __has_attribute(init_priority) To: Patrick Palka , gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org References: <20221104150525.2968778-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20221104150525.2968778-1-ppalka@redhat.com> 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=-13.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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 11/4/22 11:05, Patrick Palka wrote: > Currently __has_attribute(init_priority) always returns true, even on > targets that don't actually support init priorities, and when using > the attribute on such targets, we issue a hard error that init > priorities are unsupported. This makes it impossible to conditionally > use the attribute by querying __has_attribute. > > This patch fixes this by adding the attribute to the attribute table > only if the target supports init priorities, so that __has_attribute > returns false appropriately. Thus on such targets we'll now treat it as > just another unrecognized attribute, so using it gives a -Wattribute > warning instead of an error. OK. > gcc/cp/ChangeLog: > > * tree.cc (cxx_attribute_table): Add entry for init_priority > only if SUPPORTS_INIT_PRIORITY. > (handle_init_priority_attribute): Assert SUPPORTS_INIT_PRIORITY > is true. > > gcc/testsuite/ChangeLog: > > * g++.dg/special/initpri3.C: New test. > --- > gcc/cp/tree.cc | 20 +++++++------------- > gcc/testsuite/g++.dg/special/initpri3.C | 9 +++++++++ > 2 files changed, 16 insertions(+), 13 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/special/initpri3.C > > diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc > index 45348c58bb6..c30bbeb0839 100644 > --- a/gcc/cp/tree.cc > +++ b/gcc/cp/tree.cc > @@ -5010,8 +5010,10 @@ const struct attribute_spec cxx_attribute_table[] = > { > /* { name, min_len, max_len, decl_req, type_req, fn_type_req, > affects_type_identity, handler, exclude } */ > +#if SUPPORTS_INIT_PRIORITY > { "init_priority", 1, 1, true, false, false, false, > handle_init_priority_attribute, NULL }, > +#endif > { "abi_tag", 1, -1, false, false, false, true, > handle_abi_tag_attribute, NULL }, > { NULL, 0, 0, false, false, false, false, NULL, NULL } > @@ -5039,7 +5041,7 @@ const struct attribute_spec std_attribute_table[] = > > /* Handle an "init_priority" attribute; arguments as in > struct attribute_spec.handler. */ > -static tree > +ATTRIBUTE_UNUSED static tree > handle_init_priority_attribute (tree* node, > tree name, > tree args, > @@ -5103,18 +5105,10 @@ handle_init_priority_attribute (tree* node, > pri); > } > > - if (SUPPORTS_INIT_PRIORITY) > - { > - SET_DECL_INIT_PRIORITY (decl, pri); > - DECL_HAS_INIT_PRIORITY_P (decl) = 1; > - return NULL_TREE; > - } > - else > - { > - error ("%qE attribute is not supported on this platform", name); > - *no_add_attrs = true; > - return NULL_TREE; > - } > + gcc_assert (SUPPORTS_INIT_PRIORITY); > + SET_DECL_INIT_PRIORITY (decl, pri); > + DECL_HAS_INIT_PRIORITY_P (decl) = 1; > + return NULL_TREE; > } > > /* DECL is being redeclared; the old declaration had the abi tags in OLD, > diff --git a/gcc/testsuite/g++.dg/special/initpri3.C b/gcc/testsuite/g++.dg/special/initpri3.C > new file mode 100644 > index 00000000000..a181abdd0b1 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/special/initpri3.C > @@ -0,0 +1,9 @@ > +// Verify __has_attribute(init_priority) is false whenever the platform > +// doesn't support it, and is treated as an unrecognized attribute. > + > +#if !__has_attribute(init_priority) > +#error init_priority /* { dg-error "" "" { target { ! init_priority } } } */ > +#endif > + > +struct A { A(); } a __attribute__((init_priority(500))); > +// { dg-warning "attribute directive ignored" "" { target { ! init_priority } } .-1 }