This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix the trivial type passed as value with bind(C)
ClosedPublic

Authored by peixin on Oct 14 2022, 8:19 PM.

Details

Summary

In the callee side, the value cannot be used directly. For example, the
dummy argument is lhs variable or the dummy argument is passed to
another procedure as actual argument.

Fix this by allocating one temporary storage and store the value. Then
map the symbol of dummy argument to the mlir::Value of the temporary.

Diff Detail

Event Timeline

peixin created this revision.Oct 14 2022, 8:19 PM
peixin requested review of this revision.Oct 14 2022, 8:19 PM
peixin updated this revision to Diff 467994.Oct 14 2022, 9:58 PM

Fix one code-style problem.

I think BIND(C) VALUE arrays should hit a compile time error, otherwise looks good to me.

flang/test/Lower/call-by-value.f90
86

I think array dummy arguments with VALUE in BIND(C) interface may be illegal. My rational is that 18.3.6 does not list them as something allowed in a BIND(C) interface. I am surprised the standard to has not been more explicit about this in 8.5.18 (adding it to C865 for instance).

gfortran, nvfortran, xlf, and ifort all raise compile time errors here.

I would be inclined to add a fatal error in lowering instead of supporting it and adding a test until a proper semantic check is added.

I think a more cryptic lowering error is most likely hit for the following anyway:

subroutine test_integer_array_value(x, n) bind(c)
  integer :: n
  integer, value :: x(n)
end
peixin updated this revision to Diff 468175.Oct 17 2022, 5:42 AM

Remove the array support.

flang/test/Lower/call-by-value.f90
86

Thanks. I agree with you. Fixed.

jeanPerier accepted this revision.Oct 17 2022, 6:50 AM

Thanks, looks good !

This revision is now accepted and ready to land.Oct 17 2022, 6:50 AM
This revision was automatically updated to reflect the committed changes.