misoptimization causing der_io.f90 failures

Tobias Schlüter tobias.schlueter@physik.uni-muenchen.de
Fri May 14 22:37:00 GMT 2004


I've been looking into the failure of the Fortran test 
execute/der_io.f90 at optimization levels -O2 and higher. To my naive 
eys this seems to be a misoptimization when inlining a nested function.

Witness:
[tobi@marktplatz tests]$ cat derio.f90
   print *,bar() ! should print 1024
   contains
     integer function bar()
       bar = 1024
     end function
   end
[tobi@marktplatz tests]$ gfortran derio.f90 -O2 -g -funit-at-a-time
[tobi@marktplatz tests]$ ./a.out
       2301916
[tobi@marktplatz tests]$ gfortran derio.f90 -O2 -g -fno-unit-at-a-time
[tobi@marktplatz tests]$ ./a.out
          1024
[tobi@marktplatz tests]$

This certainly is not intended.

Looking thorugh the tree dumps it seems that this already fails when 
lowering to gimple:
[tobi@marktplatz tests]$ cat derio.f90.t05.nested
  ... a dump which looks correct  ...
[tobi@marktplatz tests]$ cat derio.f90.t10.gimple

;; Function MAIN__ (MAIN__)

MAIN__ ()
{
   int4 retval.1;
   register static  bar;

   _gfortran_filename = "derio.f90";
   _gfortran_line = 1;
   _gfortran_ioparm.unit = 6;
   _gfortran_ioparm.list_format = 1;
   _gfortran_st_write ();
   {
     int4 T.0;

     {
       int4 <D430>;

       {
         int4 __result_bar;

         __result_bar = 1024;
       }
       <D429>:;
       retval.1 = <D430>;  // <<<<---- why not "= __result_bar;"?
     }
     T.0 = retval.1;
     _gfortran_transfer_integer (&T.0, 4);
   }
   _gfortran_st_write_done ();
}


[tobi@marktplatz tests]$

Should I file a PR? It didn't seem to be the right thing, as the 
testsuite keeps reminding us of that failure anyway.

- Tobi



More information about the Fortran mailing list