[Patch] Fortran: Skip bound conv in gfc_conv_gfc_desc_to_cfi_desc with intent(out) ptr [PR108621]

Tobias Burnus tobias@codesourcery.com
Fri Feb 24 11:31:59 GMT 2023


[The following is about Fortran pointers as actual argument to a CFI taking procedure.]

The issue has been marked as 12/13 regression but the issue is just a diagnostic one.

To disentangle:

(A) Bogus warning
[Now tracked as middle-end https://gcc.gnu.org/PR108906 ]
Assume:
    nullify(p)
    call bind_c_proc(p)

For some reasons, the compiler does not propagate the NULL and thus assumes that
if (addr != NULL) could be true. This leads to a may-be-uninit warning with '-Wall -O0'.
(And no warning with -Og/-Os/-O1.)

We could silence it on the gfortran side, I think, by tweaking some tree properties,
but I am not sure we want to to it.

(The same kind of code is in GCC 11 but as it is hidden in libgfortran; hence, there are
no warnings when compiling user code. Since GCC 12, the compiler does the conversion
in place when generating the code.)



(B) The attached patch:

With 'intent(out)' there is no reason to do the conversions. While for nullified
pointers the bounds-conversion loop is skipped, it may still be executed for undefined
pointers. (Which is usually harmless.) In either case, not generating this code makes
sense.

OK for mainline?

Regarding GCC 12:  I am not really sure as it is no real regression. Besides bogus
warnings, there might be an issue for undefined pointers and -fsanitize=undefined, namely
if 'ubound - lbound' evaluated on random numbers overflows (such as for ubound = huge(..)
and lbound = -huge(..)). But that looks like a rather special case. - Thoughts?

Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
-------------- next part --------------
A non-text attachment was scrubbed...
Name: intent-out-ptr-cfi.diff
Type: text/x-patch
Size: 5492 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20230224/c6958cd7/attachment-0001.bin>


More information about the Fortran mailing list