Every built-in function is expected to have a matching prototype in at least one header file and completely matching prototypes are something that _should_ happen. Therefore, warning about that probably does not serve any useful purpose but only generates an unwanted noice. Environment: System: FreeBSD k8.dnsalias.net 5.2-CURRENT FreeBSD 5.2-CURRENT #0: Mon Jul 12 00:28:33 EDT 2004 kan@k8.dnsalias.net:/usr/src/sys/amd64/compile/KAN amd64 <machine, os, target, libraries (multiple lines)> host: x86_64-portbld-freebsd5.2 build: x86_64-portbld-freebsd5.2 target: x86_64-portbld-freebsd5.2 configured with: ./..//gcc-3.4-20040709/configure --disable-nls --with-system-zlib --with-libiconv-prefix=/usr/local --program-suffix=34 --with-gxx-include-dir=/usr/local/lib/gcc/x86_64-portbld-freebsd5.2/3.4.2/include/c++/ --disable-shared --disable-libgcj --prefix=/usr/local x86_64-portbld-freebsd5.2 How-To-Repeat: Simplified test case for amd64 (replace long long with int for i386): % cat test.c void * malloc(unsigned long long size); % gcc34 -save-temps -Wredundant-decls -c test.c test.c:1: warning: redundant redeclaration of 'malloc'
Fix: Disable warning if built-in function declaration is being redeclared by normal declaration in user source files. Index: c-decl.c =================================================================== RCS file: /usr/download/ncvs/src/contrib/gcc/c-decl.c,v retrieving revision 1.1.1.18 diff -u -r1.1.1.18 c-decl.c --- c-decl.c 21 Jun 2004 23:47:45 -0000 1.1.1.18 +++ c-decl.c 22 Jul 2004 01:55:22 -0000 @@ -1253,6 +1255,9 @@ definition. */ && !(TREE_CODE (newdecl) == FUNCTION_DECL && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) + /* Don't warn about redundant redeclarations of builtins. */ + && !(TREE_CODE (newdecl) == FUNCTION_DECL + && !DECL_BUILT_IN (newdecl) && DECL_BUILT_IN (olddecl)) /* Don't warn about an extern followed by a definition. */ && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl)) /* Don't warn about forward parameter decls. */
: Search converges between 2004-01-01-trunk (#437) and 2004-01-17-trunk (#438). Confirmed, a regression from 3.3.3. Caused most likely by: 2004-01-10 Zack Weinberg <zack@codesourcery.com> * c-decl.c (duplicate_decls): Break apart into... (diagnose_arglist_conflict, validate_proto_after_old_defn) (locate_old_defn, diagnose_mismatched_decls, merge_decls): ... these new functions. Restructure for comprehensibility. Remove various archaic special cases. Always report the location of the previous declaration when a diagnostic is issued. (redeclaration_error_message): Fold into diagnose_mismatched_decls. (match_builtin_function_types): Delete unnecessary forward declaration. patches as usually goto gcc-patches@gcc.gnu.org.
Subject: Re: (PR 16684) Patch to disable warning about redundant redeclaration of builtin Alexander Kabaev <kan@freebsd.org> writes: > I tried to describe the problem in bug c/16684 titled "[3.4/3.5 > Regression] GCC should not warn about redundant redeclarations of > built-ins". The patch below suppresses the warning if redundant > declaration matches builtin function type exactly. The patch is > against gcc 3.4 branch. I am testing the following slight revision against mainline, and will apply it there if successful. Since it's a regression, I will also test and apply to 3.4 branch, but only if mainline is happy. zw
Created attachment 6819 [details] pr16684.diff
Comment on attachment 6819 [details] pr16684.diff ... fix mime type ...
Subject: Bug 16684 CVSROOT: /cvs/gcc Module name: gcc Changes by: zack@gcc.gnu.org 2004-07-25 03:58:51 Modified files: gcc : ChangeLog c-decl.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: Wredundant-decls-1.c Log message: 2004-07-24 Alexander Kabaev <kan@freebsd.org> Zack Weinberg <zack@codesourcery.com PR 16684 * c-decl.c (diagnose_mismatched_decls): Don't issue a redundant-declaration warning the first time a builtin is declared explicitly. testsuite: * gcc.dg/Wredundant-decls-1.c: New test case. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.4669&r2=2.4670 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-decl.c.diff?cvsroot=gcc&r1=1.537&r2=1.538 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4047&r2=1.4048 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/Wredundant-decls-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
fixed in 3.5 now. will commit for 3.4 shortly.
grar stupid new/assigned thing never works the way i think it does.
3.4 branch commit message seems to have gone off into the weeds. Oh well. It's in now.