]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix checking of arguments to UNPACK when MASK is a variable [PR105813]
authorHarald Anlauf <anlauf@gmx.de>
Fri, 24 Jun 2022 20:21:39 +0000 (22:21 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 1 Jul 2022 17:10:47 +0000 (19:10 +0200)
gcc/fortran/ChangeLog:

PR fortran/105813
* check.c (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.

(cherry picked from commit f21f17f95c0237f4f987a5fa9f1fa9c7e0db3c40)

gcc/fortran/check.c
gcc/testsuite/gfortran.dg/unpack_vector_1.f90 [new file with mode: 0644]

index 44e2da65a4c984fd3d676f02f67d7dba0657536e..488c9aff94b5431f27a3447a9f6f5ac059c2450c 100644 (file)
@@ -6329,6 +6329,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 (file)
index 0000000..5347c11
--- /dev/null
@@ -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