Bug 49108

Summary: Support constructors tied to a variable
Product: gcc Reporter: Tobias Burnus <burnus>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: WAITING ---    
Severity: normal Keywords: missed-optimization
Priority: P3    
Version: 4.7.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2019-01-18 00:00:00
Bug Depends on:    
Bug Blocks: 18918    

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
contains
  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;
}
Comment 1 Dominique d'Humieres 2019-01-18 00:37:53 UTC
The code in comment 0 is rejected with

    4 |     integer :: a[*]
      |                   1
Error: Variable 'a' at (1) is a coarray and is not ALLOCATABLE, SAVE nor a dummy argument