public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6864] Fortran: optional argument DIM for intrinsics NORM2, PARITY must be scalar
Date: Tue, 25 Jan 2022 20:18:11 +0000 (GMT)	[thread overview]
Message-ID: <20220125201811.5E521385BF85@sourceware.org> (raw)

https://gcc.gnu.org/g:34e8dafb76240f69c729c11cfc8c8fc4f717bc17

commit r12-6864-g34e8dafb76240f69c729c11cfc8c8fc4f717bc17
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Jan 24 21:40:41 2022 +0100

    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.

Diff:
---
 gcc/fortran/check.cc                               |  6 ++++++
 gcc/testsuite/gfortran.dg/argument_checking_26.f90 | 14 ++++++++++++++
 2 files changed, 20 insertions(+)

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


                 reply	other threads:[~2022-01-25 20:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220125201811.5E521385BF85@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).