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 8E6ED395443A for ; Thu, 6 Oct 2022 21:42:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8E6ED395443A 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=1665092566; 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=ojwZiyK+3POV/K6pPtpyIa16s5IEkEVbFAa/tyjxwVM=; b=OcZnroocvY7hUKaVAh5e8uEsMwhSXaaA5A9yZAZojFn6y+fIFFoBH9h5SUVh75jIlRVyWJ H+bU7+m9KjEupYRN2Ruokl4oCVjge+LjW+b5B+N2hBDOdGmkhOYavPe1EDa7ae9cKzkv4d F2yfJaQkQrwQURnha6atywxzijsWnXI= 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-658-1FqlR9CGOqe0wiWRK8NZHQ-1; Thu, 06 Oct 2022 17:42:43 -0400 X-MC-Unique: 1FqlR9CGOqe0wiWRK8NZHQ-1 Received: by mail-qt1-f200.google.com with SMTP id y5-20020ac85245000000b003925165520fso1950569qtn.22 for ; Thu, 06 Oct 2022 14:42:43 -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; bh=ojwZiyK+3POV/K6pPtpyIa16s5IEkEVbFAa/tyjxwVM=; b=6R77zNKwRK/Tct3C1Z11Xd2gfj7reV/CRvFrXhNPGSSZ12CKfn9bXkK/VbOq8ICaKQ ZnfEg7dl3EeniEhj0Tp7dsgU0tG0lvevQQ0CF0vrTXCSq1/HNLCpajCK5/e0Ry3/8H1W XtbhccnsJbDw0nlwaY4M4nUBgGyZXIMr3zqzsw1zl9KjXAg6mJ8JqmODb4v9TWwqCouy kptsj6XAcAxOtuY6wCiJV79R+1lNxRu8xMccOQ3lAYkoPoqNjFjwovlVgzeHxAFuKPIE 83v87sQm4WqPpCZMSqnekr8tLZN0eFQdlSXntBn6RvwjQaIOVGMTRu0yJNjGQNkcryp+ YgFw== X-Gm-Message-State: ACrzQf2EgJ8WRtqqXig8z+Cy4I+w+GUafKGBNboSHFmI5BBc0ez7XD+o MXatmZv5n6HweId4Spws7O1rRcLYlOf19hh99wkJKzpWyobA1VdUWdRlTaIckwfC2BGBf5f1sA2 aBIVt/siuomleIKPDpQ== X-Received: by 2002:a05:6214:20cf:b0:4b1:72a5:2f15 with SMTP id 15-20020a05621420cf00b004b172a52f15mr1806530qve.49.1665092562676; Thu, 06 Oct 2022 14:42:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM76cTXcSpWyZ/mTPT3A4dCuRoflSk4B5d0PsdAA4Yitn48aq6LCs855ZiR6W/GI9yeup8S4Ig== X-Received: by 2002:a05:6214:20cf:b0:4b1:72a5:2f15 with SMTP id 15-20020a05621420cf00b004b172a52f15mr1806521qve.49.1665092562361; Thu, 06 Oct 2022 14:42:42 -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 bn7-20020a05620a2ac700b006ce622e6c96sm227007qkb.30.2022.10.06.14.42.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Oct 2022 14:42:41 -0700 (PDT) Message-ID: <986ebf27-6897-c762-ff5a-d82c465e61a8@redhat.com> Date: Thu, 6 Oct 2022 17:42:41 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.1 Subject: Re: [PATCH v2] c-family: ICE with [[gnu::nocf_check]] [PR106937] To: Marek Polacek Cc: GCC Patches , Joseph Myers References: <20220929224945.90798-1-polacek@redhat.com> <1c85a5bf-82dd-772c-a960-75a495ded832@redhat.com> From: Jason Merrill In-Reply-To: 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.3 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,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 10/4/22 19:06, Marek Polacek wrote: > 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! Indeed, it should be void (* [[gnu::nocf_check]])(void) > 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