https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102456

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Priority|P3                          |P4
   Last reconfirmed|                            |2021-09-22

--- Comment #1 from kargl at gcc dot gnu.org ---
The following diff stops the ICE, which is a null pointer dereference.

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 851af1b30dc..2a250d73a28 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -4589,9 +4589,14 @@ gfc_check_rank (gfc_expr *a)

   /* Functions returning pointers are regarded as variable, cf. F2008, R602. 
*/
   if (a->expr_type == EXPR_FUNCTION)
-    is_variable = a->value.function.esym
-                 ? a->value.function.esym->result->attr.pointer
-                 : a->symtree->n.sym->result->attr.pointer;
+    {
+      if (a->value.function.esym && a->value.function.esym->result)
+       is_variable = a->value.function.esym->result->attr.pointer;
+      else if (a->symtree->n.sym->result)
+       is_variable = a->symtree->n.sym->result->attr.pointer;
+      else
+       is_variable = false;
+    }

   if (a->expr_type == EXPR_OP
       || a->expr_type == EXPR_NULL

But, the patch yields

% gfcx -c -fcoarray=lib a.f90
a.f90:6:17:

    6 |    print *, rank(x[1])
      |                 1
Error: The argument of the RANK intrinsic at (1) must be a data object

and Gerhard indicates the code is legal.  I don't use coarrays say cannot
confirm or deny this assertion.  I do note that if one pokes around in
gdb that one finds

(gdb) p *a->value.function.actual->expr->symtree->n.sym->as 
$11 = {rank = 0, corank = 1, type = AS_EXPLICIT, cotype = AS_EXPLICIT, 
  lower = {0x203627620, 0x0 <repeats 14 times>}, upper = {
    0x0 <repeats 15 times>}, cray_pointee = false, cp_was_assumed = false, 
  resolved = true}

which is the only place I can locate rank and corank info.  I'll also
note that we do have

(gdb) p a->rank
$13 = 0

Reply via email to