This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, fortran] PR31213 , PR33888 and PR33998 - formal actual mapping problems


:ADDPATCH fortran:

The attached patch builds upon Richard Sandiford's interface mapping
mechanism to permit the compilation of calls to horrors like:

  pure function tricky (str,ugly)                 ! PR31213
    character(*), intent(in) :: str
    integer(ik1) :: ia_ik1(len(str))
    interface yoagly
      pure function ugly(n)
        use mykinds
        implicit none
        integer, intent(in) :: n
        complex(dp) :: ugly(3*n+2)
      end function ugly
    end interface yoagly
    logical :: la(size (yoagly (size (ia_ik1))))
    integer :: i
    character(tricky_helper ((/(.TRUE., i=1, size (la))/)) + c_size) :: tricky

    tricky = transfer (yoagly (1), tricky)
  end function tricky

At the same time, the extensions to the mapping mechanism permit a
solution to PR33888, where the size of the temporary for an array
valued call to an elemental function was failing because the interface
mapping occurred too late.

The above serves to illustrate the issues.

(i) The result character length expression is:
length = tricky_helper ((/(.TRUE., i=1, size (la))/)) + c_size

This contains an inquiry about a procedure variable, which must be
expanded in the caller's scope, using the actual argument values for
the procedure.  This is performed by the new function trans-expr.c
(gfc_map_intrinsic_function).

It should be noted that my attempts to make this implementation of
LBOUND and UBOUND compliant with the standard failed, in the case
where the size in the dimension concerned is zero.  This failure comes
about because expressions like gfc_log2int (gfc_gt (*, *, *)) return
not zero or one but zero and the numeric value of the greater-than.
The only way that I can see to deal with this is to write a hidden
intrinsic gfc_expr* gfc_cond ('cond', 'value') = <'cond' ?  'value' :
'zero'>.  I have added a TODO to this effect.

(ii) When this character length is expanded, we get:
length = tricky_helper ((/(.TRUE., i=1, size (ugly (size (ia_ik1))))/)) + c_size

The mapping of this procedure requires the actual argument expression
so that the expressions for the result characteristics can be mapped
onto the formal arguments and hence to the caller's actual arguments.
This necessitates the addition of the 'expr' field to the mapping
structure.  The function is mapped in gfc_map_fcn_formal_to_actual.
Note that the backend_decl is not available here, so expression
substitution has to be introduced to the mapping mechanism as well as
symtree substitution.  Note, as well, that the specific function
'ugly' has to be set as referenced in the caller's scope.

(iii) The array constructor has an iterator variable that is not
declared in the caller's scope.  This is dealt with by making a
temporary, when no backend_decl is present.

(iv) Since the mapping mechanism can now mix tree expressions and
frontend expressions, this open ups up the solution to PR33888, where
a mapping is done for the elemental character length, purely in
frontend expressions.  This is the purpose of trans-expr.c
(get_elemental_fcn_charlen).

With this introduction, the patch and the ChangeLogs should be
comprehensible.  The testcases are the contributors'.  I might just
reorder these so that the patch is tested more systematically but they
will do for now.

This patch has only been regtested on Cygwin_NT/amd64, so it might
have some of the usual problems.  Also, it has not been tested on CP2K
or tonto-2.3 yet.  I will be in a position to remedy all of this next
week but if somebody could give the patch a spin on a more lively
system, I would be grateful.

OK for trunk?

Paul

Attachment: Change.Logs
Description: Binary data

Attachment: patch_1213.diff
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]