From patchwork Tue May 9 19:23:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 91724 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3117252vqo; Tue, 9 May 2023 12:24:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7zZkvZBgelCz0GY22s2d49FSxz+A6b27SH0omd4fFErDLCAn43k6Pzxm96kNPAumdxQQBS X-Received: by 2002:a17:907:6d8c:b0:94f:cee:56f2 with SMTP id sb12-20020a1709076d8c00b0094f0cee56f2mr14044048ejc.4.1683660249478; Tue, 09 May 2023 12:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683660249; cv=none; d=google.com; s=arc-20160816; b=mjBSSW3RWnrDc/+tjTMW0LjIh26fojXvq4zzc93DxE7qLbvURzRI638qAKNnWBZz84 2MltY7njLJgJld15FvOuWO/VyB3YgiF3VrTZ8OIzvv8aNl1VaapbhV1IF+DCEXp4L41y 4qyIMSmBUGSepORn01bneWeT79qZ4NrzkRe1Cvhqtz1/19IgK7CD9UvLmKcVYhCfNfx6 a0yC3KjaeYFvoGgEvxOJC+WQfJDlg6H14ld8uP2XoIerizmxNS47LuG3PYT7geKSzlZZ Pmd0B3l6+P+nOb08segBrOxppT5p1sIsOuJj3sETUyHlLJAaSCGxDZLwINqAOrjS3vl3 cXbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from: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:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=+X4X6Zl3evJEISaCKlq4dVk8Z4YLgGZkMTTwH7DVHmc=; b=0v57NoMJZRcBIxSP6xybKgBQVHp9hq6JwrEfGcLvgvgOAH0eQpeDxuCt45DWf3Ltvy ULkzgP4Wv9UtTD5ve9bDb3vhoFhmWT4w/0ZKfGjqeo0v3+tyisu0BznruhnuCwwoUdZn bZkCpOdqq8c8ecViV48Yl/vKBnVZXGrSewxFDzKPRKnIflyYOpoOdhPyjW9WH2KF8gD8 qUa4HrHnCMde+s46PD47qndXodkWETwdlPBCF4ROVasUa/wdDSg6bDZWJAGC/U1d0D7V cA6ZAKOLZ+NDYgj58AAQIyd3EkKVYxS4Plm+BwG8Xj9rScrJTq1THteWBGp3gZ2zAYfE aXqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CLbSt2sW; 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=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hb13-20020a170907160d00b0096597d94471si3081730ejc.830.2023.05.09.12.24.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 12:24:09 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=CLbSt2sW; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CAE913857023 for ; Tue, 9 May 2023 19:24:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAE913857023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683660243; bh=+X4X6Zl3evJEISaCKlq4dVk8Z4YLgGZkMTTwH7DVHmc=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=CLbSt2sWIL7Ydmrwmy0CDySMkd8dpBUaamNVMgoVeXp3CqWfyO5mioEvMb4yAjI4e ttyxEBJLBQrCCqxSZDWIYUSocf7IB3jhppZIZ6kJ2tMtqYYaMB4q9XYLN7+YkE+/NA AL1zkPirEyRSQujhJCci0HYXO1yAOSr/hVEmYnDI= 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 51E133857356 for ; Tue, 9 May 2023 19:23:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51E133857356 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-176-BCD_7z3yMV-fDaQVtha9VA-1; Tue, 09 May 2023 15:23:17 -0400 X-MC-Unique: BCD_7z3yMV-fDaQVtha9VA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 889103C0254E for ; Tue, 9 May 2023 19:23:17 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.156]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A83B2026D25; Tue, 9 May 2023 19:23:17 +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 349JN9TY1697068 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 9 May 2023 21:23:10 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 349JN9kd1697067; Tue, 9 May 2023 21:23:09 +0200 Date: Tue, 9 May 2023 21:23:09 +0200 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, v2: Reject attributes without arguments used as pack expansion [PR109756] Message-ID: References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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_H2, 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765445729558500833?= X-GMAIL-MSGID: =?utf-8?q?1765445729558500833?= On Tue, May 09, 2023 at 01:17:09PM -0400, Jason Merrill wrote: > How about changing cp_parser_std_attribute to set TREE_VALUE to > error_mark_node if it skips arguments? In limited testing that seems to work (tried GXX_TESTSUITE_STDS=98,11,14,17,20,2b make -j32 -k check-g++ RUNTESTFLAGS='dg.exp=*attr*' so far with it). Will bootstrap/regtest it tonight. Ok if it passes? 2023-05-09 Jakub Jelinek PR c++/109756 * parser.cc (cp_parser_std_attribute): For unknown attributes with arguments set TREE_VALUE (attribute) to error_mark_node after skipping the balanced tokens. (cp_parser_std_attribute_list): If ... is used after attribute without arguments, diagnose it and return error_mark_node. If TREE_VALUE (attribute) is error_mark_node, don't call make_pack_expansion nor return early error_mark_node. * g++.dg/cpp0x/gen-attrs-78.C: New test. Jakub --- gcc/cp/parser.cc.jj 2023-04-25 16:40:42.010723809 +0200 +++ gcc/cp/parser.cc 2023-05-09 20:22:42.025601924 +0200 @@ -29468,9 +29468,12 @@ cp_parser_std_attribute (cp_parser *pars } /* For unknown attributes, just skip balanced tokens instead of - trying to parse the arguments. */ + trying to parse the arguments. Set TREE_VALUE (attribute) to + error_mark_node to distinguish skipped arguments from attributes + with no arguments. */ for (size_t n = cp_parser_skip_balanced_tokens (parser, 1) - 1; n; --n) cp_lexer_consume_token (parser->lexer); + TREE_VALUE (attribute) = error_mark_node; return attribute; } @@ -29562,7 +29565,13 @@ cp_parser_std_attribute_list (cp_parser if (attribute == NULL_TREE) error_at (token->location, "expected attribute before %<...%>"); - else + else if (TREE_VALUE (attribute) == NULL_TREE) + { + error_at (token->location, "attribute with no arguments " + "contains no parameter packs"); + return error_mark_node; + } + else if (TREE_VALUE (attribute) != error_mark_node) { tree pack = make_pack_expansion (TREE_VALUE (attribute)); if (pack == error_mark_node) --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-78.C.jj 2023-05-08 12:33:13.387581760 +0200 +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-78.C 2023-05-08 12:32:23.146301128 +0200 @@ -0,0 +1,29 @@ +// PR c++/109756 +// { dg-do compile { target c++11 } } +// { dg-options "-Wno-attributes" } + +template +[[noreturn...]] // { dg-error "attribute with no arguments contains no parameter packs" } +[[deprecated...]] // { dg-error "attribute with no arguments contains no parameter packs" } +[[nodiscard...]] // { dg-error "attribute with no arguments contains no parameter packs" } +int foo (int x) +{ + switch (x) + { + case 1: + [[likely...]]; // { dg-error "attribute with no arguments contains no parameter packs" } + [[fallthrough...]]; // { dg-error "attribute with no arguments contains no parameter packs" } + case 2: + [[unlikely...]]; // { dg-error "attribute with no arguments contains no parameter packs" } + + break; + default: + break; + } + struct T {}; + struct S { [[no_unique_address...]] T t; }; // { dg-error "attribute with no arguments contains no parameter packs" } + for (;;) + ; +} + +int a = foo <1, 2, 3> (4);