User account creation filtered due to spam.

Bug 49108 - Support constructors tied to a variable
Summary: Support constructors tied to a variable
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: missed-optimization
Depends on:
Blocks: 18918
  Show dependency treegraph
Reported: 2011-05-22 11:43 UTC by Tobias Burnus
Modified: 2011-05-22 11:43 UTC (History)
0 users

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-05-22 11:43:52 UTC
Follow up to PR 49106.

There should be the possibility to tie (nested) constructors to a variable (of the parent function), such that the constructor is optimized away if the parent function is optimized way.

Fortran example (with -fcoarray=lib):

program main
  subroutine foo()
    integer :: a[*] 
    a = 8
  end subroutine
end program main

Here, "foo()" is never called. With -fcoarray=lib gfortran creates a constructor function to register the coarray "a" with the library. The constructor is nested in "foo" - and obviously not needed if the function (or the variable "a") is optimized away.

Expected: By tying the constructor to the variable, the constructor can be optimized away if the variable is needed.

Dump of the Fortran program above:

_caf_init.1 ()
  a = (integer(kind=4) * restrict)
        _gfortran_caf_register (4, 0, &caf_token.0, 0B, 0B, 0);

foo ()
  static void * caf_token.0;
  static integer(kind=4) * restrict a;
  void _caf_init.1 (void);

  *a = 8;