From patchwork Mon Feb 28 14:01:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kwok Cheung Yeung X-Patchwork-Id: 51447 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 302263857C47 for ; Mon, 28 Feb 2022 14:02:50 +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 A1F1A3858C83; Mon, 28 Feb 2022 14:02:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A1F1A3858C83 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.90,142,1643702400"; d="scan'208,223";a="75068294" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 28 Feb 2022 06:02:03 -0800 IronPort-SDR: N5F/5lvIjiVkHXmlfHoEVpmISoO5ZGVmUrrdKWswMqXMyMPc70WXK3QUGfcmlvF6bfbCkBozZf Mctwes89AlEgB2FgwpeYEQ38R/Y0jVseifXNG21DPKL7tGeSZai9x+v/a0VSJfHn6dcfkvQPH5 B8Ab5OFshvXeFVjnUdmLUPFUlHzMGArNZO0UmAfSdJRzbutpYOT732qCtZGW4l4PaePqgM0rDQ PsuW6gpNIcNHIMItdcI82Z8Mm03INM80CsPxnS8IjZlC3ZigLfXpGnI6qRQztHGMqBd74cH/DL ogE= Message-ID: Date: Mon, 28 Feb 2022 14:01:03 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 From: Kwok Cheung Yeung Subject: [PATCH] openmp, fortran: Check that event handles passed to detach clauses are not arrays [PR104131] To: gcc-patches , fortran , Jakub Jelinek , X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-07.mgc.mentorg.com (139.181.222.7) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, 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" Hello This patch addresses PR fortran/104131 on the GCC bug tracker, where an ICE would occur if an array or co-array was passed as the event handle in the detach clause of a task. Since the event handle is supposed to be a scalar of type omp_event_handle_kind, we can simply reject the event handle during parsing if it is any type of array, thereby preventing the situation leading to an ICE in the first place. Okay for trunk? Thanks Kwok From 8ed3b8bd793298f94bdefbdff32f91eaea1a9d70 Mon Sep 17 00:00:00 2001 From: Kwok Cheung Yeung Date: Mon, 28 Feb 2022 12:34:22 +0000 Subject: [PATCH] openmp, fortran: Check that event handles passed to detach clauses are not arrays [PR104131] 2022-02-28 Kwok Cheung Yeung gcc/fortran/ PR fortran/104131 * openmp.cc (gfc_match_omp_detach): Check that the event handle is not an array type. gcc/testsuite/ PR fortran/104131 * gfortran.dg/gomp/pr104131.f90: New. * gfortran.dg/gomp/pr104131-2.f90: New. * gfortran.dg/gomp/task-detach-1.f90: Update expected error message. --- gcc/fortran/openmp.cc | 5 +++-- gcc/testsuite/gfortran.dg/gomp/pr104131-2.f90 | 10 ++++++++++ gcc/testsuite/gfortran.dg/gomp/pr104131.f90 | 10 ++++++++++ gcc/testsuite/gfortran.dg/gomp/task-detach-1.f90 | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/gomp/pr104131-2.f90 create mode 100644 gcc/testsuite/gfortran.dg/gomp/pr104131.f90 diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index 19142c4d8d0..50a1c476009 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -531,9 +531,10 @@ gfc_match_omp_detach (gfc_expr **expr) if (gfc_match_variable (expr, 0) != MATCH_YES) goto syntax_error; - if ((*expr)->ts.type != BT_INTEGER || (*expr)->ts.kind != gfc_c_intptr_kind) + if ((*expr)->ts.type != BT_INTEGER || (*expr)->ts.kind != gfc_c_intptr_kind + || (*expr)->symtree->n.sym->as) { - gfc_error ("%qs at %L should be of type " + gfc_error ("%qs at %L should be a scalar of type " "integer(kind=omp_event_handle_kind)", (*expr)->symtree->n.sym->name, &(*expr)->where); return MATCH_ERROR; diff --git a/gcc/testsuite/gfortran.dg/gomp/pr104131-2.f90 b/gcc/testsuite/gfortran.dg/gomp/pr104131-2.f90 new file mode 100644 index 00000000000..8d10367ba3b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/pr104131-2.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! { dg-options "-fopenmp -fcoarray=single" } + +program p + use iso_c_binding, only: c_intptr_t + integer, parameter :: omp_event_handle_kind = c_intptr_t + integer (kind=omp_event_handle_kind) :: x[*] + !$omp task detach (x) ! { dg-error "'x' at \\\(1\\\) should be a scalar of type integer\\\(kind=omp_event_handle_kind\\\)" } + !$omp end task ! { dg-error "Unexpected !\\\$OMP END TASK statement at \\\(1\\\)" } +end diff --git a/gcc/testsuite/gfortran.dg/gomp/pr104131.f90 b/gcc/testsuite/gfortran.dg/gomp/pr104131.f90 new file mode 100644 index 00000000000..70a2dedfd7f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/pr104131.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! { dg-options "-fopenmp" } + +program p + use iso_c_binding, only: c_intptr_t + integer, parameter :: omp_event_handle_kind = c_intptr_t + integer(omp_event_handle_kind) :: x(1) + !$omp task detach(x) ! { dg-error "'x' at \\\(1\\\) should be a scalar of type integer\\\(kind=omp_event_handle_kind\\\)" } + !$omp end task ! { dg-error "Unexpected !\\\$OMP END TASK statement at \\\(1\\\)" } +end diff --git a/gcc/testsuite/gfortran.dg/gomp/task-detach-1.f90 b/gcc/testsuite/gfortran.dg/gomp/task-detach-1.f90 index 020be13a8b6..b73db07b7c3 100644 --- a/gcc/testsuite/gfortran.dg/gomp/task-detach-1.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/task-detach-1.f90 @@ -18,7 +18,7 @@ program task_detach_1 !$omp task detach(x) mergeable ! { dg-error "'DETACH' clause at \\\(1\\\) must not be used together with 'MERGEABLE' clause" } !$omp end task - !$omp task detach(z) ! { dg-error "'z' at \\\(1\\\) should be of type integer\\\(kind=omp_event_handle_kind\\\)" } + !$omp task detach(z) ! { dg-error "'z' at \\\(1\\\) should be a scalar of type integer\\\(kind=omp_event_handle_kind\\\)" } !$omp end task ! { dg-error "Unexpected !\\\$OMP END TASK statement at \\\(1\\\)" } !$omp task detach (x) firstprivate (x) ! { dg-error "DETACH event handle 'x' in FIRSTPRIVATE clause at \\\(1\\\)" }