Bug 13507

Summary: [3.3 Regression] spurious printf format warning
Product: gcc Reporter: snyder
Component: c++Assignee: Nathan Sidwell <nathan>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs
Priority: P3 Keywords: diagnostic, patch
Version: 3.4.0   
Target Milestone: 3.3.3   
Host: i686-pc-linux-gnu Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed: 2003-12-31 17:00:41

Description snyder 2003-12-29 23:01:26 UTC
For the source below, gives a bogus warning when -Wall is used:

$ ./cc1plus -Wall -quiet x.i
x.i: In function `void foo(unsigned int)':
x.i:8: warning: format argument is not a pointer (arg 2)
$

This problem appears to have been introduced by this change:

2003-12-28  Roger Sayle  <roger@eyesopen.com>

	PR c++/13070
	* decl.c (duplicate_decls): When setting the type of an anticipated
	declaration, merge the existing type attributes.

If i revert that change, then the warning goes away.

Below is the dump of the attrs parameter at the entry
to check_function_format().  It contains _two_ format
attributes, one printf and one scanf.  check_format_info is being
called twice, once for each; the second time (the scanf one)
is when the warnings gets emitted.

 <tree_list 0x400eab40
    purpose <identifier_node 0x40026e40 format
    bindings <(nil)>
    local bindings <(nil)>>
    value <tree_list 0x40030ca8
        value <identifier_node 0x40026fc0 printf public
        bindings <0x4007a460>
        local bindings <(nil)>>
        chain <tree_list 0x40030b04
            value <integer_cst 0x40030a50 constant 1>
            chain <tree_list 0x40030a8c
                value <integer_cst 0x40030a78 constant 2>>>>
    chain <tree_list 0x4007a8fc
        purpose <identifier_node 0x40026f00 nonnull
        bindings <(nil)>
        local bindings <(nil)>>
        value <tree_list 0x40030a64 value <integer_cst 0x40030a50 1>>
        chain <tree_list 0x4007a8e8 purpose <identifier_node 0x40026e40 format>
            value <tree_list 0x40030d98
                value <identifier_node 0x40033140 scanf public
                bindings <0x4007a988>
                local bindings <(nil)>> chain <tree_list 0x40030b04>>>>>

Environment:
System: Linux karma 2.6.0 #9 Sun Dec 28 19:12:01 EST 2003 i686 i686 i386 GNU/Linux
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --prefix=/usr/local/gcc --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77

How-To-Repeat:

Compile with -Wall:

-----------------------------------------------------------
extern "C" {
extern int printf (__const char *__restrict __format, ...) throw ();
extern int scanf (__const char *__restrict __format, ...) throw ();
}

void foo(unsigned int x)
{
  printf ("%d\n", x);
}
-----------------------------------------------------------
Comment 1 Andrew Pinski 2003-12-30 00:05:04 UTC
The problem was not introduced by that patch, that patch fixed -Wformat for C++.
Comment 2 Andrew Pinski 2003-12-30 00:43:00 UTC
This is another case of tree sharing.
Roger could look into this one, since you caused it.
Comment 3 Andrew Pinski 2003-12-30 07:00:36 UTC
I posted a patch which should fix it: <http://gcc.gnu.org/ml/gcc-patches/2003-12/
msg02251.html> and not brake every thing else.
Comment 4 Nathan Sidwell 2003-12-30 10:48:36 UTC
Sorry, that patch cannot be right. I'm testing a patch that
correctly merges the attributes.
Comment 5 GCC Commits 2003-12-30 12:18:31 UTC
Subject: Bug 13507

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	nathan@gcc.gnu.org	2003-12-30 12:18:28

Modified files:
	gcc/cp         : ChangeLog decl.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/ext: attrib11.C 

Log message:
	cp:
	PR c++/13507
	* decl.c (duplicate_decls): Use build_type_attribute_variant to
	merge attributes.
	testsuite:
	PR c++/13507
	* g++.dg/ext/attrib11.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3842&r2=1.3843
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1169&r2=1.1170
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3322&r2=1.3323
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/attrib11.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 6 Nathan Sidwell 2003-12-30 12:19:06 UTC
2003-12-30  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/13507
	* decl.c (duplicate_decls): Use build_type_attribute_variant to
	merge attributes.
Comment 7 Andrew Pinski 2003-12-30 17:02:45 UTC
Should also be fixed for 3.3.3 also, right?
Comment 8 GCC Commits 2004-01-01 03:32:19 UTC
Subject: Bug 13507

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	pinskia@gcc.gnu.org	2004-01-01 03:32:14

Modified files:
	gcc/cp         : ChangeLog decl.c 

Log message:
	2003-12-20  Andrew Pinski  <pinskia@physics.uc.edu>
	
	Backport from mainline:
	2003-12-30  Nathan Sidwell  <nathan@codesourcery.com>
	
	PR c++/13507
	* decl.c (duplicate_decls): Use build_type_attribute_variant to
	merge attributes.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.233&r2=1.3076.2.234
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.965.2.68&r2=1.965.2.69

Comment 9 Andrew Pinski 2004-01-01 03:34:05 UTC
Fixed for 3.3.3 also.