[PATCH] Fortran: make STAT/LSTAT/FSTAT intrinsics generic [PR82480]
Harald Anlauf
anlauf@gmx.de
Tue Sep 9 19:19:28 GMT 2025
Am 09.09.25 um 21:13 schrieb Steve Kargl:
> On Tue, Sep 09, 2025 at 08:49:51PM +0200, Harald Anlauf wrote:
>> Hi Jerry!
>>
>> Am 08.09.25 um 23:56 schrieb Jerry D:
>>> On 9/8/25 12:59 PM, Harald Anlauf wrote:
>>>> Dear all,
>>>>
>>>> this is the second (and hopefully final) patch to fix this PR for good.
>>>> This makes the GNU intrinsics STAT/LSTAT/FSTAT almost generic, with few
>>>> restrictions:
>>>>
>>>> - for the VALUES argument we will support only kinds 4 and 8.
>>>> This allows to stay with the current runtime library functions
>>>> in libgfortran. Other arguments will be converted suitably.
>>>>
>>>> - a STATUS argument shall have a decimal exponent range of at
>>>> least four. This allows to handle both common errno values
>>>> as well as potential LIBERROR_* from libgfortran.h.
>>>>
>>>> The hard part was getting this optional,intent(out) STATUS
>>>> argument right when we want to allow kind conversions,
>>>> and the actual argument being an optional dummy.
>>>>
>>>> In its current version, gfc_conv_procedure_call does not seem
>>>> to support such trickery, so I wrote a specialized version
>>>> handling this. It is actually more complex than it needs
>>>> to be, as the related runtime library functions do not
>>>> change their behavior depending on the presence of the
>>>> actual argument. We'll generate a temporary of the needed
>>>> kind, pass a suitable pointer, and assign the result only
>>>> when it should happen.
>>>>
>>>> (Maybe the required feature is already mostly implemented,
>>>> but I just did not see it.)
>>>>
>>>> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>>>>
>>>> Thanks,
>>>> Harald
>>>>
>>>
>>> Reviewed, applied, regression checked here OK.
>>>
>>> make info has no errors and the generated info file looks good.
>>
>> Thanks for the review and full testing!
>>
>> Pushed as r16-3724-g52d754a1a620ef.
>>
>> Harald
>>
>
> This broke bootstrap on FreeBSD where warning.
>
>
> In function 'tree_node* conv_intrinsic_fstat_lstat_stat_sub(gfc_code*)',
> inlined from 'tree_node* gfc_conv_intrinsic_subroutine(gfc_code*)' at ../../gccx/gcc/fortran/trans-intrinsic.cc:13477:49:
> ../../gccx/gcc/fortran/trans-intrinsic.cc:5964:31: error: 'unit' may be used uninitialized [-Werror=maybe-uninitialized]
> 5964 | tmp = build_call_expr_loc (input_location, tmp, 3, unit, vals,
> | ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 5965 | stat ? arg3 : null_pointer_node);
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../../gccx/gcc/fortran/trans-intrinsic.cc: In function 'tree_node* gfc_conv_intrinsic_subroutine(gfc_code*)':
> ../../gccx/gcc/fortran/trans-intrinsic.cc:5881:8: note: 'unit' was declared here
> 5881 | tree unit;
> | ^~~~
> In function 'tree_node* conv_intrinsic_fstat_lstat_stat_sub(gfc_code*)',
> inlined from 'tree_node* gfc_conv_intrinsic_subroutine(gfc_code*)' at ../../gccx/gcc/fortran/trans-intrinsic.cc:13477:49:
> ../../gccx/gcc/fortran/trans-intrinsic.cc:5967:31: error: 'name' may be used uninitialized [-Werror=maybe-uninitialized]
> 5967 | tmp = build_call_expr_loc (input_location, tmp, 4, name, vals,
> | ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 5968 | stat ? arg3 : null_pointer_node, slen);
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../../gccx/gcc/fortran/trans-intrinsic.cc: In function 'tree_node* gfc_conv_intrinsic_subroutine(gfc_code*)':
> ../../gccx/gcc/fortran/trans-intrinsic.cc:5882:8: note: 'name' was declared here
> 5882 | tree name, slen;
> | ^~~~
> In function 'tree_node* conv_intrinsic_fstat_lstat_stat_sub(gfc_code*)',
> inlined from 'tree_node* gfc_conv_intrinsic_subroutine(gfc_code*)' at ../../gccx/gcc/fortran/trans-intrinsic.cc:13477:49:
> ../../gccx/gcc/fortran/trans-intrinsic.cc:5967:31: error: 'slen' may be used uninitialized [-Werror=maybe-uninitialized]
> 5967 | tmp = build_call_expr_loc (input_location, tmp, 4, name, vals,
> | ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 5968 | stat ? arg3 : null_pointer_node, slen);
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../../gccx/gcc/fortran/trans-intrinsic.cc: In function 'tree_node* gfc_conv_intrinsic_subroutine(gfc_code*)':
> ../../gccx/gcc/fortran/trans-intrinsic.cc:5882:14: note: 'slen' was declared here
> 5882 | tree name, slen;
> | ^~~~
>
Does the attached work for you?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fortran-fix-bootstrap-with-Werror-maybe-uninitialize.patch
Type: text/x-patch
Size: 924 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/fortran/attachments/20250909/d7674330/attachment-0001.bin>
More information about the Fortran
mailing list