* [PATCH, committed] Fortran: fix checking of arguments to UNPACK when MASK is a variable [PR105813]
@ 2022-06-24 20:38 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-06-24 20:38 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 290 bytes --]
Dear all,
we failed to fully check arguments to UNPACK when the MASK
argument was not simplified and considered a variable instead
of an array. The fix is a one-liner.
Regtested on x86_64-pc-linux-gnu and committed to mainline
as obvious after an OK by Steve in the PR.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr105813.diff --]
[-- Type: text/x-patch, Size: 1972 bytes --]
From f21f17f95c0237f4f987a5fa9f1fa9c7e0db3c40 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Fri, 24 Jun 2022 22:21:39 +0200
Subject: [PATCH] Fortran: fix checking of arguments to UNPACK when MASK is a
variable [PR105813]
gcc/fortran/ChangeLog:
PR fortran/105813
* check.cc (gfc_check_unpack): Try to simplify MASK argument to
UNPACK so that checking of the VECTOR argument can work when MASK
is a variable.
gcc/testsuite/ChangeLog:
PR fortran/105813
* gfortran.dg/unpack_vector_1.f90: New test.
---
gcc/fortran/check.cc | 2 ++
gcc/testsuite/gfortran.dg/unpack_vector_1.f90 | 12 ++++++++++++
2 files changed, 14 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/unpack_vector_1.f90
diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc
index 0c2cb50c6a7..91d87a1b2c1 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -6353,6 +6353,8 @@ gfc_check_unpack (gfc_expr *vector, gfc_expr *mask, gfc_expr *field)
if (!same_type_check (vector, 0, field, 2))
return false;
+ gfc_simplify_expr (mask, 0);
+
if (mask->expr_type == EXPR_ARRAY
&& gfc_array_size (vector, &vector_size))
{
diff --git a/gcc/testsuite/gfortran.dg/unpack_vector_1.f90 b/gcc/testsuite/gfortran.dg/unpack_vector_1.f90
new file mode 100644
index 00000000000..5347c111e8f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/unpack_vector_1.f90
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! PR fortran/105813
+! Fix checking of VECTOR argument to UNPACK when MASK is a variable.
+! Contributed by G.Steinmetz
+
+program p
+ logical, parameter :: mask(2,2) = reshape ([.true., .true., &
+ .false., .true.], &
+ shape (mask))
+ print *, unpack ([1,2,3], mask, 0) ! OK
+ print *, unpack ([1,2], mask, 0) ! { dg-error "must provide at least" }
+end
--
2.35.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-24 20:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24 20:38 [PATCH, committed] Fortran: fix checking of arguments to UNPACK when MASK is a variable [PR105813] Harald Anlauf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).