public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918
@ 2021-12-20 22:05 Harald Anlauf
  2021-12-21 12:38 ` Mikael Morin
  0 siblings, 1 reply; 7+ messages in thread
From: Harald Anlauf @ 2021-12-20 22:05 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

Dear all,

we need to check the arguments of the elemental MASKL and MASKR
intrinsics also before simplifying.

Testcase by Gerhard.  The fix is almost obvious, but I'm happy to
get feedback in case there is something I overlooked.  (There is
already a check on scalar arguments to MASKL/MASKR, which however
misses the case of array arguments.)

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-check-arguments-of-MASKL-MASKR-intrinsics-be.patch --]
[-- Type: text/x-patch, Size: 2398 bytes --]

From b58a44bc861ee3d1e67e3b7c949a301b6290c05c Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 20 Dec 2021 22:59:53 +0100
Subject: [PATCH] Fortran: check arguments of MASKL/MASKR intrinsics before
 simplification

gcc/fortran/ChangeLog:

	PR fortran/103777
	* simplify.c (gfc_simplify_maskr): Check validity of argument 'I'
	before simplifying.
	(gfc_simplify_maskl): Likewise.

gcc/testsuite/ChangeLog:

	PR fortran/103777
	* gfortran.dg/masklr_3.f90: New test.
---
 gcc/fortran/simplify.c                 |  6 ++++++
 gcc/testsuite/gfortran.dg/masklr_3.f90 | 14 ++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/masklr_3.f90

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 90067b6bbe6..b6f636d4ff1 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -4878,6 +4878,9 @@ gfc_simplify_maskr (gfc_expr *i, gfc_expr *kind_arg)
   bool fail = gfc_extract_int (i, &arg);
   gcc_assert (!fail);

+  if (!gfc_check_mask (i, kind_arg))
+    return &gfc_bad_expr;
+
   result = gfc_get_constant_expr (BT_INTEGER, kind, &i->where);

   /* MASKR(n) = 2^n - 1 */
@@ -4909,6 +4912,9 @@ gfc_simplify_maskl (gfc_expr *i, gfc_expr *kind_arg)
   bool fail = gfc_extract_int (i, &arg);
   gcc_assert (!fail);

+  if (!gfc_check_mask (i, kind_arg))
+    return &gfc_bad_expr;
+
   result = gfc_get_constant_expr (BT_INTEGER, kind, &i->where);

   /* MASKL(n) = 2^bit_size - 2^(bit_size - n) */
diff --git a/gcc/testsuite/gfortran.dg/masklr_3.f90 b/gcc/testsuite/gfortran.dg/masklr_3.f90
new file mode 100644
index 00000000000..eb689f0f408
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/masklr_3.f90
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! PR fortran/103777 - ICE in gfc_simplify_maskl
+! Contributed by G.Steinmetz
+
+program p
+  print *, maskl([999])       ! { dg-error "must be less than or equal" }
+  print *, maskr([999])       ! { dg-error "must be less than or equal" }
+  print *, maskl([-999])      ! { dg-error "must be nonnegative" }
+  print *, maskr([-999])      ! { dg-error "must be nonnegative" }
+  print *, maskl([32],kind=4)
+  print *, maskl([33],kind=4) ! { dg-error "must be less than or equal" }
+  print *, maskl([64],kind=8)
+  print *, maskl([65],kind=8) ! { dg-error "must be less than or equal" }
+end
--
2.26.2


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-01-09 21:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-20 22:05 [PATCH] PR fortran/103777 - ICE in gfc_simplify_maskl, at fortran/simplify.c:4918 Harald Anlauf
2021-12-21 12:38 ` Mikael Morin
2022-01-06 19:50   ` Harald Anlauf
2022-01-06 19:50     ` Harald Anlauf
2022-01-06 21:44     ` Mikael Morin
2022-01-09 20:12       ` Mikael Morin
2022-01-09 21:25         ` 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).