From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 60821 invoked by alias); 11 Feb 2020 21:35:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 60813 invoked by uid 89); 11 Feb 2020 21:35:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 21:35:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581456935; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qhb7J3OHj3PKXIdUVpe8mwSsL7mKhQangdm4c6n6Ncc=; b=YIQDKRC2cIUuj3Jk6U6A9FRF3Wkn+20frantRLGDBvEzhK9aYt6qtQk6+vp9HxDBnqgr5l VwBtdu8ifOw6B0KrjM7oSX7+i96M4jThPOj1haiDqhP5q+z3ZUUxRJQxBAmOy3wTtVfIGh LHeMjwbXTb3iLMwNzMauyW/YjQmGhsk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-cL5kJJs7P3O7Xbx7wJmDVQ-1; Tue, 11 Feb 2020 16:35:30 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 79FD413EA for ; Tue, 11 Feb 2020 21:35:29 +0000 (UTC) Received: from pdp-11.bss.redhat.com (unknown [10.20.4.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D09D6E40A; Tue, 11 Feb 2020 21:35:28 +0000 (UTC) From: Marek Polacek To: Jason Merrill , GCC Patches Subject: [PATCH] c++: Fix ICE-on-invalid with broken attribute [PR93684] Date: Tue, 11 Feb 2020 21:35:00 -0000 Message-Id: <20200211213522.392020-1-polacek@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SW-Source: 2020-02/txt/msg00679.txt.bz2 We crash when parsing [[a:: because we see a CPP_SCOPE and then we're trying to consume a CPP_EOF token. So peek before consuming it. Bootstrapped/regtested on x86_64-linux, ok for trunk? PR c++/93684 - ICE-on-invalid with broken attribute. * parser.c (cp_parser_std_attribute): Peek a token first before consuming it. * g++.dg/parse/attr4.C: New test. --- gcc/cp/parser.c | 3 ++- gcc/testsuite/g++.dg/parse/attr4.C | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/parse/attr4.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 640affd8368..e8a536ae22f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -26720,7 +26720,7 @@ cp_parser_std_attribute (cp_parser *parser, tree at= tr_ns) "with scoped attribute token"); attr_ns =3D attr_id; =20 - token =3D cp_lexer_consume_token (parser->lexer); + token =3D cp_lexer_peek_token (parser->lexer); if (token->type =3D=3D CPP_NAME) attr_id =3D token->u.value; else if (token->type =3D=3D CPP_KEYWORD) @@ -26733,6 +26733,7 @@ cp_parser_std_attribute (cp_parser *parser, tree at= tr_ns) "expected an identifier for the attribute name"); return error_mark_node; } + cp_lexer_consume_token (parser->lexer); =20 attr_ns =3D canonicalize_attr_name (attr_ns); attr_id =3D canonicalize_attr_name (attr_id); diff --git a/gcc/testsuite/g++.dg/parse/attr4.C b/gcc/testsuite/g++.dg/pars= e/attr4.C new file mode 100644 index 00000000000..7713fc96c64 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/attr4.C @@ -0,0 +1,3 @@ +// PR c++/93684 - ICE-on-invalid with broken attribute. + +[[a:: // { dg-error "expected|expected" } base-commit: ad21e0072e20b7c8e4d7af5ca78f24cc6ae407d1 --=20 Marek Polacek =E2=80=A2 Red Hat, Inc. =E2=80=A2 300 A St, Boston, MA