From patchwork Sat Feb 26 23:55:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 51407 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2DC003858001 for ; Sat, 26 Feb 2022 23:55:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 1874C3858D28 for ; Sat, 26 Feb 2022 23:55:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1874C3858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JQzjEzCWO83mpg7tCfgW541Ph2X4UO1F4Yr5Jl0OmrY=; b=Dem1AdNyWNwrtM7MjDkoE5FBgl WCfsC+dRid+xjSQUn7gE/lfIbuNu19dvQXz3PKfsHefjEVQ146lwzAeZ9+dKY1RrsO72PdQA2hBtN mx1Uqbw9drDQIB57lGO11eYRoVpssiAEZGos8uuZZhv1QVyY1Gsw7GRY100VeTSw25lcazWIPL6cN pS6qZXz1v5nV7WW1m6NpC98VijHNKHCXsDNCXzMaSmGe21e8f3qtSxNEkwlLbBFA6MshuDK55Xo/9 glNm/YLlihzUrdqIn9S7CoJfpjDmKXflDQ56JnTJdmjW5U6Lw7gfNY4AdkJFN6WKDvYAT+JxRXQbq iSTSPFig==; Received: from host86-186-213-42.range86-186.btcentralplus.com ([86.186.213.42]:57447 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nO6u8-0005ot-Gb for gcc-patches@gcc.gnu.org; Sat, 26 Feb 2022 18:55:12 -0500 From: "Roger Sayle" To: Subject: [PATCH] PR c++/39751: ICE-on-invalid parsing regression. Date: Sat, 26 Feb 2022 23:55:10 -0000 Message-ID: <002b01d82b6c$4adcdb40$e09691c0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adgra46gcllyu2dASu+21tpuiM9B2g== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FROM_FMBLA_NEWDOM, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This is a fix for PR c++/39751 which is an ICE-on-invalid regression in the C++ parser after encountering the end of file. The one line change is to check that the tokens cached in DECL_PENDING_INLINE_INFO haven't been purged before processing them in cp_parser_late_parsing_for_member. Alas in addition to the one line fix (and new test case), I've also taken the opportunity to silence the -Wmissing-field-initializers warnings compiling this source file, by replacing the " = { };" with explicit calls to memset to initialize/reset structures. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check with no new (unexpected) failures. Ok for mainline? 2022-02-26 Roger Sayle gcc/cp/ChangeLog PR c++/39751 * parser.cc (cp_parser_late_parsing_for_member): Confirm the token stream hasn't been purged before processing DECL_PENDING_INLINE. (cp_parser_handle_statement_omp_attributes): Silence compilation warnings using memset to initialize structure. (cp_parser_late_parsing_omp_declare_simd): Likewise. gcc/testsuite/ChangeLog PR c++/39751 * g++.dg/pr39751.C: New test case. Thanks in advance, Roger diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 03d99ab..585502b 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -11935,7 +11935,8 @@ cp_parser_handle_statement_omp_attributes (cp_parser *parser, tree attrs) if (flag_openmp || dir->simd) tokens += (last - first) + 1; } - cp_omp_attribute_data v = {}; + cp_omp_attribute_data v; + memset (&v, 0, sizeof (v)); vec.safe_push (v); *pa = TREE_CHAIN (*pa); } @@ -12021,7 +12022,8 @@ cp_parser_handle_statement_omp_attributes (cp_parser *parser, tree attrs) continue; cp_token *first = v->tokens->first; cp_token *last = v->tokens->last; - cp_token tok = {}; + cp_token tok; + memset (&tok, 0, sizeof (tok)); tok.type = CPP_PRAGMA; tok.keyword = RID_MAX; tok.u.value = build_int_cst (NULL, v->dir->id); @@ -12029,13 +12031,14 @@ cp_parser_handle_statement_omp_attributes (cp_parser *parser, tree attrs) lexer->buffer->quick_push (tok); while (++first < last) lexer->buffer->quick_push (*first); - tok = {}; + memset (&tok, 0, sizeof (tok)); tok.type = CPP_PRAGMA_EOL; tok.keyword = RID_MAX; tok.location = last->location; lexer->buffer->quick_push (tok); } - cp_token tok = {}; + cp_token tok; + memset (&tok, 0, sizeof (tok)); tok.type = CPP_EOF; tok.keyword = RID_MAX; tok.location = lexer->buffer->last ().location; @@ -32126,8 +32129,9 @@ cp_parser_late_parsing_for_member (cp_parser* parser, tree member_function) maybe_begin_member_template_processing (member_function); /* If the body of the function has not yet been parsed, parse it - now. */ - if (DECL_PENDING_INLINE_P (member_function)) + now. Except if the tokens have been purged (PR c++/39751). */ + if (DECL_PENDING_INLINE_P (member_function) + && !DECL_PENDING_INLINE_INFO (member_function)->first->purged_p) { tree function_scope; cp_token_cache *tokens; @@ -45693,7 +45697,8 @@ cp_parser_late_parsing_omp_declare_simd (cp_parser *parser, tree attrs) lexer->debugging_p = parser->lexer->debugging_p; } vec_safe_reserve (lexer->buffer, (last - first) + 2); - cp_token tok = {}; + cp_token tok; + memset (&tok, 0, sizeof (tok)); tok.type = CPP_PRAGMA; tok.keyword = RID_MAX; tok.u.value = build_int_cst (NULL, PRAGMA_OMP_DECLARE); @@ -45701,12 +45706,12 @@ cp_parser_late_parsing_omp_declare_simd (cp_parser *parser, tree attrs) lexer->buffer->quick_push (tok); while (++first < last) lexer->buffer->quick_push (*first); - tok = {}; + memset (&tok, 0, sizeof (tok)); tok.type = CPP_PRAGMA_EOL; tok.keyword = RID_MAX; tok.location = last->location; lexer->buffer->quick_push (tok); - tok = {}; + memset (&tok, 0, sizeof (tok)); tok.type = CPP_EOF; tok.keyword = RID_MAX; tok.location = last->location; diff --git a/gcc/testsuite/g++.dg/pr39751.C b/gcc/testsuite/g++.dg/pr39751.C new file mode 100644 index 0000000..91b09ac --- /dev/null +++ b/gcc/testsuite/g++.dg/pr39751.C @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +template < typename > +struct A +{ +A < struct +{ +f () : + +// { dg-excess-errors "" }