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

--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Rohith Kapelli
<[email protected]>:

https://gcc.gnu.org/g:ce88ece514dcedd41fb9d28943ad37b927ec5621

commit r17-4212-gce88ece514dcedd41fb9d28943ad37b927ec5621
Author: Rohith Kapelli <[email protected]>
Date:   Sat Aug 15 21:47:34 2026 +0530

    ipa-icf: compare the nonnull contract of two functions [PR123227]

    Two functions with identical bodies can still make different promises
    about their arguments, and ICF was not looking at those promises.
    get_nonnull_args derives them from two places: the nonnull attribute on
    the function type, and a METHOD_TYPE, whose this pointer is nonnull
    whether or not anything says so.  sem_function::equals_wpa compared the
    type attributes with comp_type_attributes, which by design only reports
    attributes whose affects_type_identity is set, and nonnull is not one of
    those, and it never compared FUNCTION_TYPE against METHOD_TYPE outside a
    devirtualization specific check.  Either way the two functions were
    declared equal and unified.  The surviving body keeps its own promise, a
    later pass drops the null test that promise makes redundant, and a call
    through the other symbol dereferences the null pointer that symbol was
    required to accept.

    Type identity is the wrong question for ICF.  The comment above the
    variable case already says that for functions we do not know which
    attributes affect code generation, which is why the decl attributes are
    compared as whole lists.  Compare the type attributes the same way, and
    reject a METHOD_TYPE paired with a FUNCTION_TYPE, which carries the same
    promise with nothing on the attribute list to compare.

            PR ipa/123227

    gcc/ChangeLog:

            * ipa-icf.cc (sem_function::equals_wpa): Compare TYPE_ATTRIBUTES
            as a list rather than through comp_type_attributes.  Reject a
            METHOD_TYPE compared against a FUNCTION_TYPE.

    gcc/testsuite/ChangeLog:

            * gcc.dg/ipa/pr123227.c: New test.
            * g++.dg/ipa/pr123227.C: New test.
            * gcc.dg/lto/pr123227_0.c: New test.
            * gcc.dg/lto/pr123227_1.c: New test.
            * g++.dg/lto/pr123227_0.C: New test.
            * g++.dg/lto/pr123227_1.C: New test.

    Signed-off-by: Rohith Kapelli <[email protected]>

Reply via email to