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 340AC38376E6 for ; Wed, 25 May 2022 19:51:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 340AC38376E6 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-NZoA_Cz7M0e60bv6UsEHJA-1; Wed, 25 May 2022 15:51:33 -0400 X-MC-Unique: NZoA_Cz7M0e60bv6UsEHJA-1 Received: by mail-qt1-f197.google.com with SMTP id 4-20020ac85944000000b002f935868212so7625596qtz.1 for ; Wed, 25 May 2022 12:51:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=24+CbF8pvzQVibpxBRvBIGl3r/tzcfmyiat32yZ6xmw=; b=EZDERKNq69raU9mPSYX4tyzqMe1kElyswv0fp65114l2UzknH6BeAB7yf0Oww9X/mM Sd6+oJREp+1Bea5A/8CS7fpbe955TMffcXiHWTUd1ZOPoULaO+MUXTuXrsq/5TetvMCX 8W+As6PX18AqFmzqAmWk6fO6tW4ewMze1rUwEKolq1X/mexRczOk9asoQlE9c2WtMVP8 XR4PmNtWoyZnORs4ykvftwd+YyoO7erT3yoHINLa5IsqgHk6LWjNt0lDimGG3UDNVEhv qXYxWDA6vVzGt7XbGsjQuznCNkS63TEhTK2UMhMOHJiKWp8EGmoyy5aexgzohBxfxTRE 4QPA== X-Gm-Message-State: AOAM530eBjqYUlaVg8fe8jtU6Ns2jnUHMTi2oNV2B06soWGRBKzwrBN1 VqwPLQXxeoHivGtOZfswWogScY9MbJTEhhjh9eCn/7HJEoCv8J7DQA2bWBvIitqHgmLtwNfVZvV atLhsDwwhDVS8obPDxQ== X-Received: by 2002:a05:6214:2468:b0:462:648c:3631 with SMTP id im8-20020a056214246800b00462648c3631mr3443096qvb.48.1653508292689; Wed, 25 May 2022 12:51:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyL4glmHPXGVGvjJf4GEe9ZgGkQxctBgvAKAE0mq27rbtADLQ5tEUaft65x+XB4Mci+imnTKQ== X-Received: by 2002:a05:6214:2468:b0:462:648c:3631 with SMTP id im8-20020a056214246800b00462648c3631mr3443074qvb.48.1653508292359; Wed, 25 May 2022 12:51:32 -0700 (PDT) Received: from [192.168.1.100] (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 x23-20020ae9e917000000b0069fc13ce1d4sm1846402qkf.5.2022.05.25.12.51.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 May 2022 12:51:31 -0700 (PDT) Message-ID: Date: Wed, 25 May 2022 15:51:30 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] c++: fix ICE on invalid attributes [PR96637] To: Marek Polacek Cc: GCC Patches References: <20220429141233.41897-1-polacek@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=-12.7 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, T_SCC_BODY_TEXT_LINE 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-List-Received-Date: Wed, 25 May 2022 19:51:36 -0000 On 5/25/22 14:49, Marek Polacek wrote: > On Tue, May 24, 2022 at 08:22:22AM -0400, Jason Merrill wrote: >> On 4/29/22 10:12, Marek Polacek wrote: >>> This patch fixes crashes with invalid attributes. Arguably it could >>> make sense to assert seen_error() too. >> >> So in this testcase we have TREE_CHAIN of a TREE_LIST pointing to >> error_mark_node? Can we avoid that? > > Yes and yes. Sorry, my previous fix was lousy. This one is better: > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? OK, thanks. > -- >8 -- > When chaining attributes, attr_chainon should be used rather than plain > chainon, so that we don't end up with a TREE_LIST where one of the elements > is error_mark_node, which causes problems. parser.cc has already been > fixed to use attr_chainon, but decl.cc has not. Until now. > > PR c++/96637 > > gcc/cp/ChangeLog: > > * cp-tree.h (attr_chainon): Declare. > * decl.cc (start_decl): Use attr_chainon. > (grokdeclarator): Likewise. > * parser.cc (cp_parser_statement): No longer static. > > gcc/testsuite/ChangeLog: > > * g++.dg/parse/error64.C: New test. > --- > gcc/cp/cp-tree.h | 1 + > gcc/cp/decl.cc | 19 ++++++++++--------- > gcc/cp/parser.cc | 2 +- > gcc/testsuite/g++.dg/parse/error64.C | 4 ++++ > 4 files changed, 16 insertions(+), 10 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/parse/error64.C > > diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h > index ba986e892b6..d77fd1eb8a9 100644 > --- a/gcc/cp/cp-tree.h > +++ b/gcc/cp/cp-tree.h > @@ -7235,6 +7235,7 @@ extern void inject_this_parameter (tree, cp_cv_quals); > extern location_t defparse_location (tree); > extern void maybe_show_extern_c_location (void); > extern bool literal_integer_zerop (const_tree); > +extern tree attr_chainon (tree, tree); > > /* in pt.cc */ > extern tree canonical_type_parameter (tree); > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index 381259cb9cf..b1ea838ce8b 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -5557,7 +5557,7 @@ start_decl (const cp_declarator *declarator, > *pushed_scope_p = NULL_TREE; > > if (prefix_attributes != error_mark_node) > - attributes = chainon (attributes, prefix_attributes); > + attributes = attr_chainon (attributes, prefix_attributes); > > decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, > &attributes); > @@ -12728,9 +12728,10 @@ grokdeclarator (const cp_declarator *declarator, > as a whole. */ > late_attrs = splice_template_attributes (&attrs, type); > returned_attrs = decl_attributes (&type, > - chainon (returned_attrs, attrs), > + attr_chainon (returned_attrs, > + attrs), > attr_flags); > - returned_attrs = chainon (late_attrs, returned_attrs); > + returned_attrs = attr_chainon (late_attrs, returned_attrs); > } > > inner_declarator = declarator->declarator; > @@ -12781,8 +12782,8 @@ grokdeclarator (const cp_declarator *declarator, > > The optional attribute-specifier-seq appertains to the > array. */ > - returned_attrs = chainon (returned_attrs, > - declarator->std_attributes); > + returned_attrs = attr_chainon (returned_attrs, > + declarator->std_attributes); > break; > > case cdk_function: > @@ -13122,9 +13123,9 @@ grokdeclarator (const cp_declarator *declarator, > /* transaction_safe applies to the type, but > transaction_safe_dynamic applies to the function. */ > if (is_attribute_p ("transaction_safe", tx_qual)) > - attrs = chainon (attrs, att); > + attrs = attr_chainon (attrs, att); > else > - returned_attrs = chainon (returned_attrs, att); > + returned_attrs = attr_chainon (returned_attrs, att); > } > if (attrs) > /* [dcl.fct]/2: > @@ -13438,7 +13439,7 @@ grokdeclarator (const cp_declarator *declarator, > if (returned_attrs) > { > if (attrlist) > - *attrlist = chainon (returned_attrs, *attrlist); > + *attrlist = attr_chainon (returned_attrs, *attrlist); > else > attrlist = &returned_attrs; > } > @@ -13451,7 +13452,7 @@ grokdeclarator (const cp_declarator *declarator, > /* [dcl.meaning]/1: The optional attribute-specifier-seq following > a declarator-id appertains to the entity that is declared. */ > if (declarator->std_attributes != error_mark_node) > - *attrlist = chainon (*attrlist, declarator->std_attributes); > + *attrlist = attr_chainon (*attrlist, declarator->std_attributes); > else > /* We should have already diagnosed the issue (c++/78344). */ > gcc_assert (seen_error ()); > diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc > index 868b8610d60..62aaccda23d 100644 > --- a/gcc/cp/parser.cc > +++ b/gcc/cp/parser.cc > @@ -12557,7 +12557,7 @@ cp_parser_statement (cp_parser* parser, tree in_statement_expr, > > /* Append ATTR to attribute list ATTRS. */ > > -static tree > +tree > attr_chainon (tree attrs, tree attr) > { > if (attrs == error_mark_node) > diff --git a/gcc/testsuite/g++.dg/parse/error64.C b/gcc/testsuite/g++.dg/parse/error64.C > new file mode 100644 > index 00000000000..87848a58c27 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/parse/error64.C > @@ -0,0 +1,4 @@ > +// PR c++/96637 > +// { dg-do compile } > + > +void foo(int[] alignas[1] alignas(1)){} // { dg-error "" } > > base-commit: 850a9ce8bcca59c7efabcdeeca14c5bd905e8363