PR40011 -fwhole-file problems

Paul Richard Thomas paul.richard.thomas@gmail.com
Tue Jun 2 05:31:00 GMT 2009


Tobias,

Bingo!  Thanks for that.  I suppose that there must be some flag that
can be set to signal that - I'll take a look to night.

Cheers

Paul

2009/6/2 Tobias Schlüter <tobias.schlueter@physik.uni-muenchen.de>:
>
> Hi,
>
> Paul Richard Thomas wrote:
>>
>> gfortran.dg/default_initialization_3.f90 fails at runtime at -O2.   I
>> have reduced it to expose the problem:
>
> ...
>>
>> Which looks fine.  At -O2, however, we get:
>>
>> func (integer(kind=4) & ivalue, struct myint & retval1, struct myint &
>> retval2)
>> {
>>  static struct myint foo2 = {.bar=77};
>>
>> <bb 2>:
>>  retval1_1(D)->bar = 42;
>>  *retval2_2(D) = foo2;
>>  foo2.bar = 999;
>>  return;
>>
>> }
>>
>>
>> ;; Function other (other_)
>>
>> other ()
>> {
>>  static struct myint foo2 = {.bar=77};
>>  static struct myint foo2 = {.bar=77};
>>  static struct myint foo2 = {.bar=77};
>
> This is the issue, apparently the optimizer can't handle inlining functions
> with static variables (SAVE in Fortran).  I verified with a C example that
> indeed functions with static variables are not inlined if they're called
> more than once.
>
> Example below.
>
> Cheers & HTH,
> - Tobi
>
> extern int printf(const char*, ...);
>
> static int x()
> {
>  static int i = 0;
>  return i++;
> }
>
> static int y()
> {
>  int i = 2;
>  return i;
> }
>
>
> int z()
> {
>  if (x())
>    printf("a");
>  if (y())
>    printf("b");
>  if (x())
>    printf("c");
> }
>
>
> from the optimized dump:
> <bb 0>:
>  D.1472 = x ();
>  if (D.1472 != 0) goto <L0>; else goto <L1>;
>
> <L0>:;
>  printf (&"a"[0]);
>
> <L1>:;
>  printf (&"b"[0]);
>  D.1474 = x ();
>  if (D.1474 != 0) goto <L5>; else goto <L6>;
>
> <L5>:;
>  printf (&"c"[0]) [tail call];
>
>



-- 
The knack of flying is learning how to throw yourself at the ground and miss.
       --Hitchhikers Guide to the Galaxy



More information about the Fortran mailing list