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

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

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

commit r16-4667-gdcf69bdcd49bccd901bfb01db7c15530e9a70dc0
Author: H.J. Lu <[email protected]>
Date:   Sun Oct 26 08:42:20 2025 +0800

    c: Try the type with the previous function attributes

    When there are 2 conflicting function declarations, try the new type
    with the previous TYPE_ATTRIBUTES if the current declaration has no
    TYPE_ATTRIBUTES to support

    extern void foo (void) __attribute__((nocf_check));

    void
    foo (void)
    {
    }

    instead of issuing an error:

    $ gcc -O2 -fcf-protection -S x.c
    x.c:4:1: error: conflicting types for âfooâ; have âvoid(void)â
        4 | foo (void)
          | ^~~
    x.c:1:13: note: previous declaration of âfooâ with type
âvoid(void)â
        1 | extern void foo (void) __attribute__((nocf_check));
          |             ^~~

    The resulting function definition is compatible with the previous
    declaration.

    gcc/c/

            PR c/122427
            * c-decl.cc (diagnose_mismatched_decls): For FUNCTION_DECL, if
            OLDDECL has TYPE_ATTRIBUTES and NEWDECL doesn't, try the type
            with the OLDDECL attributes.

    gcc/testsuite/

            PR c/122427
            * g++.target/i386/cf_check-1.C: New test.
            * g++.target/i386/cf_check-2.C: Likewise.
            * g++.target/i386/cf_check-3.C: Likewise.
            * g++.target/i386/cf_check-4.C: Likewise.
            * gcc.target/i386/cf_check-7.c: Likewise.
            * gcc.target/i386/cf_check-8.c: Likewise.
            * gcc.target/i386/cf_check-9.c: Likewise.
            * gcc.target/i386/cf_check-10.c: Likewise.
            * gcc.target/i386/cf_check-11.c: Likewise.
            * gcc.target/i386/no-callee-saved-12.c: Remove dg-error.
            * gcc.target/i386/preserve-none-17.c: Likewise.

    Signed-off-by: H.J. Lu <[email protected]>

Reply via email to