public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/102715 - [12 Regression] ICE in gfc_simplify_transpose, at fortran/simplify.c:8184
@ 2021-10-31 21:35 Harald Anlauf
  2021-11-05 17:55 ` *PING* " Harald Anlauf
  2021-11-06 10:17 ` Mikael Morin
  0 siblings, 2 replies; 3+ messages in thread
From: Harald Anlauf @ 2021-10-31 21:35 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear Fortranners,

the fix for initialization of DT arrays caused an apparent regression for
cases where inconsistent ranks were used in such an initialization.
This caused either an ICE in subsequent uses of these arrays, or showed
up in valgrind as invalid reads, all of which seemed to be related to this
rank mismatch.

The cleanest solution seems to be to strictly reject rank mismatch earlier
than we used to, which helps error recovery.  I had to adjust one testcase
accordingly.

The place I inserted the check does not distinguish between explicit shape
and implied shape.  The Intel compiler does give a slightly different
error message for the implied shape case.  If anyone feels strongly about
this, I'm open to suggestions for better choices of handling this.

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

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr102715.diff --]
[-- Type: text/x-patch, Size: 2658 bytes --]

commit b1b5e5da928accfe02a7289a331cbea815255a16
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Sun Oct 31 22:20:01 2021 +0100

    Fortran: error recovery on rank mismatch of array and its initializer

    gcc/fortran/ChangeLog:

            PR fortran/102715
            * decl.c (add_init_expr_to_sym): Reject rank mismatch between
            array and its initializer.

    gcc/testsuite/ChangeLog:

            PR fortran/102715
            * gfortran.dg/pr68019.f90: Adjust error message.
            * gfortran.dg/pr102715.f90: New test.

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 2788348d1be..141fdef8c61 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -2105,6 +2105,14 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
 	    }
 	}

+      if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension && sym->as
+	  && sym->as->rank && init->rank && init->rank != sym->as->rank)
+	{
+	  gfc_error ("Rank mismatch of array at %L and its initializer "
+		     "(%d/%d)", &sym->declared_at, sym->as->rank, init->rank);
+	  return false;
+	}
+
       /* If sym is implied-shape, set its upper bounds from init.  */
       if (sym->attr.flavor == FL_PARAMETER && sym->attr.dimension
 	  && sym->as->type == AS_IMPLIED_SHAPE)
diff --git a/gcc/testsuite/gfortran.dg/pr102715.f90 b/gcc/testsuite/gfortran.dg/pr102715.f90
new file mode 100644
index 00000000000..7b29a1c05a6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr102715.f90
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! PR fortran/102715 - ICE in gfc_simplify_transpose
+
+program p
+  type t
+  end type
+  type(t), parameter :: a(4)   = t()
+  type(t), parameter :: b(2,2) = reshape(a, [2]) ! { dg-error "Rank mismatch" }
+  type(t), parameter :: c(2,2) = transpose(b)    ! { dg-error "must be of rank 2" }
+  type(t), parameter :: s2(*)  = b(2,:)          ! { dg-error "Syntax error" }
+  type(t), parameter :: x(*,*) = reshape(a, [2]) ! { dg-error "Rank mismatch" }
+  type(t), parameter :: s3(*)  = x(2,:)          ! { dg-error "Syntax error" }
+end
diff --git a/gcc/testsuite/gfortran.dg/pr68019.f90 b/gcc/testsuite/gfortran.dg/pr68019.f90
index 2e304c3a260..77fd55bd331 100644
--- a/gcc/testsuite/gfortran.dg/pr68019.f90
+++ b/gcc/testsuite/gfortran.dg/pr68019.f90
@@ -9,5 +9,5 @@ program p
       integer :: n
    end type
    type(t), parameter :: vec(*) = [(t(i), i = 1, 4)]
-   type(t), parameter :: arr(*) = reshape(vec, [2, 2])   ! { dg-error "ranks 1 and 2 in assignment" }
+   type(t), parameter :: arr(*) = reshape(vec, [2, 2])   ! { dg-error "Rank mismatch" }
 end

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

* *PING* [PATCH] PR fortran/102715 - [12 Regression] ICE in gfc_simplify_transpose, at fortran/simplify.c:8184
  2021-10-31 21:35 [PATCH] PR fortran/102715 - [12 Regression] ICE in gfc_simplify_transpose, at fortran/simplify.c:8184 Harald Anlauf
@ 2021-11-05 17:55 ` Harald Anlauf
  2021-11-06 10:17 ` Mikael Morin
  1 sibling, 0 replies; 3+ messages in thread
From: Harald Anlauf @ 2021-11-05 17:55 UTC (permalink / raw)
  To: fortran, gcc-patches

Early ping.

Am 31.10.21 um 22:35 schrieb Harald Anlauf via Fortran:
> Dear Fortranners,
>
> the fix for initialization of DT arrays caused an apparent regression for
> cases where inconsistent ranks were used in such an initialization.
> This caused either an ICE in subsequent uses of these arrays, or showed
> up in valgrind as invalid reads, all of which seemed to be related to this
> rank mismatch.
>
> The cleanest solution seems to be to strictly reject rank mismatch earlier
> than we used to, which helps error recovery.  I had to adjust one testcase
> accordingly.
>
> The place I inserted the check does not distinguish between explicit shape
> and implied shape.  The Intel compiler does give a slightly different
> error message for the implied shape case.  If anyone feels strongly about
> this, I'm open to suggestions for better choices of handling this.
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline / affected branches?
>
> Thanks,
> Harald
>


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

* Re: [PATCH] PR fortran/102715 - [12 Regression] ICE in gfc_simplify_transpose, at fortran/simplify.c:8184
  2021-10-31 21:35 [PATCH] PR fortran/102715 - [12 Regression] ICE in gfc_simplify_transpose, at fortran/simplify.c:8184 Harald Anlauf
  2021-11-05 17:55 ` *PING* " Harald Anlauf
@ 2021-11-06 10:17 ` Mikael Morin
  1 sibling, 0 replies; 3+ messages in thread
From: Mikael Morin @ 2021-11-06 10:17 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Le 31/10/2021 à 22:35, Harald Anlauf via Fortran a écrit :
> Dear Fortranners,
> 
> the fix for initialization of DT arrays caused an apparent regression for
> cases where inconsistent ranks were used in such an initialization.
> This caused either an ICE in subsequent uses of these arrays, or showed
> up in valgrind as invalid reads, all of which seemed to be related to this
> rank mismatch.
> 
> The cleanest solution seems to be to strictly reject rank mismatch earlier
> than we used to, which helps error recovery.  I had to adjust one testcase
> accordingly.
> 
> The place I inserted the check does not distinguish between explicit shape
> and implied shape.  The Intel compiler does give a slightly different
> error message for the implied shape case.  If anyone feels strongly about
> this, I'm open to suggestions for better choices of handling this.
> 
> Regtested on x86_64-pc-linux-gnu.  OK for mainline / affected branches?
> 

OK, thanks.

Mikael

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

end of thread, other threads:[~2021-11-06 10:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-31 21:35 [PATCH] PR fortran/102715 - [12 Regression] ICE in gfc_simplify_transpose, at fortran/simplify.c:8184 Harald Anlauf
2021-11-05 17:55 ` *PING* " Harald Anlauf
2021-11-06 10:17 ` Mikael Morin

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).