This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix the interface for numerical/logical scalar with VALUE attribute
ClosedPublic

Authored by peixin on Oct 19 2022, 7:58 AM.

Details

Summary

Programmers may use procedure without BIND(C) attribute to interoperate
with C code. For numerical/logical scalar with VALUE attribute, pass the
argument by value so that the behavior is consistent with gfortran or
nvfortran. The argument with the OPTIONAL attribute cannot be passed by
value since the actual argument may be absent.

For the derived type, pass-by-value is not supported yet, so pass the
argument by reference for now.

Diff Detail

Event Timeline

peixin created this revision.Oct 19 2022, 7:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2022, 7:58 AM
peixin requested review of this revision.Oct 19 2022, 7:58 AM

Could you elaborate a bit more on why you are choosing to still pass VALUE argument of elemental procedures by reference copy ?

I understand why optionality is needs to be passed by reference copy to encode the presence/absence of the value. But I do not get what is preventing elemental function VALUE arguments to be passed by value.

Could you elaborate a bit more on why you are choosing to still pass VALUE argument of elemental procedures by reference copy ?

I understand why optionality is needs to be passed by reference copy to encode the presence/absence of the value. But I do not get what is preventing elemental function VALUE arguments to be passed by value.

The ELEMENTAL conflicts with BIND(C) attribute. In semantics, the intention of elemental procedure is not to be called by C code. But the truth is that gfortran and classic-flang do support pass-by-value for elemental procedure. Do you think we should support it in flang-new, too?

BTW, for optional argument with VALUE attribute, gfortran still supports pass-by-value. But classic-flang pass the argument by reference. But I think for optional arugment should be passed by reference since it can be absent.

Could you elaborate a bit more on why you are choosing to still pass VALUE argument of elemental procedures by reference copy ?

I understand why optionality is needs to be passed by reference copy to encode the presence/absence of the value. But I do not get what is preventing elemental function VALUE arguments to be passed by value.

The ELEMENTAL conflicts with BIND(C) attribute. In semantics, the intention of elemental procedure is not to be called by C code. But the truth is that gfortran and classic-flang do support pass-by-value for elemental procedure. Do you think we should support it in flang-new, too?

I think we should be consistent as much as possible. If we start to pass non optional VALUE logical and numeric scalar by value for non bind(c) procedure, it seems to me we should also do it for elemental procedures.

BTW, for optional argument with VALUE attribute, gfortran still supports pass-by-value. But classic-flang pass the argument by reference. But I think for optional arugment should be passed by reference since it can be absent.

Interesting. It may encode the presence/absence in an extra argument then. I would stay away from this for the sake of simplicity.

peixin updated this revision to Diff 469244.Oct 20 2022, 8:35 AM
peixin edited the summary of this revision. (Show Details)

Address the comments.

BTW, for optional argument with VALUE attribute, gfortran still supports pass-by-value. But classic-flang pass the argument by reference. But I think for optional arugment should be passed by reference since it can be absent.

Interesting. It may encode the presence/absence in an extra argument then. I would stay away from this for the sake of simplicity.

Agree.

jeanPerier accepted this revision.Oct 21 2022, 4:23 AM

Thanks a lot @peixin, looks good

This revision is now accepted and ready to land.Oct 21 2022, 4:23 AM