From patchwork Tue Feb 11 21:35:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1236493 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519369-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=W123ietl; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=YIQDKRC2; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48HGKZ11q9z9sRY for ; Wed, 12 Feb 2020 08:35:45 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=m2w5dJB2eshmpsEk /m+WNfO29t18Q8pbv5ipPWY1jD6LmwOTp0akugQaecRZ25P5TBgKOpT3jzNn1hGN 91SHb4NgbFd9esYQlDr77ZkZlDLFKC8YtvgwrkmsJRAk+Bi2MgjGv2zsER9Sr5rU miwEnnjvDSxY53ddN7amcdDEp8A= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=6/CA+QKChHxp16rBbDkQqD nT+yc=; b=W123ietl3WvWC03pBYCZC1Ci0TJg96gQ12/SM7orLqMd2j1e5VPKNl oauuHwAS0EyyUB6VURAGvy/NVUYw2WRjPOsXxwsuX5zpJFJFvq0dcF/yJ2807Kxx GB3niLSamNqK5k5Il3nBfp4SSqz1AYHVAaGiD5fF3aokAUsxq3XXU= 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-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@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 16:35:22 -0500 Message-Id: <20200211213522.392020-1-polacek@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 base-commit: ad21e0072e20b7c8e4d7af5ca78f24cc6ae407d1 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 attr_ns) "with scoped attribute token"); attr_ns = attr_id; - token = cp_lexer_consume_token (parser->lexer); + token = cp_lexer_peek_token (parser->lexer); if (token->type == CPP_NAME) attr_id = token->u.value; else if (token->type == CPP_KEYWORD) @@ -26733,6 +26733,7 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns) "expected an identifier for the attribute name"); return error_mark_node; } + cp_lexer_consume_token (parser->lexer); attr_ns = canonicalize_attr_name (attr_ns); attr_id = canonicalize_attr_name (attr_id); diff --git a/gcc/testsuite/g++.dg/parse/attr4.C b/gcc/testsuite/g++.dg/parse/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" }