public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10078] Fortran: Fix ICE on wrong code [PR99818].
@ 2021-08-28 20:05 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2021-08-28 20:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4a573574b17caf0391ee7f7febdaa82a9ff1094e

commit r10-10078-g4a573574b17caf0391ee7f7febdaa82a9ff1094e
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Sat Apr 3 12:49:50 2021 +0100

    Fortran: Fix ICE on wrong code [PR99818].
    
    2021-04-03  Paul Thomas  <pault@gcc.gnu.org>
    
    gcc/fortran/ChangeLog
    
            PR fortran/99818
            * interface.c (compare_parameter): The codimension attribute is
            applied to the _data field of class formal arguments.
    
    gcc/testsuite/ChangeLog
    
            PR fortran/99818
            * gfortran.dg/coarray_48.f90: New test.
    
    (cherry picked from commit fc27115d6107f219e6f3dc610c99210005fe9dc5)

Diff:
---
 gcc/fortran/interface.c                  | 14 ++++++++++----
 gcc/testsuite/gfortran.dg/coarray_48.f90 | 24 ++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index 1744a82798e..a09a09c925e 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -2326,6 +2326,7 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
   bool rank_check, is_pointer;
   char err[200];
   gfc_component *ppc;
+  bool codimension = false;
 
   /* If the formal arg has type BT_VOID, it's to one of the iso_c_binding
      procs c_f_pointer or c_f_procpointer, and we need to accept most
@@ -2489,7 +2490,12 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
       return false;
     }
 
-  if (formal->attr.codimension && !gfc_is_coarray (actual))
+  if (formal->ts.type == BT_CLASS && formal->attr.class_ok)
+    codimension = CLASS_DATA (formal)->attr.codimension;
+  else
+    codimension = formal->attr.codimension;
+
+  if (codimension && !gfc_is_coarray (actual))
     {
       if (where)
 	gfc_error ("Actual argument to %qs at %L must be a coarray",
@@ -2497,7 +2503,7 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
       return false;
     }
 
-  if (formal->attr.codimension && formal->attr.allocatable)
+  if (codimension && formal->attr.allocatable)
     {
       gfc_ref *last = NULL;
 
@@ -2519,7 +2525,7 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
 	}
     }
 
-  if (formal->attr.codimension)
+  if (codimension)
     {
       /* F2008, 12.5.2.8 + Corrig 2 (IR F08/0048).  */
       /* F2018, 12.5.2.8.  */
@@ -2585,7 +2591,7 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
       return false;
     }
 
-  if (formal->attr.allocatable && !formal->attr.codimension
+  if (formal->attr.allocatable && !codimension
       && actual_attr.codimension)
     {
       if (formal->attr.intent == INTENT_OUT)
diff --git a/gcc/testsuite/gfortran.dg/coarray_48.f90 b/gcc/testsuite/gfortran.dg/coarray_48.f90
new file mode 100644
index 00000000000..adec014995f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_48.f90
@@ -0,0 +1,24 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+!
+! Fix for P99818 in which wrong code caused an ICE.
+!
+! Contributed by Gerhard Steinmetz <gscfq@t-online.de>
+!
+module m
+   type t
+      integer :: a
+   contains
+      procedure :: s
+   end type
+contains
+   subroutine s(x)
+      class(t) :: x[*]
+   end
+end
+program p
+   use m
+   associate (y => t(1))
+      call y%s           ! { dg-error "must be a coarray" }
+   end associate
+end


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

only message in thread, other threads:[~2021-08-28 20:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-28 20:05 [gcc r10-10078] Fortran: Fix ICE on wrong code [PR99818] 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).