]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Try the type with the previous function attributes
authorH.J. Lu <hjl.tools@gmail.com>
Sun, 26 Oct 2025 00:42:20 +0000 (08:42 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 27 Oct 2025 22:46:35 +0000 (06:46 +0800)
commitdcf69bdcd49bccd901bfb01db7c15530e9a70dc0
tree3ce12375d22c293d289b06720f6e695abaae6fc8
parent76943639ddd861dce3886d1def2a353ccfcdd585
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 <hjl.tools@gmail.com>
12 files changed:
gcc/c/c-decl.cc
gcc/testsuite/g++.target/i386/cf_check-1.C [new file with mode: 0644]
gcc/testsuite/g++.target/i386/cf_check-2.C [new file with mode: 0644]
gcc/testsuite/g++.target/i386/cf_check-3.C [new file with mode: 0644]
gcc/testsuite/g++.target/i386/cf_check-4.C [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cf_check-10.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cf_check-11.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cf_check-7.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cf_check-8.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/cf_check-9.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/no-callee-saved-12.c
gcc/testsuite/gcc.target/i386/preserve-none-17.c