Hello,

I’m stil trying to fix this
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106731> ICE bug for an
automatic array of a derived type with DTIO:

   63 |         type(t) :: automatic(n)

      |                               1

internal compiler error: in gfc_trans_auto_array_allocation, at
fortran/trans-array.cc:6617


Still digging for the first time in the gfortran code, I need help to move
further.

So far I’ve found:



   1. ICE is triggered in trans-array line 6617 by  gcc_assert
   (!TREE_STATIC (decl)); Makes sense, an automatic array is not SAVEd.
   2. Elsewhere, in trans-decl.cc, I found this chunk and commented it out.
   This fixed the ICE issue, but crashes some test cases i.e. dtio_4.f90 and
   dtio_14.f90, when built with full optimization (-O3)


  /* If derived-type variables with DTIO procedures are not made static
     some bits of code referencing them get optimized away.
     TODO Understand why this is so and fix it.  */
//  if (!sym->attr.use_assoc
//      && ((sym->ts.type == BT_DERIVED
//           && sym->ts.u.derived->attr.has_dtio_procs)
//        || (sym->ts.type == BT_CLASS
//            && CLASS_DATA (sym)->ts.u.derived->attr.has_dtio_procs)))
//    TREE_STATIC (decl) = 1;3.

3. Of the optimization flags "-fpeel-loops" is the one that triggers the
failing tests

3. in dtio_4.f90, the first test fails for 1) non-extended class; 2)
derived-type READ. Write works; extended type (BT_CLASS) works. It appears
that the optimizer thinks the derived type is not modified by the read
statement.

4. If i replace the READ statement with a direct call to the udt routine
(`call user_defined_read`) the test succeeds, so I've looked how the tree
dumps compare:

federico@Federicos-MacBook-Pro dtio % diff callsub withdtio

498c498,500

<   CALL user_defined_read ((test1:udt1) (10) ('dt') ((/ 1 /)) (iostat =
test1:ios) (iomsg = test1:iomsg))

---

>   READ UNIT=10 FMT='(dt)' IOMSG=test1:iomsg IOSTAT=test1:ios ADVANCE='no'

>   TRANSFER test1:udt1

>   DT_END

federico@Federicos-MacBook-Pro dtio %

while -fdump-tree-original returns exactly identical dumps:

federico@Federicos-MacBook-Pro dtio % diff callsub withdtio

federico@Federicos-MacBook-Pro dtio %

Now I'm a bit stuck because I have no experience in gfortran coding, more
so with the gcc optimizer.
I hope some of you can help! But at least, I'm starting to understand how
the code structure works.

Best,
Federico

Attachment: dtio_4.f90
Description: Binary data

Reply via email to