Re: PR fortran/125092 -checks for binding label argument mismatch

Jerry D <[email protected]>
Newsgroups gmane.comp.gcc.patches,gmane.comp.gcc.fortran
Message-ID <[email protected]>
On 5/13/26 9:29 AM, Thomas Koenig wrote:
> Hello world,
> 
> the patch below is regression-tested.  OK for trunk?
> 
> Best regards
> 
>      Thomas
> 
> PR fortran/125092 - checks for binding label argument mismatch.
> 
> This patch implements some checks on different interfaces to the same
> C binding functions. It contains a few policy changes, and is somewhat
> more permissive than the standard, but there are no constraint
> violations (to my knowledge) that it misses.
> 
> Apart from checking for standards conformance, this should also
> help proof code against (now or future) type-based aliasing mishaps.
> 
> Checks for global identifiers are performed on a case-insensitive
> basis by default, and only sensitive when -pedantic is in force.
> This makes sense if Fortran code wants to interface to "FOO" and
> "foo".  The restriction to case-insensitive labels comes from a time
> when relevant systems had linkers which were case-insensitive, and
> it is not possible to implement C (especially the C versions referenced
> in the standard) with such a linker.
> 
> Return types of functions, ranks, number, type and rank of arguments
> are checked. In non-pedantic mode, arguments which have the same
> prototype on the C side are permitted, for example passing a scalar
> or an array by reference, or arrays of different rank (both for pass
> by reference and pass by descriptors). Assumed types are also
> assumed to bee OK. This functionality was checked in a few test
> cases, so it would make little sense to remove it.
> 
> C_PTR is *not* compatible with a random argument passed by reference.
> For example, a TYPE(C_PTR), VALUE argument is not compatible
> with an INTEGER argument (without VALUE); C_LOC has to be used.
> 
> The one-liner in decl.cc may fix some ENTRY problems, I didn't check.
> 
> gcc/fortran/ChangeLog:
> 
>      * decl.cc (add_global_entry): Use string from the heap instead
>      of a pointer to stack-allocated memory.
>      * frontend-passes.cc (check_against_globals): If there is an error
>      already, return early.
>      * gfortran.h (gfc_symbol_rank): New prototype.
>      * interface.cc (symbol_rank): Rename to
>      (gfc_symbol_rank): this.
>      (gfc_check_dummy_characteristics): Use new function name.
>      (gfc_check_result_characteristics): Likewise.
>      (gfc_compare_interfaces): Likewise.
>      (compare_parameter): Likewise.
>      (get_sym_storage_size): Likewise.
>      (gfc_procedure_use): Likewise.
>      * resolve.cc (decays_to_pointer): New function.
>      (c_types_conform): New function.
>      (compare_c_binding_arglists): New function.
>      (gfc_verify_binding_labels): Check return types and rank
>      plus argument lists if there is a pre-exisiting global
>      symbol.
> 
> gcc/testsuite/ChangeLog:
> 
>      * gfortran.dg/PR100906.f90: Add -Wno-pedantic to options.
>      * gfortran.dg/PR100911.f90: Likewise.
>      * gfortran.dg/PR100915.f90: Likewise.
>      * gfortran.dg/PR94327.f90: Likewise.
>      * gfortran.dg/PR94331.f90: Likewise.
>      * gfortran.dg/bind_c_procs_4.f90: Add error messages, remove
>      warning.
>      * gfortran.dg/binding_label_tests_25.f90: Add error messages.
>      * gfortran.dg/binding_label_tests_3.f03: Add error messages.
>      * gfortran.dg/binding_label_tests_34.f90: Add -Wno-pedantic to
>      options.
>      * gfortran.dg/c_char_tests_4.f90: Likewise.
>      * gfortran.dg/c_char_tests_5.f90: Likewise.
>      * gfortran.dg/binding_label_tests_36.f90: New test.
>      * gfortran.dg/binding_label_tests_37.f90: New test.
> 

Looks good to go. I wondered about the TO DO in one of the comments. Are you 
planning to do this later? Any thoughts about it?

Thanks for the work,

Jerry
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.