public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/104212 - ICE in transformational_result, at fortran/simplify.cc:466
@ 2022-01-24 20:53 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2022-01-24 20:53 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear Fortranners,

we lacked a check on the optional DIM argument of the intrinsics
PARITY (see pr) and NORM2 (found by scanning check.cc) to verify
that it is scalar.

I intend to commit the attached fix within 48 hours as obvious
unless there are comments.

Regtested on x86_64-pc-linux-gnu.

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-optional-argument-DIM-for-intrinsics-NORM2-P.patch --]
[-- Type: text/x-patch, Size: 2196 bytes --]

From 6c91996f7fc0664a0cf7f5f33ecf2b84c57d4b42 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 24 Jan 2022 21:40:41 +0100
Subject: [PATCH] Fortran: optional argument DIM for intrinsics NORM2, PARITY
 must be scalar

gcc/fortran/ChangeLog:

	PR fortran/104212
	* check.cc (gfc_check_norm2): Check that optional argument DIM is
	scalar.
	(gfc_check_parity): Likewise.

gcc/testsuite/ChangeLog:

	PR fortran/104212
	* gfortran.dg/argument_checking_26.f90: New test.
---
 gcc/fortran/check.cc                               |  6 ++++++
 gcc/testsuite/gfortran.dg/argument_checking_26.f90 | 14 ++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/argument_checking_26.f90

diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc
index 5fe8d452413..4fa05ee7e9b 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -4338,6 +4338,9 @@ gfc_check_norm2 (gfc_expr *array, gfc_expr *dim)
   if (!array_check (array, 0))
     return false;

+  if (!dim_check (dim, 1, false))
+    return false;
+
   if (!dim_rank_check (dim, array, false))
     return false;

@@ -4476,6 +4479,9 @@ gfc_check_parity (gfc_expr *mask, gfc_expr *dim)
   if (!array_check (mask, 0))
     return false;

+  if (!dim_check (dim, 1, false))
+    return false;
+
   if (!dim_rank_check (dim, mask, false))
     return false;

diff --git a/gcc/testsuite/gfortran.dg/argument_checking_26.f90 b/gcc/testsuite/gfortran.dg/argument_checking_26.f90
new file mode 100644
index 00000000000..2b765c5f866
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/argument_checking_26.f90
@@ -0,0 +1,14 @@
+! { dg-do compile }
+! PR fortran/104212 - ICE in transformational_result
+! Contributed by G.Steinmetz
+
+program p
+  logical, parameter :: a(*,*) = reshape([.true.,.false.], shape=[1,2])
+  real,    parameter :: r(*,*) = reshape([1.,2.], shape=[1,2])
+  print *, parity(a)
+  print *, parity(a, dim=1)
+  print *, parity(a, dim=[1]) ! { dg-error "must be a scalar" }
+  print *, norm2 (r)
+  print *, norm2 (r, dim=1)
+  print *, norm2 (r, dim=[1]) ! { dg-error "must be a scalar" }
+end
--
2.31.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-24 20:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 20:53 [PATCH] PR fortran/104212 - ICE in transformational_result, at fortran/simplify.cc:466 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).