From patchwork Wed Sep 21 21:18:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul-Antoine Arras X-Patchwork-Id: 57870 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 5E694385800E for ; Wed, 21 Sep 2022 21:19: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 8AE313858C52; Wed, 21 Sep 2022 21:18:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8AE313858C52 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,334,1654588800"; d="scan'208,223";a="86187587" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 21 Sep 2022 13:18:55 -0800 IronPort-SDR: YmC6lVfywhYhFJL7irIrjB2Vew++A6CGsSPqXG2gz0N985uHsnrA3ZGN4W2IMPmoKeg2WuVTFW BefMaYe6HZcuvEnb4y6HpYBjZT3FaXwICPdycp7BBCA9vGPSmnhPQgm5icV94Q/LRMydafbtFX +QV+bIjTxZLpT/a0wLy4U5Zi1bndU6bzqozzoKcwGfB1Ngs+Ba2OSpbMsuf6/cGTFIek+pm4Pr ZUxpHYPLY/D3XGP3BV7k60UN52N9GuJWsUk5maUF7/i02gac3wF4AkJzzoygp01l/+ekiuXGj8 C88= Message-ID: Date: Wed, 21 Sep 2022 23:18:50 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Content-Language: en-US To: , From: Paul-Antoine Arras Subject: [OG12][PATCH] OpenMP: Fix ICE with OMP metadirectives X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-07.mgc.mentorg.com (139.181.222.7) To svr-ies-mbx-13.mgc.mentorg.com (139.181.222.13) X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP 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-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" Hello, Here is a patch that fixes an ICE in gfortran triggered by an invalid end statement at the end of an OMP metadirective: ``` !$OMP metadirective ... ... !$OMP end ... ``` Does this fix look correct? Thanks, diff --git gcc/fortran/ChangeLog.omp gcc/fortran/ChangeLog.omp index 8c89cd5bd43..7b253608bf8 100644 --- gcc/fortran/ChangeLog.omp +++ gcc/fortran/ChangeLog.omp @@ -1,3 +1,8 @@ +2022-09-21 Paul-Antoine Arras + + * parse.cc (parse_omp_metadirective_body): Reject OMP end statements + at the end of an OMP metadirective. + 2022-09-09 Tobias Burnus Backport from mainline: diff --git gcc/fortran/parse.cc gcc/fortran/parse.cc index b35d76a4f6b..1f1fa0eba0e 100644 --- gcc/fortran/parse.cc +++ gcc/fortran/parse.cc @@ -5863,6 +5863,20 @@ parse_omp_metadirective_body (gfc_statement omp_st) break; } + if (gfc_state_stack->state == COMP_OMP_METADIRECTIVE + && startswith (gfc_ascii_statement (st), "!$OMP END ")) + { + for (gfc_state_data *p = gfc_state_stack; p; p = p->previous) + if (p->state == COMP_OMP_STRUCTURED_BLOCK) + goto finish; + gfc_error ( + "Unexpected %s statement in an OMP METADIRECTIVE block at %C", + gfc_ascii_statement (st)); + reject_statement (); + st = next_statement (); + } + finish: + gfc_in_metadirective_body = old_in_metadirective_body; if (gfc_state_stack->head) diff --git gcc/testsuite/ChangeLog.omp gcc/testsuite/ChangeLog.omp index e0c8c138620..f075354af4d 100644 --- gcc/testsuite/ChangeLog.omp +++ gcc/testsuite/ChangeLog.omp @@ -1,3 +1,7 @@ +2022-09-21 Paul-Antoine Arras + + * gfortran.dg/gomp/metadirective-9.f90: New test. + 2022-09-09 Paul-Antoine Arras Backport from mainline: diff --git gcc/testsuite/gfortran.dg/gomp/metadirective-9.f90 gcc/testsuite/gfortran.dg/gomp/metadirective-9.f90 new file mode 100644 index 00000000000..4db37dd0ef9 --- /dev/null +++ gcc/testsuite/gfortran.dg/gomp/metadirective-9.f90 @@ -0,0 +1,29 @@ +! { dg-do compile } + +program OpenMP_Metadirective_WrongEnd_Test + + integer :: & + iV, jV, kV + integer, dimension ( 3 ) :: & + lV, uV + logical :: & + UseDevice + + !$OMP metadirective & + !$OMP when ( user = { condition ( UseDevice ) } & + !$OMP : target teams distribute parallel do simd collapse ( 3 ) & + !$OMP private ( iaVS ) ) & + !$OMP default ( parallel do simd collapse ( 3 ) private ( iaVS ) ) + do kV = lV ( 3 ), uV ( 3 ) + do jV = lV ( 2 ), uV ( 2 ) + do iV = lV ( 1 ), uV ( 1 ) + + + end do + end do + end do + !$OMP end target teams distribute parallel do simd ! { dg-error "Unexpected !.OMP END TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD statement in an OMP METADIRECTIVE block at .1." } + + +end program +