From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1647) id 9A3D93858D32; Sun, 29 Jan 2023 20:57:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A3D93858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675025860; bh=KBXJ0icTx7E0Q+IlEEI5MxeLRq6o1Vv2LyXHLe3IvtU=; h=From:To:Subject:Date:From; b=CHAjM3bRcmL+lhk3ZzJxTrkh06z5zVK2zbWlWbi97SxqNWJ9lYTgBrrv+cUgIuOSo iU/iMMKclcz199gsKgaH4F8SAWIw2Iezt6XHj02FkKRyo74mu8XRUGhqteRJXmDb2z /NZmDGFy4txfKc5h82rh6CUASZoq9453pl9QRMRI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Mikael Morin To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5486] fortran: Set name for *LOC default BACK argument [PR108450] X-Act-Checkin: gcc X-Git-Author: Mikael Morin X-Git-Refname: refs/heads/master X-Git-Oldrev: 8011fbba7baa46947341ca8069b5a327163a68d5 X-Git-Newrev: 2e32a12c04c72f692a7bd119fd3e4e5b74392c9d Message-Id: <20230129205740.9A3D93858D32@sourceware.org> Date: Sun, 29 Jan 2023 20:57:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2e32a12c04c72f692a7bd119fd3e4e5b74392c9d commit r13-5486-g2e32a12c04c72f692a7bd119fd3e4e5b74392c9d Author: Mikael Morin Date: Sun Jan 29 21:57:24 2023 +0100 fortran: Set name for *LOC default BACK argument [PR108450] This change fixes an ICE caused by the double resolution of MINLOC, MAXLOC and FINDLOC expressions which get a default value for the BACK argument at resolution time. That argument is added without name, and argument reordering code is not prepared to handle unnamed arguments coming after named ones, so the second resolution causes a NULL pointer dereference. The problem is fixed by explicitly setting the argument name. PR fortran/108450 gcc/fortran/ChangeLog: * check.cc (gfc_check_minloc_maxloc): Explicitly set argument name. (gfc_check_findloc): Ditto. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/minmaxloc_1.f90: New test. Diff: --- gcc/fortran/check.cc | 2 ++ gcc/testsuite/gfortran.dg/gomp/minmaxloc_1.f90 | 32 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc index ebcb8f39852..8c1ae8c2f00 100644 --- a/gcc/fortran/check.cc +++ b/gcc/fortran/check.cc @@ -3888,6 +3888,7 @@ gfc_check_minloc_maxloc (gfc_actual_arglist *ap) { b = gfc_get_logical_expr (gfc_logical_4_kind, NULL, 0); ap->next->next->next->next->expr = b; + ap->next->next->next->next->name = gfc_get_string ("back"); } if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL @@ -3969,6 +3970,7 @@ gfc_check_findloc (gfc_actual_arglist *ap) { b = gfc_get_logical_expr (gfc_logical_4_kind, NULL, 0); ap->next->next->next->next->next->expr = b; + ap->next->next->next->next->next->name = gfc_get_string ("back"); } if (m == NULL && d != NULL && d->ts.type == BT_LOGICAL diff --git a/gcc/testsuite/gfortran.dg/gomp/minmaxloc_1.f90 b/gcc/testsuite/gfortran.dg/gomp/minmaxloc_1.f90 new file mode 100644 index 00000000000..b3691f774de --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/minmaxloc_1.f90 @@ -0,0 +1,32 @@ +! { dg-do compile } +! +! PR fortran/108450 +! This program used to cause an ICE because of the double resolution +! of the maxloc expression and the addition of a hidden unnamed argument +! during the first resolution. +! +! Original testcase from G. Steinmetz + +subroutine s1 + integer :: a(8) = 0 + integer :: l + integer :: n + !$omp atomic + n = maxloc(a, mask=l) ! { dg-error ".mask. argument of .maxloc. intrinsic at .1. must be LOGICAL" } +end + +subroutine s2 + integer :: a(8) = 0 + integer :: l + integer :: n + !$omp atomic + n = minloc(a, mask=l) ! { dg-error ".mask. argument of .minloc. intrinsic at .1. must be LOGICAL" } +end + +subroutine s3 + integer :: a(8) = 0 + integer :: l + integer :: n + !$omp atomic + n = findloc(a, 3, mask=l) ! { dg-error ".mask. argument of .findloc. intrinsic at .1. must be LOGICAL" } +end