From patchwork Thu Sep 29 22:49:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp209754wrs; Thu, 29 Sep 2022 15:50:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Mv2uq4ls8Byyy9J6foKabYY0R0WX7dvwgbC4TgEjVOIkNKcEWzyupo29OtnGLvjq02fuh X-Received: by 2002:a17:906:5a71:b0:770:8625:489e with SMTP id my49-20020a1709065a7100b007708625489emr4489140ejc.405.1664491839813; Thu, 29 Sep 2022 15:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664491839; cv=none; d=google.com; s=arc-20160816; b=YIXF/gyD1781CMA3cNr7vELs+lhLptFCD7P/uje+NE9YbVTy6p3tA6WyHkUvzZc6Aq NN+UvGFiNyE8OXl9lm2YUlVA2zCwmNWnExVHXsXjw/NxyEXPrMV5nOri0572DUEOJlqN 0M6S6AQgqE8aLlemafkoh+1xp2OMM0x0wHeDLGAweV4RgtOVmPCMnl7uYzCpMrjU7Vlt 04RbEXISiMPhXidBUN8IhvDuGX0V1YH39WOgDIHgE3WKospjmYvddJsh+lgDCEDBpU6E siXa8JQU27bqjtqVLZngHRwJ3ATvbHzPrDrCD7R8sUW7DnTAv6+bdZXm1fwQQNHqreip D0uA== 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:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=2QgL75vaXGFUBKSF1NdOrGzsv4rsMH4eLWDDr1MqNfg=; b=kepB+y618JQ1uVGjm6PWozT9mjFm6egNiv/Mtisliq/k8kASc92SWxZnCbWhrZDoEu C2x4pT6AlrJzhtOoTVPCBBI19BFN+x9aQMKiOKBgRP+zp3kBNh/edoRm9X7VdZDMc+z3 jcJ+xQlI09fMO+A4HIvTyafFw20UuFs58pMSGT6xAdT2VGS6Esrfw5wbRntxyhtuMlkg 3GuHa4K5rL/CiBdrkqnBky6kAXmV6jhMvMe1NXYxp1RHGo/hXGfpJ766A+KEfBjLUiQ2 WyZJNoAJjEBsgMbVprQG/3hIbwTV/Q3GG8OJwv0eaI/LZbqIslNB2kTBkuUM1+/hsW6e dU9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=E6OEw8hx; 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 k22-20020aa7c056000000b0044e9fd71b82si600133edo.280.2022.09.29.15.50.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 15:50:39 -0700 (PDT) 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=E6OEw8hx; 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 7E995383FBAA for ; Thu, 29 Sep 2022 22:50:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E995383FBAA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664491835; bh=2QgL75vaXGFUBKSF1NdOrGzsv4rsMH4eLWDDr1MqNfg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=E6OEw8hx9gQZdyNpTpxNBktOzFX4TRRFKYT7941OyIPVOcxWwFncNtmN5dIKBwx3x 8hym/6Bya2VW+rLRdFaKXLlhtlqG1wTVdlt0mdPaFErVNWkvbtrRqTpadlN5H/hflA 604WMBfp10zL8t6RjzFyKaymq8OD7PKBA4q+oQMs= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id E57DE383FB96 for ; Thu, 29 Sep 2022 22:49:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E57DE383FB96 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-189-a01ToNBiMEypgIRB_IQf_Q-1; Thu, 29 Sep 2022 18:49:51 -0400 X-MC-Unique: a01ToNBiMEypgIRB_IQf_Q-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 12CCD811E87; Thu, 29 Sep 2022 22:49:51 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.9.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7027492CA2; Thu, 29 Sep 2022 22:49:50 +0000 (UTC) To: GCC Patches , Jason Merrill , Joseph Myers Subject: [PATCH] c-family: ICE with [[gnu::nocf_check]] [PR106937] Date: Thu, 29 Sep 2022 18:49:45 -0400 Message-Id: <20220929224945.90798-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 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_LOW, 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek 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?1745346195308818410?= X-GMAIL-MSGID: =?utf-8?q?1745346195308818410?= When getting the name of an attribute, we ought to use get_attribute_name, which handles both [[ ]] and __attribute__(()) forms. Failure to do so may result in an ICE, like here. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/106937 gcc/c-family/ChangeLog: * c-pretty-print.cc (pp_c_attributes): Use get_attribute_name. (pp_c_attributes_display): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/fcf-protection-1.c: New test. --- gcc/c-family/c-pretty-print.cc | 8 ++++---- gcc/testsuite/gcc.dg/fcf-protection-1.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/fcf-protection-1.c base-commit: c2ee70f20de8133a88553270073226b0f3f55f62 diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc index efa1768f4d6..91f88b830e3 100644 --- a/gcc/c-family/c-pretty-print.cc +++ b/gcc/c-family/c-pretty-print.cc @@ -863,7 +863,7 @@ pp_c_attributes (c_pretty_printer *pp, tree attributes) pp_c_left_paren (pp); for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes)) { - pp_tree_identifier (pp, TREE_PURPOSE (attributes)); + pp_tree_identifier (pp, get_attribute_name (attributes)); if (TREE_VALUE (attributes)) pp_c_call_argument_list (pp, TREE_VALUE (attributes)); @@ -875,7 +875,7 @@ pp_c_attributes (c_pretty_printer *pp, tree attributes) } /* Pretty-print ATTRIBUTES using GNU C extension syntax for attributes - marked to be displayed on disgnostic. */ + marked to be displayed on diagnostic. */ void pp_c_attributes_display (c_pretty_printer *pp, tree a) @@ -888,7 +888,7 @@ pp_c_attributes_display (c_pretty_printer *pp, tree a) for (; a != NULL_TREE; a = TREE_CHAIN (a)) { const struct attribute_spec *as; - as = lookup_attribute_spec (TREE_PURPOSE (a)); + as = lookup_attribute_spec (get_attribute_name (a)); if (!as || as->affects_type_identity == false) continue; if (c_dialect_cxx () @@ -906,7 +906,7 @@ pp_c_attributes_display (c_pretty_printer *pp, tree a) { pp_separate_with (pp, ','); } - pp_tree_identifier (pp, TREE_PURPOSE (a)); + pp_tree_identifier (pp, get_attribute_name (a)); if (TREE_VALUE (a)) pp_c_call_argument_list (pp, TREE_VALUE (a)); } diff --git a/gcc/testsuite/gcc.dg/fcf-protection-1.c b/gcc/testsuite/gcc.dg/fcf-protection-1.c new file mode 100644 index 00000000000..9d06feadfd1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fcf-protection-1.c @@ -0,0 +1,13 @@ +/* PR c++/106937 */ +/* { dg-options "-fcf-protection -w" } */ + +[[gnu::nocf_check]] typedef void (*FuncPointerWithNoCfCheck)(void); +typedef void (*FuncPointer)(void); +[[gnu::nocf_check]] void testNoCfCheck(); +void testNoCfCheck(){}; +int [[gnu::nocf_check]] i; +void testNoCfCheckImpl(double i [[gnu::nocf_check]]) {} +void testNoCfCheckMismatch(FuncPointer f) { + FuncPointerWithNoCfCheck fNoCfCheck = f; + (*fNoCfCheck)(); +}