From patchwork Wed Aug 24 17:47:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 740 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1534992wro; Wed, 24 Aug 2022 10:48:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR61v6T43MOQvxqNdC0MLIHCZGJ6wjcum/0gL001t14vUgCEX7ruYfXst8x7j6oF7V1Kq0X7 X-Received: by 2002:a17:906:9b87:b0:733:1795:2855 with SMTP id dd7-20020a1709069b8700b0073317952855mr75653ejc.156.1661363316940; Wed, 24 Aug 2022 10:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661363316; cv=none; d=google.com; s=arc-20160816; b=uLUVsNShglW8N0q+GSkLnUzSFAaX9qgz7CrNs8CUxDlKshGcy+ddFm3fMggpGNAPF1 C3sM+UXexnMsL2XDhMYjSlI5GHqQ7mhWnrvZlI7IejHzPab0il05i6BZX9Nnj/0XdXdx TBqXiWuyn3KFHAkCrCJwNk+DNPrsBaN1b/MHBIJ3Lg0dN84zH7XA5rHtaeLXOUSU+VtY 9DP9t/pbVkL6WrXJ/4oW/ZJDp6ataktnGwq/S1f2WLeBVXp2qMaAR59RwJTfIkzEBWud 4uTP79icYBnHcV+T/ZOKB+RAYCAcg9DVVXi5x/8mgd2xKhNVZZCnxQwK0evalq+PycqW GR+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:from:to :content-language:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=Ac7uvAGcC6yZ0Z3XCC4tFhMlFbxdf2kUjYrTDjACXOk=; b=gucR3T8mvrJmu5gX85PRGRedT1d1yLFTCRPRLJs6qTfzHBnfG1NlM658QuPUlxkGH1 JNl5qQbXf63lVHZK1NWvI+HIzeqNDUf7lbrzTYeKxoifJHgCsTVgWIRxUC9fNDsjD/Qc cuLyAnu6Ier0UgaSnwBP5rA24ct6uZH5SOIUvJKUTR6HsO0/5TQpx3Y3FjO1YnORmUjq RjOjhDl5k9O6BtorhpXSgovDb95YNmuFCYG0UbZqV2pQYx3rziGkdeYiK47PQEsMv13M +nFF6IzmTiwI7RdXKlHHN23NFKU7H9OVhIUpj2PRZuWqb2hnJOBMRgN23lGLJOQGkTHs A5tw== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d4-20020a50f684000000b0043d356e02fbsi4559332edn.527.2022.08.24.10.48.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 10:48:36 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E0926385041B for ; Wed, 24 Aug 2022 17:48:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id ED280385115E; Wed, 24 Aug 2022 17:47:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ED280385115E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.93,261,1654588800"; d="diff'?scan'208,217";a="84634396" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 24 Aug 2022 09:47:55 -0800 IronPort-SDR: LDLpa9Ba8vWPI1Wp0NQ9DlfcN02fA94ktByzAFyeo76JxUBDV0ziJDI6UnOe4X9yD6Mm42PQiM Vng741iMRi8tIPgKUxkM3/CRKJGAIkNnH1lHgKJhPPEHnOwzyPKQQXtCSM1daFHSw13ss4QxTn GMOB9Lf13dTCud5Oa0kKlWb5w5fZdCZ0aR/g6UaouL76306IXMclEc4bA3MEwrBOqV4yOZHmMO dZhMM5+i5Ckf5o2lZF349Iz3gcvEvVTDFriJMlvGvf61RrK1BZopEOlMSukN0OCUyK+r3rbpjx A+s= Message-ID: Date: Wed, 24 Aug 2022 19:47:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.1.2 Content-Language: en-US To: gcc-patches , fortran , Jakub Jelinek From: Tobias Burnus Subject: [Patch] Fortran/OpenMP: Fix strictly structured blocks parsing X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-09.mgc.mentorg.com (139.181.222.9) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, 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-Content-Filtered-By: Mailman/MimeDel 2.1.29 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742065701495308415?= X-GMAIL-MSGID: =?utf-8?q?1742065701495308415?= This patch is about error diagnostic + an ICE for invalid code. Before the patch, gfortran/f951 showed: ... Error: 'ancestor' device modifier not preceded by 'requires' directive with 'reverse_offload' clause 18 | end block | 1 Error: Expecting END PROGRAM statement at (1) gfortran: internal compiler error: Segmentation fault signal terminated program f951 * The first error is for a user error and fine. * A follow-up error is expected (due to the now dangling '!$omp end target'), but the error location and wording is misleading * And the ICE is plainly wrong. With the patch, there is no ICE and the the second error reads: 16 | !$omp end target Error: Unexpected !$OMP END TARGET statement at (1) The problem was due to nesting '!$omp target' (= same directive), where the outer one was a strictly structured block - and parsing the inner '!$omp target' failed with MATCH_ERROR, which ignored that line - while '!$omp end target' remained. (So far, so good, but then the parsing-code did run into a bug.) For the blocks, the following applies. OpenMP permits either * strictly structured blocks (with optional END_ST == 'end target') !$omp target block ... end block !$omp end target ! << this line is optional * loosely structured block !$omp target ... ! may not start with 'block' (and hence cannot end with 'end block') !$omp end target ! << required The parsing issue is in the following code, which first takes care of the 'strictly': 'end block' + optional 'end target' and then of the 'loosely structured' case with just: 'end target': else if (block_construct && st == ST_END_BLOCK) ... st = next_statement (); if (st == omp_end_st) accept_statement (st); ... else if (st != omp_end_st) { unexpected_statement (st); st = next_statement (); } The fix is to change the second if condition to: else if (st != omp_end_st || (block_construct && st == omp_end_st)) or rather to the following equivalent code: else if (st != omp_end_st || block_construct) OK for mainline and GCC 12?* Tobias *strictly structured blocks were added in r12-4592. ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 Fortran/OpenMP: Fix strictly structured blocks parsing gcc/fortran/ChangeLog: * parse.cc (parse_omp_structured_block): When parsin strictly structured blocks, issue an error if the end-directive comes before the 'end block'. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/strictly-structured-block-4.f90: New test. gcc/fortran/parse.cc | 2 +- .../gomp/strictly-structured-block-4.f90 | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc index 0b4c596996c..80492c952aa 100644 --- a/gcc/fortran/parse.cc +++ b/gcc/fortran/parse.cc @@ -5709,7 +5709,7 @@ parse_omp_structured_block (gfc_statement omp_st, bool workshare_stmts_only) } return st; } - else if (st != omp_end_st) + else if (st != omp_end_st || block_construct) { unexpected_statement (st); st = next_statement (); diff --git a/gcc/testsuite/gfortran.dg/gomp/strictly-structured-block-4.f90 b/gcc/testsuite/gfortran.dg/gomp/strictly-structured-block-4.f90 new file mode 100644 index 00000000000..66cf0a3925e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/strictly-structured-block-4.f90 @@ -0,0 +1,21 @@ +! { dg-do compile } +implicit none +integer ::x,z +x = 42 +print '(*(z16:" "))', loc(x) +!$omp target map(x, z) +block + integer :: y + x = 123 + y = 99 + !$omp target device(ancestor:1) map(always,tofrom:x) map(y) ! { dg-error "'ancestor' device modifier not preceded by 'requires' directive with 'reverse_offload' clause" } + print '(*(z16:" "))', loc(x), loc(y) + print * ,x, y + x = -x + y = -y + !$omp end target ! { dg-error "Unexpected ..OMP END TARGET statement" } + z = y +end block + print * ,x !, z +end +