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 6D5F13858428 for ; Tue, 4 Oct 2022 23:06:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D5F13858428 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=1664924785; 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: in-reply-to:in-reply-to:references:references; bh=8IVrpkwFwOTsz0YiMEh2zBoh+W9/twsgfog2gEyh8Tw=; b=Be/A/RaNkRM8N3T3O4XBNbkWXRM+/cZVIsfb6XEILYZoW7E3kEneedps0ArUL7HGFNtDsy zzouQNxAd8FtbPPtYgPUXuMgqc30KqIyvVnFikKRV41tm4V0Wc5NMmezsvIfdhB0br8g0L vTt5qELYvW4CZaep0RceC2YvSVh2dsQ= 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-558--2m8CSnMNfCmbH9h11_gvA-1; Tue, 04 Oct 2022 19:06:24 -0400 X-MC-Unique: -2m8CSnMNfCmbH9h11_gvA-1 Received: by mail-qk1-f199.google.com with SMTP id h7-20020a05620a400700b006cebec84734so13082179qko.23 for ; Tue, 04 Oct 2022 16:06:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date; bh=8IVrpkwFwOTsz0YiMEh2zBoh+W9/twsgfog2gEyh8Tw=; b=2AjH+PhyKXIwXijxFIea/tJrpLLRcUNK/QNcYaIPGt/+ZbUhuiVlkWlXaTH/CiUr3U mN0Fl/+vQUErC9j6ydbac5iSu825C3U+od4/MjDtq9BX3ZWl34U32WeiXS3x8YO3e6mH MCd/IR+A76BVaQco28A6gltOwZo2GH5WvJQPfDBYVfrQSwG6tDX04CePoPgYw9JL7GOf 2BXJLgVp0R9acX6O8w2GWAwEtcSZ2TgSjbJiMVKhpxGJ1uGbLdLXUlaJL8v5885XosJ1 L91uXg1PluSXcpIUAaHN8mQsk7YbWuBEXDJ1BeJ6qoBpI29ehEBqXSB8/2kkE57bb0iC qQRg== X-Gm-Message-State: ACrzQf1hYNjMr6H8nK0qEXchixefPdcPAqDYjq4yMsnnYFdG5NEOiVgC qy0sYhVo6bIgGXLaeg5RheTxswsseN2yAT8XozOc8gZ76qpUkz4Xmj54L8dFYe/+lAqnWIVfV2o Sl/Oh3+IV+WM6IV/3Yw== X-Received: by 2002:ad4:5949:0:b0:4ad:89bb:f00f with SMTP id eo9-20020ad45949000000b004ad89bbf00fmr21398969qvb.114.1664924784121; Tue, 04 Oct 2022 16:06:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM49lz6ODQXyoc35l6O0wJx2DsuhHzkUVzZaa6JiINXRh9v68Pk8ORbNLyWu46txc4nr28TbCg== X-Received: by 2002:ad4:5949:0:b0:4ad:89bb:f00f with SMTP id eo9-20020ad45949000000b004ad89bbf00fmr21398953qvb.114.1664924783890; Tue, 04 Oct 2022 16:06:23 -0700 (PDT) Received: from redhat.com (2603-7000-9500-2e39-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:2e39::1db4]) by smtp.gmail.com with ESMTPSA id bk40-20020a05620a1a2800b006bc1512986esm15638461qkb.97.2022.10.04.16.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 16:06:23 -0700 (PDT) Date: Tue, 4 Oct 2022 19:06:21 -0400 From: Marek Polacek To: Jason Merrill Cc: GCC Patches , Joseph Myers Subject: [PATCH v2] c-family: ICE with [[gnu::nocf_check]] [PR106937] Message-ID: References: <20220929224945.90798-1-polacek@redhat.com> <1c85a5bf-82dd-772c-a960-75a495ded832@redhat.com> MIME-Version: 1.0 In-Reply-To: <1c85a5bf-82dd-772c-a960-75a495ded832@redhat.com> User-Agent: Mutt/2.2.7 (2022-08-07) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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,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 Fri, Sep 30, 2022 at 09:12:24AM -0400, Jason Merrill wrote: > On 9/29/22 18:49, Marek Polacek wrote: > > 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? > > How do we print the attributes with this patch? Don't we also want to print > the namespace, and use [[]] in the output? Good point, however: while the testcase indeed has an attribute in the [[]] form in the typedef, here we're printing its "aka": warning: initialization of 'FuncPointerWithNoCfCheck' {aka 'void (__attribute__((nocf_check)) *)(void)'} from incompatible pointer type 'FuncPointer' {aka 'void (*)(void)'} c-pretty-print.cc doesn't seem to know how to print an [[]] attribute. I could do that, but then we'd print aka 'void ([[nocf_check]] *)(void)' in the above, but that's invalid syntax! pp_c_attributes_display appears to be called for * and & only where you can't use an [[]] attribute. So perhaps we want to keep printing the GNU form here? I noticed that pp_c_attributes has never been used, so we can just remove it. I've also adjusted the test not to use "-w". Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- 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. pp_c_attributes has been unused since its introduction in r56273. PR c++/106937 gcc/c-family/ChangeLog: * c-pretty-print.cc (pp_c_attributes): Remove. (pp_c_attributes_display): Use get_attribute_name. * c-pretty-print.h (pp_c_attributes): Remove. gcc/testsuite/ChangeLog: * gcc.dg/fcf-protection-1.c: New test. --- gcc/c-family/c-pretty-print.cc | 30 +++---------------------- gcc/c-family/c-pretty-print.h | 1 - gcc/testsuite/gcc.dg/fcf-protection-1.c | 13 +++++++++++ 3 files changed, 16 insertions(+), 28 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/fcf-protection-1.c diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc index efa1768f4d6..2419e149333 100644 --- a/gcc/c-family/c-pretty-print.cc +++ b/gcc/c-family/c-pretty-print.cc @@ -850,32 +850,8 @@ c_pretty_printer::declaration (tree t) pp_c_init_declarator (this, t); } -/* Pretty-print ATTRIBUTES using GNU C extension syntax. */ - -void -pp_c_attributes (c_pretty_printer *pp, tree attributes) -{ - if (attributes == NULL_TREE) - return; - - pp_c_ws_string (pp, "__attribute__"); - pp_c_left_paren (pp); - pp_c_left_paren (pp); - for (; attributes != NULL_TREE; attributes = TREE_CHAIN (attributes)) - { - pp_tree_identifier (pp, TREE_PURPOSE (attributes)); - if (TREE_VALUE (attributes)) - pp_c_call_argument_list (pp, TREE_VALUE (attributes)); - - if (TREE_CHAIN (attributes)) - pp_separate_with (pp, ','); - } - pp_c_right_paren (pp); - pp_c_right_paren (pp); -} - /* 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 +864,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 +882,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/c-family/c-pretty-print.h b/gcc/c-family/c-pretty-print.h index be86bed4fee..92674ab4d06 100644 --- a/gcc/c-family/c-pretty-print.h +++ b/gcc/c-family/c-pretty-print.h @@ -119,7 +119,6 @@ void pp_c_space_for_pointer_operator (c_pretty_printer *, tree); /* Declarations. */ void pp_c_tree_decl_identifier (c_pretty_printer *, tree); void pp_c_function_definition (c_pretty_printer *, tree); -void pp_c_attributes (c_pretty_printer *, tree); void pp_c_attributes_display (c_pretty_printer *, tree); void pp_c_cv_qualifiers (c_pretty_printer *pp, int qualifiers, bool func_type); void pp_c_type_qualifier_list (c_pretty_printer *, tree); 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..baad74cd86f --- /dev/null +++ b/gcc/testsuite/gcc.dg/fcf-protection-1.c @@ -0,0 +1,13 @@ +/* PR c++/106937 */ +/* { dg-options "-fcf-protection" } */ + +[[gnu::nocf_check]] typedef void (*FuncPointerWithNoCfCheck)(void); +typedef void (*FuncPointer)(void); +[[gnu::nocf_check]] void testNoCfCheck(); +void testNoCfCheck(){}; +int i; +void testNoCfCheckImpl(double i) {} +void testNoCfCheckMismatch(FuncPointer f) { + FuncPointerWithNoCfCheck fNoCfCheck = f; /* { dg-warning "initialization" } */ + (*fNoCfCheck)(); +} base-commit: ade1e0d5896221500d1cbda38cd631cf80325aaa -- 2.37.3