From patchwork Fri Nov 11 18:47:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 18968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp909638wru; Fri, 11 Nov 2022 10:48:50 -0800 (PST) X-Google-Smtp-Source: AA0mqf7aYpm7V/kUTTdUxI9PW1Gr0Y5DIHYc+io/5fF3NB0rbEFn4W5bh2dwquvwPvJjo3iilbNe X-Received: by 2002:a05:6402:174c:b0:458:ece7:d1f0 with SMTP id v12-20020a056402174c00b00458ece7d1f0mr2603222edx.409.1668192530657; Fri, 11 Nov 2022 10:48:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668192530; cv=none; d=google.com; s=arc-20160816; b=xiaEsBgrg2zFWbcoUh/TMejyzXLFJeK7OI+O3iqRg/JNtjlA7QPS0Fi6HS6/3t6YUR MMTY1XLk48pDZLgChdWHW4cgvdTsrsjhiXpJVIxTUjRiEP3aagt6nB8M8XC2Imrv2kdB k4YD/CTvPECOsjo8KHmdJT7OFZHWAs71TMN1HO5vAHuUcI1nUmUXpLfgY/sKqylXiO/h 6fxxnaq0Imse0KxUKiygHXsvriSpF+C8zZrflzx9wSb1D5ZCY6QjzXxjryRFSFHvLWXc T1nqQy36hHWI5ANk3G8jFueW4pjq6KCWk40oVngH+NGy9VA0X7S9rXCVaKJXEdIDasZq At/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Aux/yUXQlRa3thzYdZ57YirCTV08H+Q8Sw1+sC2iDuo=; b=BQjd83GIAslQMLboWs6fbcgZVK2g/+5qnNFnpC3DtdDGPD9RgRQoj6eNKHhtjaI5VF LVlmep2IZ7tXL2qdQfE96TDNzdGlxUtgCM9rey0P7RDr9BoT2G8uniVI44BGAxKjBFoA egCThkD1gUkedBmJWZZBVkyQ5RCCifyw8Pk7TpuEIjLbkhtD73VTIIbeRfmYjeRRIhwX nUIou3gkDCf2dcpH64lD5OMWKDSDsj1hMyRwvmi8AADirE8DJX8DxZOBmsm3nAsEouMR DBADBFcktKJuDM0SlAB8Qeq3aEfBBMW3mQpyeHB1qNjWrWTqisaHNufsMqwUPDXbPO/l NQpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dMFu7gYu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qb15-20020a1709077e8f00b00773db392e1esi3108663ejc.997.2022.11.11.10.48.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 10:48:50 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dMFu7gYu; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C7CB3858C2B for ; Fri, 11 Nov 2022 18:48:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C7CB3858C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668192529; bh=Aux/yUXQlRa3thzYdZ57YirCTV08H+Q8Sw1+sC2iDuo=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dMFu7gYuVl7K2koWnBTYrKAf/cdir9vqCYglPlgrqIb1IXLHna07hgonmMcl9yqs0 jX8GpoWQtLARPHj0F6lwi4D3xOPXGhDC2KuG1rNq0+PMtONEu4o70UUglvXuJYowVK E2B92hpyoJhUbGJPuPZ50QMvqqo0tRKLQcZvjHVE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 D725D3858017 for ; Fri, 11 Nov 2022 18:48:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D725D3858017 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-422-b3l81soYMR-qEBTQHMhP-w-1; Fri, 11 Nov 2022 13:48:03 -0500 X-MC-Unique: b3l81soYMR-qEBTQHMhP-w-1 Received: by mail-qv1-f72.google.com with SMTP id nh17-20020a056214391100b004bb6c16bd4dso4176598qvb.17 for ; Fri, 11 Nov 2022 10:48:03 -0800 (PST) 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=Aux/yUXQlRa3thzYdZ57YirCTV08H+Q8Sw1+sC2iDuo=; b=b/lezzCvWHjCuq02tlEoVWtsO9Qb8yDcIn6o7Da90CUZBanu9/QUFRM3F0aVgNW8Di S+9FyZwzD7mTImVr1TJZaztEYjmwVH18/f/h4ag123SZecAz4OO3UN151zHN6xYPFZ0y k03R0PxkhlIhTAzGGPiCNQdr3X35aAvUH9YM4d3C4LqfCv8Uq1wYXSej7bGdahKPcaz2 6IPXuWtuLbE2xprCulhD5GbU5xnKYYT8p38O4dJJ19CTRGJmNOTMcyD0HAWAVan/cW/I k+mIRNh27n1BVtDH3ZlypsZIr/kCgl2ZLPYSNpym7Gn0FmSkGvvrmhPWKiJonBkq3G+9 gdaA== X-Gm-Message-State: ANoB5plDiP1KSH/TpXojIlHD6H/8XkHIQjOQoRnGzBYoyMD96XtowEbT vFOC0mbdjiPZH/iWjS5ssOJBONnp1qVpYxJ2e4pNCNOcFmz+gGKwv8nL812HLGBFr4xggsMnqin VxkJqqu0TUGJ/RYAv14vRuHTaobQjSkVofsM53ztxZa1lE0OFRUl2gn0w2sVAqDn9en0= X-Received: by 2002:a0c:e60f:0:b0:4bc:1237:c5ff with SMTP id z15-20020a0ce60f000000b004bc1237c5ffmr3158276qvm.25.1668192482722; Fri, 11 Nov 2022 10:48:02 -0800 (PST) X-Received: by 2002:a0c:e60f:0:b0:4bc:1237:c5ff with SMTP id z15-20020a0ce60f000000b004bc1237c5ffmr3158254qvm.25.1668192482463; Fri, 11 Nov 2022 10:48:02 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id f9-20020a05620a280900b006b95b0a714esm1833292qkp.17.2022.11.11.10.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Nov 2022 10:48:01 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: init_priority and SUPPORTS_INIT_PRIORITY [PR107638] Date: Fri, 11 Nov 2022 13:47:59 -0500 Message-Id: <20221111184759.2531849-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.1.420.g319605f8f0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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 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: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749226651297738216?= X-GMAIL-MSGID: =?utf-8?q?1749226651297738216?= The commit r13-3706-gd0a492faa6478c for correcting the result of __has_attribute(init_priority) causes a bootstrap failure on hppa64-hpux because it assumes SUPPORTS_INIT_PRIORITY expands to a simple constant, but on this target SUPPORTS_INIT_PRIORITY is defined as #define SUPPORTS_INIT_PRIORITY (TARGET_GNU_LD ? 1 : 0) (where TARGET_GNU_LD expands to something in terms of global_options) which means we can't use this macro to statically exclude the entry for init_priority when defining the cxx_attribute_table. So instead of trying to exclude init_priority from the attribute table for sake of __has_attribute, this patch just makes __has_attribute handle init_priority specially. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? Also sanity checked by artificially defining SUPPORTS_INIT_PRIORITY to 0. PR c++/107638 gcc/c-family/ChangeLog: * c-lex.cc (c_common_has_attribute): Return 1 for init_priority iff SUPPORTS_INIT_PRIORITY. gcc/cp/ChangeLog: * tree.cc (cxx_attribute_table): Don't conditionally exclude the init_priority entry. (handle_init_priority_attribute): Remove ATTRIBUTE_UNUSED. Return error_mark_node if !SUPPORTS_INIT_PRIORITY. --- gcc/c-family/c-lex.cc | 9 +++++++++ gcc/cp/tree.cc | 11 +++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc index 89c65aca28a..2fe562c7ccf 100644 --- a/gcc/c-family/c-lex.cc +++ b/gcc/c-family/c-lex.cc @@ -380,6 +380,15 @@ c_common_has_attribute (cpp_reader *pfile, bool std_syntax) result = 201907; else if (is_attribute_p ("assume", attr_name)) result = 202207; + else if (is_attribute_p ("init_priority", attr_name)) + { + /* The (non-standard) init_priority attribute is always + included in the attribute table, but we don't want to + advertise the attribute unless the target actually + supports init priorities. */ + result = SUPPORTS_INIT_PRIORITY ? 1 : 0; + attr_name = NULL_TREE; + } } else { diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index c30bbeb0839..2324c2269fc 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -5010,10 +5010,8 @@ 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 } @@ -5041,13 +5039,19 @@ const struct attribute_spec std_attribute_table[] = /* Handle an "init_priority" attribute; arguments as in struct attribute_spec.handler. */ -ATTRIBUTE_UNUSED static tree +static tree handle_init_priority_attribute (tree* node, tree name, tree args, int /*flags*/, bool* no_add_attrs) { + if (!SUPPORTS_INIT_PRIORITY) + /* Treat init_priority as an unrecognized attribute (mirroring the + result of __has_attribute) if the target doesn't support init + priorities. */ + return error_mark_node; + tree initp_expr = TREE_VALUE (args); tree decl = *node; tree type = TREE_TYPE (decl); @@ -5105,7 +5109,6 @@ handle_init_priority_attribute (tree* node, pri); } - gcc_assert (SUPPORTS_INIT_PRIORITY); SET_DECL_INIT_PRIORITY (decl, pri); DECL_HAS_INIT_PRIORITY_P (decl) = 1; return NULL_TREE;