Message ID | ZW9XL+ac5rY9XbF9@tucnak |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3567784vqy; Tue, 5 Dec 2023 09:01:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUqzT0PqjpU7M/6MF+eet/ifcsaqeAOLyOH/tnAifr6m6q4VQJCxZ/5t7fBxnp7Dj/E5L3 X-Received: by 2002:a5b:90d:0:b0:db5:4998:86ed with SMTP id a13-20020a5b090d000000b00db5499886edmr4184754ybq.13.1701795666419; Tue, 05 Dec 2023 09:01:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701795666; cv=pass; d=google.com; s=arc-20160816; b=MZxHOjS7dW2KiZ3E6jHKYCoFw7/+je8s5MP0juhLKo/pxc3I8OantdT9II6a9Dyq4Q K4z6sC41erTt2w5MSWYwKdCNmtRBIFUZJRKs4O1UXagnyAfm0mdLxtEwFhh4+/fUF3WC bQH9XbudIIlwb9HCRMglq5BlcH0G8/O9/ytsK/7K9Jr1vdU67iWfb4qZabP2tW+0GA7I FFW4JMGr0iWfgTHGbXCbNXVQCpJ50bDToMmMew/feOsORCuNsuG611S6Em9hGK9d95Y7 HcUcLRd53K55PWqyfqWmYZbFkCjgP1lYO9qBli4aSrFWLnoMT/35xJoiMNd7FIXi2x9b Ca3g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=Kkwko+lQEAYmw+jJjqxI2E61FLVP+4WfdUuG5Zici/A=; fh=Srr+sQZqPbVACuFZHCIgubrKr6t+F7lvGKnevvbDcuU=; b=YSHKpeDm9mrwvttXdCawecSNlIoxYLvqm19KY4QuXwH+4CweppwunV74+++RTRYgab seoRCXE6JQ/A7uKVkt6fq3ddsJyTAmKwv+80Ef+DV7losHWUmESLnSftIxUJGAEGIJK/ rsQAMtu09VhGpWYfLE7fTvUUWD05qQmSvOrEcsnWA4Z2b7AUvTHa+8bHAhqDMWIOZDBc QnpVz3M1Qmm0kvsQvNLlJhqJpgq/UU6i68gK/dv0avD0q4Unb4kvYx63pwhNI0QdU3px FHDG/lC+Xe5avv3jDQmNpjfkmxT6CDe9EfLm8RkCm2xaB8WncmcHN/2XaZOK0FuIOAZB Z5QQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LMOaSdxo; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 126-20020a250d84000000b00daff0bbfeb0si5346423ybn.400.2023.12.05.09.01.06 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 09:01:06 -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=@redhat.com header.s=mimecast20190719 header.b=LMOaSdxo; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27E5A3858281 for <ouuuleilei@gmail.com>; Tue, 5 Dec 2023 17:01:06 +0000 (GMT) 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 906D03858D32 for <gcc-patches@gcc.gnu.org>; Tue, 5 Dec 2023 17:00:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 906D03858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 906D03858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701795638; cv=none; b=V5KNeZeoTe+0ZUtv8qp9Zks0VsgLlPSwbp/SS4J9pshFAy+Y3Mvyv5Iv6GI7d/jRHCPAcjp99icBcob5fxW9u4cyu/K3iCiEHeBAUg9Q22AzoR/87CASI3G8GrlbJTnkbY2D4Azj8C2NmkdnRkophB1bw3+wnFBZIQYSUIYbIo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701795638; c=relaxed/simple; bh=5Qz+VNMk86hLiWqyY0EkcAchsxVUbTVBXvbB3gmiSzk=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=BzwSPLbhbWOH35TDn20jEZjeYdMAWGo/4cl4dViyds3BUWwu25By6q1GtD9Fq25utVNxCNJtwxH10nlnhrK4++uGob1WEs9Z3HaHxj4TsJy8pNcGjHlMcvdSCMvISHsMw0Tuu0Uc81EleGkPJgQCE6dVkzbOH8nwWVj3H1ldpEc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701795636; h=from:from:reply-to: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=Kkwko+lQEAYmw+jJjqxI2E61FLVP+4WfdUuG5Zici/A=; b=LMOaSdxof47Oy5Bv5A3ny8gHFuJaqAd4OB/roLZpcj+1CxNruaYwTcztrLm44Mw6K+maJj WH8+94x621G4+QB1MpzSu4KtRPTyyflG9mBQzLc7cpqi8V6+cu6V8wM9V84ZKLSc1zzOUP fIMUfQT+gEiHrAWt3Z4PiDWHJbnhQ/c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-FNlspc4JO_iQ_Loso7QU7Q-1; Tue, 05 Dec 2023 12:00:34 -0500 X-MC-Unique: FNlspc4JO_iQ_Loso7QU7Q-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E665848539 for <gcc-patches@gcc.gnu.org>; Tue, 5 Dec 2023 17:00:34 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 26577492BC6; Tue, 5 Dec 2023 17:00:34 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3B5H0Vf92959751 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Dec 2023 18:00:32 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B5H0V802959750; Tue, 5 Dec 2023 18:00:31 +0100 Date: Tue, 5 Dec 2023 18:00:31 +0100 From: Jakub Jelinek <jakub@redhat.com> To: Jason Merrill <jason@redhat.com>, Marek Polacek <polacek@redhat.com> Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, v2: Fix parsing [[]][[]]; Message-ID: <ZW9XL+ac5rY9XbF9@tucnak> References: <ZW7Wl3w5VO475hHc@tucnak> <ZW83jKY-YW4x6VV5@redhat.com> MIME-Version: 1.0 In-Reply-To: <ZW83jKY-YW4x6VV5@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 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=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784462092437262117 X-GMAIL-MSGID: 1784462092437262117 |
Series |
c++, v2: Fix parsing [[]][[]];
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Dec. 5, 2023, 5 p.m. UTC
On Tue, Dec 05, 2023 at 09:45:32AM -0500, Marek Polacek wrote: > > When working on the previous patch I put [[]] [[]] asm (""); into a > > testcase, but was surprised it wasn't parsed. > > By wasn't parsed you mean we gave an error, right? I only see an error > with block-scope [[]] [[]];. Yeah. The reason why [[]][[]]; works at namespace scope is that if else if (cp_lexer_nth_token_is (parser->lexer, cp_parser_skip_std_attribute_spec_seq (parser, 1), CPP_SEMICOLON)) which is the case here then even if after parsing the attributes next token isn't CPP_SEMICOLON (the case here without the patch), it will just return and another cp_parser_declaration will parse another [[]], that time also with CPP_SEMICOLON. > It seems marginally better to me to use void_list_node so that we don't > need a new parm, like what we do when parsing parameters: ()/(void)/(...), > but I should let others decide. Here is a modified version of the patch which does it like that. 2023-12-05 Jakub Jelinek <jakub@redhat.com> * parser.cc (cp_parser_std_attribute_spec): Return void_list_node rather than NULL_TREE if token is neither CPP_OPEN_SQUARE nor RID_ALIGNAS CPP_KEYWORD. (cp_parser_std_attribute_spec_seq): For attr_spec == void_list_node break, for attr_spec == NULL_TREE continue. * g++.dg/cpp0x/gen-attrs-79.C: New test. Jakub
Comments
On Tue, Dec 05, 2023 at 06:00:31PM +0100, Jakub Jelinek wrote: > On Tue, Dec 05, 2023 at 09:45:32AM -0500, Marek Polacek wrote: > > > When working on the previous patch I put [[]] [[]] asm (""); into a > > > testcase, but was surprised it wasn't parsed. > > > > By wasn't parsed you mean we gave an error, right? I only see an error > > with block-scope [[]] [[]];. > > Yeah. > The reason why [[]][[]]; works at namespace scope is that if > else if (cp_lexer_nth_token_is (parser->lexer, > cp_parser_skip_std_attribute_spec_seq (parser, > 1), > CPP_SEMICOLON)) > which is the case here then even if after parsing the attributes next token > isn't CPP_SEMICOLON (the case here without the patch), it will just return > and another cp_parser_declaration will parse another [[]], that time also > with CPP_SEMICOLON. > > > It seems marginally better to me to use void_list_node so that we don't > > need a new parm, like what we do when parsing parameters: ()/(void)/(...), > > but I should let others decide. > > Here is a modified version of the patch which does it like that. Thanks, this looks good to me. > 2023-12-05 Jakub Jelinek <jakub@redhat.com> > > * parser.cc (cp_parser_std_attribute_spec): Return void_list_node > rather than NULL_TREE if token is neither CPP_OPEN_SQUARE nor > RID_ALIGNAS CPP_KEYWORD. > (cp_parser_std_attribute_spec_seq): For attr_spec == void_list_node > break, for attr_spec == NULL_TREE continue. > > * g++.dg/cpp0x/gen-attrs-79.C: New test. > > --- gcc/cp/parser.cc.jj 2023-12-05 16:18:32.224909370 +0100 > +++ gcc/cp/parser.cc 2023-12-05 17:07:34.690170639 +0100 > @@ -30244,7 +30244,11 @@ void cp_parser_late_contract_condition ( > [ [ assert : contract-mode [opt] : conditional-expression ] ] > [ [ pre : contract-mode [opt] : conditional-expression ] ] > [ [ post : contract-mode [opt] identifier [opt] : > - conditional-expression ] ] */ > + conditional-expression ] ] > + > + Return void_list_node if the current token doesn't start an > + attribute-specifier to differentiate from NULL_TREE returned e.g. > + for [ [ ] ]. */ > > static tree > cp_parser_std_attribute_spec (cp_parser *parser) > @@ -30324,7 +30328,7 @@ cp_parser_std_attribute_spec (cp_parser > > if (token->type != CPP_KEYWORD > || token->keyword != RID_ALIGNAS) > - return NULL_TREE; > + return void_list_node; > > cp_lexer_consume_token (parser->lexer); > maybe_warn_cpp0x (CPP0X_ATTRIBUTES); > @@ -30397,8 +30401,12 @@ cp_parser_std_attribute_spec_seq (cp_par > while (true) > { > tree attr_spec = cp_parser_std_attribute_spec (parser); > - if (attr_spec == NULL_TREE) > + if (attr_spec == void_list_node) > break; > + /* Accept [[]][[]]; for which cp_parser_std_attribute_spec > + returns NULL_TREE as there are no attributes. */ > + if (attr_spec == NULL_TREE) > + continue; > if (attr_spec == error_mark_node) > return error_mark_node; > > --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-79.C.jj 2023-12-05 17:04:14.235988879 +0100 > +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-79.C 2023-12-05 17:04:14.235988879 +0100 > @@ -0,0 +1,9 @@ > +// { dg-do compile { target c++11 } } > + > +[[]] [[]]; > + > +[[]] [[]] void > +foo () > +{ > + [[]] [[]]; > +} Marek
On 12/5/23 12:17, Marek Polacek wrote: > On Tue, Dec 05, 2023 at 06:00:31PM +0100, Jakub Jelinek wrote: >> On Tue, Dec 05, 2023 at 09:45:32AM -0500, Marek Polacek wrote: >>>> When working on the previous patch I put [[]] [[]] asm (""); into a >>>> testcase, but was surprised it wasn't parsed. >>> >>> By wasn't parsed you mean we gave an error, right? I only see an error >>> with block-scope [[]] [[]];. >> >> Yeah. >> The reason why [[]][[]]; works at namespace scope is that if >> else if (cp_lexer_nth_token_is (parser->lexer, >> cp_parser_skip_std_attribute_spec_seq (parser, >> 1), >> CPP_SEMICOLON)) >> which is the case here then even if after parsing the attributes next token >> isn't CPP_SEMICOLON (the case here without the patch), it will just return >> and another cp_parser_declaration will parse another [[]], that time also >> with CPP_SEMICOLON. >> >>> It seems marginally better to me to use void_list_node so that we don't >>> need a new parm, like what we do when parsing parameters: ()/(void)/(...), >>> but I should let others decide. >> >> Here is a modified version of the patch which does it like that. > > Thanks, this looks good to me. Agreed, OK.
--- gcc/cp/parser.cc.jj 2023-12-05 16:18:32.224909370 +0100 +++ gcc/cp/parser.cc 2023-12-05 17:07:34.690170639 +0100 @@ -30244,7 +30244,11 @@ void cp_parser_late_contract_condition ( [ [ assert : contract-mode [opt] : conditional-expression ] ] [ [ pre : contract-mode [opt] : conditional-expression ] ] [ [ post : contract-mode [opt] identifier [opt] : - conditional-expression ] ] */ + conditional-expression ] ] + + Return void_list_node if the current token doesn't start an + attribute-specifier to differentiate from NULL_TREE returned e.g. + for [ [ ] ]. */ static tree cp_parser_std_attribute_spec (cp_parser *parser) @@ -30324,7 +30328,7 @@ cp_parser_std_attribute_spec (cp_parser if (token->type != CPP_KEYWORD || token->keyword != RID_ALIGNAS) - return NULL_TREE; + return void_list_node; cp_lexer_consume_token (parser->lexer); maybe_warn_cpp0x (CPP0X_ATTRIBUTES); @@ -30397,8 +30401,12 @@ cp_parser_std_attribute_spec_seq (cp_par while (true) { tree attr_spec = cp_parser_std_attribute_spec (parser); - if (attr_spec == NULL_TREE) + if (attr_spec == void_list_node) break; + /* Accept [[]][[]]; for which cp_parser_std_attribute_spec + returns NULL_TREE as there are no attributes. */ + if (attr_spec == NULL_TREE) + continue; if (attr_spec == error_mark_node) return error_mark_node; --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-79.C.jj 2023-12-05 17:04:14.235988879 +0100 +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-79.C 2023-12-05 17:04:14.235988879 +0100 @@ -0,0 +1,9 @@ +// { dg-do compile { target c++11 } } + +[[]] [[]]; + +[[]] [[]] void +foo () +{ + [[]] [[]]; +}