]> git.ipfire.org Git - thirdparty/gcc.git/commit
diagnostics: Consistently add fixit hint for implicit builtin declaration
authorMark Wielaard <mark@klomp.org>
Thu, 28 May 2020 00:55:36 +0000 (02:55 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 5 Jun 2020 18:21:17 +0000 (20:21 +0200)
commit1c7bcefbc95220cd74cee7c239f6d723f75a0ccc
tree135fe4efe728f939d0d86cb7ee7e4ca10292ed32
parent0cdc55f5ed881436c49d313b6cead244bdcf0654
diagnostics: Consistently add fixit hint for implicit builtin declaration

There are two warnings that might trigger when a builtin function is
used but not declared yet. Both called through implicitly_declare in
c-decl. The first in implicit_decl_warning does warn for builtins,
but does not add a fixit hint for them (only for non-builtins when
a header is suggested through lookup_name_fuzzy). This warning is
guarded by -Wimplicit-function-declaration. The second warning, which
does include a fixit hint if possible, is given when the implicit
builtin declaration has an incompatible signature. This second warning
cannot be disabled.

This setup means that you only get a fixit-hint for usage of builtin
functions where the implicit signature is different than the actual
signature of the builtin. No fixit hints with header suggestions
are ever generated for builtins like abs, isdigit or putchar.

It seems more consistent to always generate a fixit-hint if possible
for the -Wimplicit-function-declaration warning. And for the second
warning to make it depend on -Wbuiltin-declaration-mismatch like
other warnings about builtin declaration mismatches.

Include a new test to show we get fixit-hints for abs, isdigit and
putchar now. Some small tweaks to existing tests to show the
effect of -Wno-builtin-declaration-mismatch with this change. And
a testcase to show that #pragma GCC diagnostic ignored now works.

gcc/c/ChangeLog:

* c-decl.c (implicit_decl_warning): When warned and olddecl is
an undeclared builtin, then add a fixit header hint, if found.
(implicitly_declare): Add OPT_Wbuiltin_declaration_mismatch to
warning_at about implicit builtin declaration type mismatch.

gcc/testsuite/ChangeLog:

* gcc.dg/missing-header-fixit-3.c: Add
-Wno-implicit-function-declaration.
* gcc.dg/missing-header-fixit-4.c: Add new expected output.
* gcc.dg/missing-header-fixit-5.c: New testcase.
* gcc.dg/Wbuiltin-declaration-mismatch-ignore.c: Likewise.
gcc/c/c-decl.c
gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-ignore.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/missing-header-fixit-3.c
gcc/testsuite/gcc.dg/missing-header-fixit-4.c
gcc/testsuite/gcc.dg/missing-header-fixit-5.c [new file with mode: 0644]