This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Fixed passing c_ptr arguments by value.
ClosedPublic

Authored by vzakhari on Apr 26 2023, 4:41 PM.

Details

Summary

c_ptr arguments passed by value need special handling, which was missing
in HLFIR lowering. The lowering has to load the __address component
and pass the loaded value as the actual argument.

Diff Detail

Event Timeline

vzakhari created this revision.Apr 26 2023, 4:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2023, 4:41 PM
vzakhari requested review of this revision.Apr 26 2023, 4:41 PM

Thanks for working on this TODO!

flang/lib/Lower/ConvertCall.cpp
1084

You cannot assume you will get an hlfir.expr here. This is the case in the example because this a a function result, but I think that with this modified example, a fir.ref<fir.type<cptr....>> would reach this spot:

subroutine test(cptr)
  use iso_c_binding
  interface
     subroutine get_expected_f(src) bind(c)
       use iso_c_binding
       type(c_ptr), value :: src
     end subroutine get_expected_f
  end interface
  type(c_ptr) :: cptr
  call get_expected_f(cptr)
end

Derived type are not part of the "trivial" definition of fir (fir::isa_trivial), so loadTrivialScalar did not turn it into an hlfir.expr.

So you will have to skip the associate/end_associate when value.isValue() is false.

vzakhari added inline comments.Apr 27 2023, 8:42 AM
flang/lib/Lower/ConvertCall.cpp
1084

Thank you for the example, Jean! I will upload the updated change shortly.

vzakhari updated this revision to Diff 517582.Apr 27 2023, 8:43 AM
jeanPerier accepted this revision.Apr 27 2023, 8:59 AM

Thanks, LGTM!

This revision is now accepted and ready to land.Apr 27 2023, 8:59 AM
This revision was automatically updated to reflect the committed changes.