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: 1350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2302:b0:79:6ae5:3758 with SMTP id gv2csp45780dyb; Wed, 21 Sep 2022 14:19:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM48pVvw5F9U5aWQ53/oCs4G7QcLUSy864Eky+9q4wKYePByJQg1BJ+bWDupZSrOOxJ0jvlt X-Received: by 2002:a05:6402:27ca:b0:451:7b58:1b01 with SMTP id c10-20020a05640227ca00b004517b581b01mr63000ede.61.1663795183519; Wed, 21 Sep 2022 14:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663795183; cv=none; d=google.com; s=arc-20160816; b=WNwFf+A7juCTWkb4HHI1Au7rK4dWLmdSqqVs9OIzCjKLTnwgaimviG/+ZFXjA4fFpY hB1f4bcVFEJ1mg1iqRPSWg2g/aYj67Ve88JoFkwkdsuQADhnDSy2d5BJDQo2x6fYJlC4 0oYDaRIkpoFXP9/zWVb1Mt/FKn7ugTfDVGbfLc005mdlkIzosappujmgvEDjJjUqg8qj ppXjj8CBNeCafAiRPG1f34SZWjoe4jw2rZp13UWzhcH7beRlfGhZwidH4ONDEEmK6gX0 +cy8zFhVKLbl5FqqHAxxkohB3IdhcrIYTyixCbpCW6M5210BZQqyTiSwM6z2EE8Pj52K 6llw== 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=iSnl67Xly3s4TolKJewmrDoUFLvWvTsBSO3VNt0o8PU=; b=yTWYtBdBm+K9U5PgwaTYWmAM3rlMv+97Pz9eGdCEh3u/HqdyF27R6uwvHFmSTPnLYi nSJFOA5D6hkwbwcJk4TNYZ0XKFLFxRtftCAEvyTIirfjsYSTzJIV6umjXdsDQUSpYVdN IWgymTNRJt78rIoyVic+zJG+S8fUvxnb/OUBdV58ZX+G749TLRUDaO8B8tQPbyeolVTY aJns1xODh691FKqXbgcTLJ5+Klw3TbC8IkGkcmmClVcSQkAdxSQ4kQLM1GPbeesoeENv vnIhHZC1Gzvx5H+iw0TRq8BUWZLFVXX8zrSp0dYELKeRvLsa+5+A7QAK87+3lfYOmbM7 vcdg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g15-20020a50d0cf000000b004537a3c4982si2846207edf.601.2022.09.21.14.19.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 14:19:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 A6575385801D for ; Wed, 21 Sep 2022 21:19:28 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744615698173784703?= X-GMAIL-MSGID: =?utf-8?q?1744615698173784703?= 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 +