]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fortran: Skip bound conv in gfc_conv_gfc_desc_to_cfi_desc with intent(out) ptr [PR108621]
authorTobias Burnus <tobias@codesourcery.com>
Sat, 25 Feb 2023 10:55:08 +0000 (11:55 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Sat, 25 Feb 2023 10:55:42 +0000 (11:55 +0100)
commitd3e427f684b0cd7cedbe7b93a06f455e562c5901
treef3c68b810b06cc09a7c1e5ebe27b5cf90844e3ba
parent4341106354c6a463ce3628a4ef9c1a1d37193b59
Fortran: Skip bound conv in gfc_conv_gfc_desc_to_cfi_desc with intent(out) ptr [PR108621]

When the dummy argument of the bind(C) proc is 'pointer, intent(out)', the conversion
of the GFC to the CFI bounds can be skipped: it is not needed and avoids issues with
noninit memory.

Note that the 'cfi->base_addr = gfc->addr' assignment is kept as the C code of a user
might assume that a nullified pointer arrives as NULL (or even a specific value).
For instance, gfortran.dg/c-interop/section-{1,2}.f90 assumes the value NULL.

Note 2: The PR is about a may-be-uninitialized warning with intent(out). In the PR's
testcase, the pointer was nullified and should not have produced that warning.
That is a diagnostic issue, now tracked as PR middle-end/108906 as the issue in principle
still exists (e.g. with 'intent(inout)'). [But no longer for intent(out).]

Note 3: With undefined pointers and no 'intent', accessing uninit memory is unavoidable
on the caller side as the compiler cannot know what the C function does (but this usage
determines whether the pointer is permitted be undefined or whether the bounds must be
gfc-to-cfi converted).

gcc/fortran/ChangeLog:

PR fortran/108621
* trans-expr.cc (gfc_conv_gfc_desc_to_cfi_desc): Skip setting of
bounds of CFI desc for 'pointer,intent(out)'.

gcc/testsuite/ChangeLog:

PR fortran/108621
* gfortran.dg/c-interop/fc-descriptor-pr108621.f90: New test.
gcc/fortran/trans-expr.cc
gcc/testsuite/gfortran.dg/c-interop/fc-descriptor-pr108621.f90 [new file with mode: 0644]