From patchwork Tue Jul 21 19:43:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1333314 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=pUt0aZUf; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BB8Ck3XdDz9sQt for ; Wed, 22 Jul 2020 05:43:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0E95E3861033; Tue, 21 Jul 2020 19:43:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by sourceware.org (Postfix) with ESMTPS id DF44A3857C45 for ; Tue, 21 Jul 2020 19:43:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DF44A3857C45 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qt1-x82b.google.com with SMTP id w9so56877qts.6 for ; Tue, 21 Jul 2020 12:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=CqyLvCCtniAaj9JNdXcMLAwxVfqz8DKElODh00P3mj0=; b=pUt0aZUfxTpK5x02BgSmhue7CogZqtVhGWvCHd3SPa64CRqP+LAw3WWPvotp4uiQ6E k/4PbpIkRUHcLiyGkXfUNRFu2RuKRdHUEcSivfGMb4tKAHgAokW+Sla68ucQuV/97+ul Iyw6k7SxKVt0QA0uqGGq/mw4F5YAQtQjU8O2mTjkJn5ys8gg10a4m0t3rAjvkg9+qhV0 WGPTO4MKEdnzYoyComCu+XCbAvjzmLVqZiK5Rkd2lsbWGfOQWdbboeYqsoRbTz60aO3m s48jRdhR0CKDiJnE1Fx+9SaamlYuvuOrJsTjpuPZReYsn8Mymz4SFSH0Ibv0HlX4SQ9W Ls0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=CqyLvCCtniAaj9JNdXcMLAwxVfqz8DKElODh00P3mj0=; b=KVSO6ENh8dT5Zanx6ZqyLZ8OuTgEpMBQueXUrodSBOAUlaz2/3V90TiEgcfnvDyq38 KBLVFyWwVaNL7IDxCtL0FvtCHd4M72wxlASyilY03uB+luj4o9azVEBHuODsVn6bkCQd PuXxV6oFPqyUQwVcqni18ZTAQepbzO+jGGo9Uj0HbGZtLpJlpFPOg6R2XnecfcT3Ru/7 2SZP1Y6wIxE60QRn2mR3KMHfR/pX0PjOTXnGkvz9/56eBiZaoehGuAL5iplC6Ezzqoq3 T0tBQUE9/TACyg37JI/rJnZPfyV0J4Nf6Igpfq3oNGDDj3JH6q7C4rCzONd+UfndCSfY X5vw== X-Gm-Message-State: AOAM531TzvRbHKuz+N6yi0Nq/8VuhGX/M+NhJBbtrX9nOAghYqBfnj1v tY4ETGSoHUsh/mHOJzP02dU= X-Google-Smtp-Source: ABdhPJzclqM/KYQAC8CLxWKOFJe7qD1jPE7NdOWiIwRipDq20TWWtY5Oq5os3j7cC7YIlGVFkDKCuw== X-Received: by 2002:ac8:35d8:: with SMTP id l24mr31468860qtb.300.1595360605269; Tue, 21 Jul 2020 12:43:25 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:d1b7:d770:d6c0:283c? ([2620:10d:c091:480::1:d201]) by smtp.googlemail.com with ESMTPSA id j9sm23475871qtr.60.2020.07.21.12.43.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Jul 2020 12:43:24 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: Fix scan forward over pragma [PR96257] Message-ID: <7a9c3b23-9af2-20a1-93f5-097ac06674f1@acm.org> Date: Tue, 21 Jul 2020 15:43:23 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" It turns out that the paren scanning code is used for speculatively searching to see if we're looking at a compound_literal. So we shouldn't always purge pragma tokens. gcc/cp/ * parser.c (cp_lexer_consume_token): Drop PRAGMA_EOL assert. (cp_parser_skip_to_closing_parenthesis_1): Only pass start token to pragma skipper if recovering. (cp_parser_skip_to_pragma_eol): Only purge and change pragma state when recovering. gcc/testsuite/ * g++.dg/parse/pr96257.C: New. pushed diff --git c/gcc/cp/parser.c w/gcc/cp/parser.c index 11db02418bc..5a2d73d1ab0 100644 --- c/gcc/cp/parser.c +++ w/gcc/cp/parser.c @@ -1121,8 +1121,6 @@ cp_lexer_consume_token (cp_lexer* lexer) { cp_token *token = lexer->next_token; - gcc_assert (!lexer->in_pragma || token->type != CPP_PRAGMA_EOL); - do { gcc_assert (token->type != CPP_EOF); @@ -3691,7 +3689,7 @@ cp_parser_skip_to_closing_parenthesis_1 (cp_parser *parser, case CPP_PRAGMA: /* We fell into a pragma. Skip it, and continue. */ - cp_parser_skip_to_pragma_eol (parser, token); + cp_parser_skip_to_pragma_eol (parser, recovering ? token : nullptr); continue; default: @@ -3930,15 +3928,14 @@ cp_parser_skip_to_closing_brace (cp_parser *parser) /* Consume tokens until we reach the end of the pragma. The PRAGMA_TOK parameter is the PRAGMA token, allowing us to purge the entire pragma - sequence. */ + sequence. PRAGMA_TOK can be NULL, if we're speculatively scanning + forwards (not error recovery). */ static void cp_parser_skip_to_pragma_eol (cp_parser* parser, cp_token *pragma_tok) { cp_token *token; - parser->lexer->in_pragma = false; - do { /* The preprocessor makes sure that a PRAGMA_EOL token appears @@ -3950,8 +3947,12 @@ cp_parser_skip_to_pragma_eol (cp_parser* parser, cp_token *pragma_tok) } while (token->type != CPP_PRAGMA_EOL); - /* Ensure that the pragma is not parsed again. */ - cp_lexer_purge_tokens_after (parser->lexer, pragma_tok); + if (pragma_tok) + { + /* Ensure that the pragma is not parsed again. */ + cp_lexer_purge_tokens_after (parser->lexer, pragma_tok); + parser->lexer->in_pragma = false; + } } /* Require pragma end of line, resyncing with it as necessary. The diff --git c/gcc/testsuite/g++.dg/parse/pr96257.C w/gcc/testsuite/g++.dg/parse/pr96257.C new file mode 100644 index 00000000000..34b0208c5d7 --- /dev/null +++ w/gcc/testsuite/g++.dg/parse/pr96257.C @@ -0,0 +1,18 @@ +// PR96257 we scan forwards checking for a compound literal. Do not +// eat the tokens when doing that! +/* { dg-require-effective-target fopenmp } */ +/* { dg-additional-options -fopenmp } */ + +int +f2 () +{ + int s = (int // { dg-error "expected" } +#pragma omp atomic capture + ){1}; + + int t = (int // { dg-error "expected" } +#pragma omp atomic capture ){ + {1}; + + return s + t; +} // { dg-bogus "expected" }