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

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Something is rotten in the state of gfc_simplify_expr.

Adding

Index: simplify.c
===================================================================
--- simplify.c  (Revision 258232)
+++ simplify.c  (Arbeitskopie)
@@ -230,6 +230,7 @@
   return x;
 }

+void gfc_debug_expr (gfc_expr *);

 /* Test that the expression is a constant array, simplifying if
    we are dealing with a parameter array.  */
@@ -242,9 +243,11 @@
   if (e == NULL)
     return true;

+  gfc_debug_expr (e);
   if (e->expr_type == EXPR_VARIABLE && e->rank > 0
       && e->symtree->n.sym->attr.flavor == FL_PARAMETER)
     gfc_simplify_expr (e, 1);
+  gfc_debug_expr (e);

   if (e->expr_type != EXPR_ARRAY || !gfc_is_constant_expr (e))
     return false;

on a.f90 below yields

main:z(FULL)
0

but the 0 output after simplification seems to be wrong:

show_expr (p=0x11ec2780) at ../../trunk/gcc/fortran/dump-parse-tree.c:388
388       if (p == NULL)
(gdb) p *p
$1 = {expr_type = EXPR_CONSTANT, ts = {type = BT_INTEGER, kind = 4, u =
{derived = 0x0, cl = 0x0, pad = 0}, interface = 0x0, is_c_interop = 0, 
    is_iso_c = 0, f90_type = BT_UNKNOWN, deferred = false, interop_kind = 0x0},
rank = 1, shape = 0x0, symtree = 0x0, ref = 0x0, where = {
    nextc = 0x11ec0378, lb = 0x11ec02e0},
(gdb) p p->rank
$2 = 1
(gdb) p p->shape
$3 = (mpz_t *) 0x0

Note that this works correctly:

program main
  implicit none
  integer, parameter :: z(0) = [integer::]
  print *,minloc(z)
end program main

This yields (correctly)

(gdb) p *p
$1 = {expr_type = EXPR_ARRAY, ts = {type = BT_INTEGER, kind = 4, u = {derived =
0x0, cl = 0x0, pad = 0}, interface = 0x0, is_c_interop = 0, is_iso_c = 0, 
    f90_type = BT_UNKNOWN, deferred = false, interop_kind = 0x11d41be0
<file_changes_cur>}, rank = 1, shape = 0x11ea8610, symtree = 0x0, ref = 0x0, 
  where = {nextc = 0x11ec0378, lb = 0x11ec02e0},

Steve, this may also be the root cause of the other problems in PR66128.

Reply via email to