https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125092

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Thomas Koenig <[email protected]>:

https://gcc.gnu.org/g:8b40209e48c8212ad870724b83718ed244bdf6eb

commit r17-514-g8b40209e48c8212ad870724b83718ed244bdf6eb
Author: Thomas Koenig <[email protected]>
Date:   Thu May 14 16:59:11 2026 +0200

    PR fortran/125092 - implement 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:

            PR fortran/125092
            * 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:

            PR fortran/125092
            * 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.

Reply via email to