PR c/83656 - missing -Wbuiltin-declaration-mismatch on declaration without prototype gcc/c/ChangeLog: PR c/83656 * c-decl.c (diagnose_mismatched_decls): Diagnose declarations of built-in functions without a prototype. gcc/testsuite/ChangeLog: PR c/83656 * gcc.dg/Wbuiltin-declaration-mismatch-5.c: New test. diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 6c9e667..7008176 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -2088,15 +2088,29 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, can't validate the argument list) the built-in definition is overridden, but optionally warn this was a bad choice of name. */ if (DECL_BUILT_IN (olddecl) - && !C_DECL_DECLARED_BUILTIN (olddecl) - && (!TREE_PUBLIC (newdecl) - || (DECL_INITIAL (newdecl) - && !prototype_p (TREE_TYPE (newdecl))))) + && !C_DECL_DECLARED_BUILTIN (olddecl)) { - warning (OPT_Wshadow, "declaration of %q+D shadows " - "a built-in function", newdecl); - /* Discard the old built-in function. */ - return false; + if (!TREE_PUBLIC (newdecl) + || (DECL_INITIAL (newdecl) + && !prototype_p (TREE_TYPE (newdecl)))) + { + warning_at (DECL_SOURCE_LOCATION (newdecl), + OPT_Wshadow, "declaration of %qD shadows " + "a built-in function", newdecl); + /* Discard the old built-in function. */ + return false; + } + + if (!prototype_p (TREE_TYPE (newdecl))) + { + warning_at (DECL_SOURCE_LOCATION (newdecl), + OPT_Wbuiltin_declaration_mismatch, + "declaration of built-in function %qD without " + "a prototype; expected %qT", + newdecl, TREE_TYPE (olddecl)); + /* Discard the old built-in function. */ + return false; + } } if (DECL_INITIAL (newdecl)) diff --git a/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-5.c b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-5.c new file mode 100644 index 0000000..51a634d --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-5.c @@ -0,0 +1,10 @@ +/* PR c/83656 - missing -Wbuiltin-declaration-mismatch on declaration + without prototype + { dg-do compile } + { dg-options "-Wbuiltin-declaration-mismatch" } */ + +void* memcpy (); /* { dg-warning "declaration of built-in function .memcpy. without a prototype; expected .void \\\*\\\(void \\\*, const void \\\*, \(long \)?unsigned int\\\)." } */ + +int strcmp (); /* { dg-warning "declaration of built-in function .strcmp. without a prototype; expected .int\\\(const char* \\\*, const char \\\*\\\)." } */ + +int strcpy (); /* { dg-warning "conflicting types for built-in function .strcpy.; expected .char \\\*\\\(char \\\*, const char \\\*\\\)." } */