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

--- Comment #11 from kargl at gcc dot gnu.org ---
(In reply to kargl from comment #10)
> *** Bug 85526 has been marked as a duplicate of this bug. ***

Comment #6 in the duplicate provides additional information.
Reprodcued here.



Well, I understand the problem a bit now.  In decl.c (lines 3229
to 3248), we have 

      /* If gfortran ends up here, then the len may be reducible to a
         constant.  Try to do that here.  If it does not reduce, simply
         assign len to the charlen.  */
      if (len && len->expr_type != EXPR_CONSTANT)
        {
          gfc_expr *e;
          e = gfc_copy_expr (len);
          gfc_reduce_init_expr (e);
          if (e->expr_type == EXPR_CONSTANT)
            {
              gfc_replace_expr (len, e);
              if (mpz_cmp_si (len->value.integer, 0) < 0)
                mpz_set_ui (len->value.integer, 0);
            }
          else
            {
              gfc_free_expr (e);
            }
          cl->length = len;
        }

'gfc_reduce_init_expr (e)' is causing the symbol checkFmt,
which has not previously been seen, to be committed to the
current namespace before the symbol has been resolved.  So,
checkFmt() doesn't have a proper type and gfortran cannot
set it when she finally parses the function.  During the
translation, checkFmt is implicitly typed, which can be
gleaned from 

0x6ce630 gfc_conv_expr(gfc_se*, gfc_expr*)
        ../../gcc8/gcc/fortran/trans-expr.c:7918
0x6d0967 gfc_conv_expr_val(gfc_se*, gfc_expr*)    <-- from stepping in gdb
        ../../gcc8/gcc/fortran/trans-expr.c:7975
0x6fed87 gfc_trans_if_1
        ../../gcc8/gcc/fortran/trans-stmt.c:1427
0x70715a gfc_trans_if(gfc_code*)

What needs to be done is that symbols in the gfc_current_ns
must be save before the call to 'gfc_reduce_init_expr (e)'.
If reduction fails, then the old symbols need to be
restored in the gfc_current_ns and any new symbols added
by 'gfc_reduce_init_expr (e)' need to be removed.  

Unfortunately, I don't know how to do this.

Reply via email to