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

--- Comment #9 from anlauf at gcc dot gnu.org ---
(In reply to Jerry DeLisle from comment #8)
> This seems to fix this:
> 
> diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
> index 4b3f75ced71..ae451da04e8 100644
> --- a/gcc/fortran/trans-decl.cc
> +++ b/gcc/fortran/trans-decl.cc
> @@ -764,7 +764,7 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
>             && 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;
> +    TREE_THIS_VOLATILE (decl) = 1;
>  
>    /* Treat asynchronous variables the same as volatile, for now.  */
>    if (sym->attr.volatile_ || sym->attr.asynchronous)

I thought of the same modification and also saw:

> Running target unix
> FAIL: gfortran.dg/dtio_4.f90   -O3 -fomit-frame-pointer -funroll-loops
> -fpeel-loops -ftracer -finline-functions  execution test
> FAIL: gfortran.dg/dtio_4.f90   -O3 -g  execution test

Comparing the optimized dump shows the following types of differences after
the above:

   <bb 20> [local count: 30384459]:
-  _8 = MEM[(integer(kind=4)[15] *)&udt1][14];
   _9 = result_array[14];
-  if (_8 != _9)
+  if (_9 != 99)
     goto <bb 22>; [5.50%]
   else
     goto <bb 21>; [94.50%]

For some reason the optimizer thinks that it can optimize

  if (any(udt1%myarray.ne.result_array)) STOP 2

although the read sets udt1%myarray to the same as result_array
(confirmed by an explicit print).

Even setting

  volatile :: udt1

has no effect on the above optimized code.

Note that the 99 comes from initialization

  udt1%myarray = 99

and it should get overwritten by the read.

Maybe we are barking up the wrong tree, and the issue is actually
with the read!

Should it set the variable udt1 as modified?

Reply via email to