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.129.124]) by sourceware.org (Postfix) with ESMTPS id F2040385841C for ; Fri, 4 Nov 2022 15:05:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F2040385841C 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=1667574331; 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; bh=SiHoEGlKNa6IhUXGZql+tHZGKoj6aaAKkiE873CTqPo=; b=KCqdmTAcgDG4DpqeYDGjy5s2drsmdgRliWWDyL6NnUWT3mnJrth4LMNsozyrIBHyItg2zT RZK4ig45swxZilUVU1jZYacIXSafl+rwELqB+8OiLkPSaQs7Suq0QnMf3fT1DJSirFlTjZ tnTqvdP6UHqTMsvaBulxAetKYHgWlXE= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-531-w4qDOKrJN823SfcLykjXNw-1; Fri, 04 Nov 2022 11:05:30 -0400 X-MC-Unique: w4qDOKrJN823SfcLykjXNw-1 Received: by mail-qk1-f199.google.com with SMTP id bm2-20020a05620a198200b006fa6eeee4a9so4611669qkb.14 for ; Fri, 04 Nov 2022 08:05:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SiHoEGlKNa6IhUXGZql+tHZGKoj6aaAKkiE873CTqPo=; b=lOZHL0mJvqTtcnh2Ms3orksnZ32uX62AumR/AY7rV/V/3UnjPr6eH5Lu3pZJ43sN2q MGokGugsrSt7bFjZF6rVfAeWuNQ+22K2KHEH2daNBCigAWtVwHRdRvauiZd/j0E1qXXW 6ttZQHYi/7VOEGb3hyvzdTGq01AXtVHWgxw0dLhBW3V+laUmaVDXMQHAVKmn4fruGZVR zy6grj4YmKLL9EvLAmRHzAxaFlB/GsxINiUK8T3nCK1wEnW1lOjYnaIvVxoWyXNjURAk DgC6+s+DIXQ/SZmX1eUZBj/s0wb63BEIpWaM0UXNQCDJbpbjZKM/gP/h5GGqRg79vn7z vUTg== X-Gm-Message-State: ACrzQf2Sd1rhveiYgr7xkr1s+yfO9hqkM9ircahZjuaOjVHC+u93sp15 ynn2ClKv1Ke7Dzw6bOElSXBcVHBF3LGnZBSSOocpBryR87rSiCq2oONn9yrw/MZA7Fv/xUDd7v4 VUzfll12h+on5UlU= X-Received: by 2002:a05:620a:2b93:b0:6fa:307f:e074 with SMTP id dz19-20020a05620a2b9300b006fa307fe074mr19806835qkb.523.1667574329925; Fri, 04 Nov 2022 08:05:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6J5y3bK2EphMASorTD1Ac7wNyDGjovSO3HJuYwJGnNDmywUhLOhUEfo2u4YdiHJegvmF8Nlg== X-Received: by 2002:a05:620a:2b93:b0:6fa:307f:e074 with SMTP id dz19-20020a05620a2b9300b006fa307fe074mr19806808qkb.523.1667574329632; Fri, 04 Nov 2022 08:05:29 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id cx26-20020a05620a51da00b006fa12a74c53sm3018498qkb.61.2022.11.04.08.05.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 08:05:29 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Patrick Palka Subject: [PATCH 1/2] c++: correct __has_attribute(init_priority) Date: Fri, 4 Nov 2022 11:05:24 -0400 Message-Id: <20221104150525.2968778-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.1.385.g3b08839926 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.3 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_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: 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. 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 } -- 2.38.1.385.g3b08839926