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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Priority|P3                          |P4
   Last reconfirmed|                            |2022-09-07

--- Comment #3 from kargl at gcc dot gnu.org ---
(In reply to G. Steinmetz from comment #2)
> The following examples are presumably valid code,
> don't use a function, nor alloc, but should be related :
> 
> 
> $ cat z1.f90
> program p
>    use iso_c_binding
>    integer :: a(2) = 0
>    print *, c_sizeof((a))
>    print *, c_sizeof(2*a)
> end
> 
> 
> $ cat z2.f90
> program p
>    use iso_c_binding
>    character(1) :: a(2) = '0'
>    print *, c_sizeof((a))
>    print *, c_sizeof(a)
> end
> 

The above testcases compile with this patch.

diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc
index bbdb5b392fc..f5fed223a23 100644
--- a/gcc/fortran/array.cc
+++ b/gcc/fortran/array.cc
@@ -2766,7 +2766,24 @@ gfc_find_array_ref (gfc_expr *e, bool allow_null)
 {
   gfc_ref *ref;

-  for (ref = e->ref; ref; ref = ref->next)
+  if (e->expr_type == EXPR_OP && !e->ref)
+    {
+      gfc_expr *op1, *op2;
+      op1 = e->value.op.op1;
+      op2 = e->value.op.op2;
+      if (!op2)
+       {
+         if (op1->rank == 0)
+           return NULL;
+         ref = op1->ref;
+       }
+      else
+       ref = op2->ref;
+    }
+  else
+    ref = e->ref;
+
+  for (; ref; ref = ref->next)
     if (ref->type == REF_ARRAY
        && (ref->u.ar.type == AR_FULL || ref->u.ar.type == AR_SECTION))
       break;

Reply via email to