From patchwork Tue Dec 5 07:51:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 173775 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3271281vqy; Mon, 4 Dec 2023 23:52:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrxzJPEY/CRnEj92LS8FnM6fXXRE18zZrDRmjsaJ35n+atNyQsH7b7HKxL1zz2Frz1OrIV X-Received: by 2002:a25:aa67:0:b0:db7:d413:df4d with SMTP id s94-20020a25aa67000000b00db7d413df4dmr4729540ybi.59.1701762740851; Mon, 04 Dec 2023 23:52:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701762740; cv=pass; d=google.com; s=arc-20160816; b=MSL2JmERNLGAMXxhbIihkLzf0fO0euPP176TvJh3xEylM+x89dKPcAY1QPXqFlGagB 57qYA6ITye8+kfbCwTqK/67CkSOzlkuROyooiUeBguYXebvUG3P0sddMln5EzlDbmFzW PfcqjDF38c8XUVMUEthuWNkK3GkGr/8r0tdWBXO/mCeNX3JxSZV5T2xbDNgZdCaJR8oW Kg+MAtj4yKOPMoVGbW0JMkRM6/sZMgXHmS89p5VW8KDlwiZnFNgVQmvcooFWsDGa4Fdu Hh50cBnzcXZKb5ZQsyDhiCmtb4VcQwqBF24XsdTP+d9oBGRA3LQgCqJus0chZFLuvt4H BpQA== 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 :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=X7mldu29L+9udaXD7sfH0Ggsf7ewAtV8tFoTl5lVk2U=; fh=0xZT+NBKSeH8qOu04/61f1ZGePpF4jF/gxp331YE14k=; b=V9mZmY3vR1/jkbo71a+bxiVmXRUymbduFLNcbVus+g8XoFOg/+LRj+gfuzL4rVJWaD NzleBTwoOT8OtnrYBl3A2VIc4Sqlcoy4Vk2hesEOTwauLrXIt6ILgjbqhZ+mteAGtxTp QNwqcCWwK/qAF+sY+ETk6g4IwPJ9mnB5TVZq4S1H+FePFk1PTNxM/6+Br6lcpnzYABU2 tzti6wd7YthbKK+ELr1m4knEuI1g44BGxV8lTgmGOKRQmFg8mmAAQ9+oURg6FwP6tAxh 1bUDm4Bhq9ZwT6A+4EV5OIv2T1fd3XgmKvd/3Sa/pqZbuskm0aOx2+u1uc+WVYu3wj7H xeKg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Dfy845y5; 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 i6-20020ad44106000000b0067ab63e89fesi5943638qvp.348.2023.12.04.23.52.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:52:20 -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=Dfy845y5; 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 65521384CBBF for ; Tue, 5 Dec 2023 07:52:20 +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 950DD3858403 for ; Tue, 5 Dec 2023 07:51:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 950DD3858403 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 950DD3858403 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=1701762717; cv=none; b=P4PKisBtH7Ro8LPaPHkY+u0UNYJJ/OjbPGgNNSlo2HIC/XCrIzvBrn9TDw6lEZa9ih3gsbZqbkrkXd7FGNe5MtU+KgP69p2MUdu2tzl1pj5B9G7lrGMZWTFJXI4yHlkugLL+cWY864bJbzx4cwtrh4KN63ssEHXVzcoJY0KlE5w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701762717; c=relaxed/simple; bh=/Gc4t4zs102vfaRxqfSx2PFu98nCA4pw/6W1bLf8uVo=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=AZz46pcKGswiZDLZNa+xkPcmSUrNilknIHYECi/rOaesfKvI5OaH2FM6ojSUSMmsSaLYOzk7WohrjvDIl8wT8q0WHkUxUIoBklDsouHowDT7AaTrSyUfRwiBgJ6uMHzcdF7bS78he64GOir2cTqt51lNbm5osNCcfjg5qB8OhGI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701762716; 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; bh=X7mldu29L+9udaXD7sfH0Ggsf7ewAtV8tFoTl5lVk2U=; b=Dfy845y5TpC4yzkOUGZE69Xhbn8pMvTySSCTlQpUG3n1Cjpyr3BnsamtiMBxpfuqpYT6jQ fxGiouM5oUOnsXxirnF6V4TRenLz4gYHAGRyG1Uw0EpqNfdJioVWgP7t1uvpGJarYHBCGE F2NSrs5HOINZ+HX5QwFeMv1GvEJxPz4= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-500-m86DrJ6ZOoSUFKvCSmOAjw-1; Tue, 05 Dec 2023 02:51:54 -0500 X-MC-Unique: m86DrJ6ZOoSUFKvCSmOAjw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 5CDA638060EB for ; Tue, 5 Dec 2023 07:51:54 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 20839C15A0C; Tue, 5 Dec 2023 07:51:54 +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 3B57ppcG694121 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Dec 2023 08:51:52 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B57ppW1694120; Tue, 5 Dec 2023 08:51:51 +0100 Date: Tue, 5 Dec 2023 08:51:51 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix parsing [[]][[]]; Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784427568077817003 X-GMAIL-MSGID: 1784427568077817003 Hi! When working on the previous patch I put [[]] [[]] asm (""); into a testcase, but was surprised it wasn't parsed. The problem is that when cp_parser_std_attribute_spec returns NULL, it can mean 2 different things, one is that the next token(s) are neither [[ nor alignas (in that case the caller should break from the loop), or when we parsed something like [[]] - it was valid attribute specifier, but didn't specify any attributes in it. The following patch fixes that by adding another parameter to differentiate between the cases, guess another option would be to use some magic tree value for the break case instead of NULL_TREE (but error_mark_node is already taken and means something else). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Or shall I go with some magic return which will never happen otherwise? void_node? 2023-12-05 Jakub Jelinek * parser.cc (cp_parser_std_attribute_spec): Add ANY_P argument, set what it points to initially to true and only if token is neither CPP_OPEN_SQUARE nor RID_ALIGNAS CPP_KEYWORD set it to false. (cp_parser_std_attribute_spec_seq): Adjust cp_parser_std_attribute_spec caller. If it returns NULL_TREE and any_p is true, continue rather than break. * g++.dg/cpp0x/gen-attrs-79.C: New test. Jakub --- gcc/cp/parser.cc.jj 2023-12-04 20:23:53.225009856 +0100 +++ gcc/cp/parser.cc 2023-12-04 20:49:21.160426104 +0100 @@ -2703,7 +2703,7 @@ static tree cp_parser_gnu_attribute_list static tree cp_parser_std_attribute (cp_parser *, tree); static tree cp_parser_std_attribute_spec - (cp_parser *); + (cp_parser *, bool *); static tree cp_parser_std_attribute_spec_seq (cp_parser *); static size_t cp_parser_skip_std_attribute_spec_seq @@ -30265,11 +30265,12 @@ void cp_parser_late_contract_condition ( conditional-expression ] ] */ static tree -cp_parser_std_attribute_spec (cp_parser *parser) +cp_parser_std_attribute_spec (cp_parser *parser, bool *any_p) { tree attributes = NULL_TREE; cp_token *token = cp_lexer_peek_token (parser->lexer); + *any_p = true; if (token->type == CPP_OPEN_SQUARE && cp_lexer_peek_nth_token (parser->lexer, 2)->type == CPP_OPEN_SQUARE) { @@ -30342,7 +30343,10 @@ cp_parser_std_attribute_spec (cp_parser if (token->type != CPP_KEYWORD || token->keyword != RID_ALIGNAS) - return NULL_TREE; + { + *any_p = false; + return NULL_TREE; + } cp_lexer_consume_token (parser->lexer); maybe_warn_cpp0x (CPP0X_ATTRIBUTES); @@ -30414,9 +30418,16 @@ cp_parser_std_attribute_spec_seq (cp_par while (true) { - tree attr_spec = cp_parser_std_attribute_spec (parser); + bool any_p; + tree attr_spec = cp_parser_std_attribute_spec (parser, &any_p); if (attr_spec == NULL_TREE) - break; + { + /* Accept [[]][[]]; for which cp_parser_std_attribute_spec + also returns NULL_TREE as there are no attributes. */ + if (any_p) + continue; + break; + } if (attr_spec == error_mark_node) return error_mark_node; --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-79.C.jj 2023-12-04 20:38:35.122574430 +0100 +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-79.C 2023-12-04 20:38:29.468654143 +0100 @@ -0,0 +1,9 @@ +// { dg-do compile { target c++11 } } + +[[]] [[]]; + +[[]] [[]] void +foo () +{ + [[]] [[]]; +}