public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* fix some printf mismatches
@ 2007-05-18 23:05 Geoffrey Keating
  2007-05-18 23:08 ` Andrew Pinski
  2007-05-18 23:19 ` Joseph S. Myers
  0 siblings, 2 replies; 7+ messages in thread
From: Geoffrey Keating @ 2007-05-18 23:05 UTC (permalink / raw)
  To: gcc-patches; +Cc: Rafael Avila de Espindola


Rafael's patch caused GCC to start warning about using %x with signed
values.  Although the patch had other problems, this warning in itself
is not wrong; ISO C doesn't strictly permit this (although it is not a
problem on any platform I know about).  It turns out that looking for
places where people have been sloppy about this is pretty good at
finding other problems, as in the sched-vis change below, so I went
through and fixed them.

I'd have changed the dump-pointer specifier to %p but am not sure if
anything depends on the current version.

Bootstrapped & tested on powerpc-darwin8.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/gcc-longprintf.patch======================
Index: gcc/java/ChangeLog
2007-05-18  Geoffrey Keating  <geoffk@apple.com>

	* jcf-dump.c (HANDLE_MAGIC): Use 'unsigned long' for %lx.
	(print_constant): Likewise.

Index: gcc/ChangeLog
2007-05-18  Geoffrey Keating  <geoffk@apple.com>

	* dwarf2out.c (print_die): Use '%ld' not '%lu' to print a 'long'.
	(output_die): Use 'unsigned long' with %x.
	* sched-vis.c (print_value): Use 'unsigned HOST_WIDE_INT' and
	HOST_WIDE_INT_PRINT_HEX to print HOST_WIDE_INT.
	* tree-dump.c (dump_pointer): Use 'unsigned long' for %lx.

Index: gcc/cp/ChangeLog
2007-05-18  Geoffrey Keating  <geoffk@apple.com>

	* mangle.c (write_real_cst): Use 'unsigned long' for %lx.

Index: gcc/tree-dump.c
===================================================================
--- gcc/tree-dump.c	(revision 124837)
+++ gcc/tree-dump.c	(working copy)
@@ -166,7 +166,7 @@
 dump_pointer (dump_info_p di, const char *field, void *ptr)
 {
   dump_maybe_newline (di);
-  fprintf (di->stream, "%-4s: %-8lx ", field, (long) ptr);
+  fprintf (di->stream, "%-4s: %-8lx ", field, (unsigned long) ptr);
   di->column += 15;
 }
 
Index: gcc/java/jcf-dump.c
===================================================================
--- gcc/java/jcf-dump.c	(revision 124837)
+++ gcc/java/jcf-dump.c	(working copy)
@@ -138,7 +138,7 @@
   if (flag_print_class_info) \
     fprintf (out, \
              "Magic number: 0x%0lx, minor_version: %ld, major_version: %ld.\n",\
-	     (long) MAGIC, (long) MINOR, (long) MAJOR)
+	     (unsigned long) MAGIC, (long) MINOR, (long) MAJOR)
 
 #define HANDLE_START_CONSTANT_POOL(COUNT) \
   if (flag_print_constant_pool) \
@@ -811,7 +811,7 @@
 	  }
 
 	if (verbosity > 1)
-	  fprintf (out, ", bits = 0x%08lx", (long) JPOOL_UINT (jcf, index));
+	  fprintf (out, ", bits = 0x%08lx", (unsigned long) JPOOL_UINT (jcf, index));
 	
 	break;
       }
@@ -860,7 +860,8 @@
 	    int32 hi, lo;
 	    hi = JPOOL_UINT (jcf, index);
 	    lo = JPOOL_UINT (jcf, index + 1);
-	    fprintf (out, ", bits = 0x%08lx%08lx", (long) hi, (long) lo);
+	    fprintf (out, ", bits = 0x%08lx%08lx", (unsigned long) hi,
+		     (unsigned long) lo);
 	  }
 	break;
       }
Index: gcc/cp/mangle.c
===================================================================
--- gcc/cp/mangle.c	(revision 124837)
+++ gcc/cp/mangle.c	(working copy)
@@ -1340,7 +1340,7 @@
 
       for (; i != limit; i += dir)
 	{
-	  sprintf (buffer, "%08lx", target_real[i]);
+	  sprintf (buffer, "%08lx", (unsigned long) target_real[i]);
 	  write_chars (buffer, 8);
 	}
     }
Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c	(revision 124837)
+++ gcc/dwarf2out.c	(working copy)
@@ -5768,11 +5768,11 @@
   unsigned ix;
 
   print_spaces (outfile);
-  fprintf (outfile, "DIE %4lu: %s\n",
+  fprintf (outfile, "DIE %4ld: %s\n",
 	   die->die_offset, dwarf_tag_name (die->die_tag));
   print_spaces (outfile);
   fprintf (outfile, "  abbrev id: %lu", die->die_abbrev);
-  fprintf (outfile, " offset: %lu\n", die->die_offset);
+  fprintf (outfile, " offset: %ld\n", die->die_offset);
 
   for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
     {
@@ -5820,7 +5820,7 @@
 	      if (AT_ref (a)->die_symbol)
 		fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol);
 	      else
-		fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset);
+		fprintf (outfile, "die -> %ld", AT_ref (a)->die_offset);
 	    }
 	  else
 	    fprintf (outfile, "die -> <null>");
@@ -7091,7 +7091,8 @@
     output_die_symbol (die);
 
   dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)",
-			       die->die_offset, dwarf_tag_name (die->die_tag));
+			       (unsigned long)die->die_offset,
+			       dwarf_tag_name (die->die_tag));
 
   for (ix = 0; VEC_iterate (dw_attr_node, die->die_attr, ix, a); ix++)
     {
@@ -7273,7 +7274,7 @@
   /* Add null byte to terminate sibling list.  */
   if (die->die_child != NULL)
     dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx",
-			 die->die_offset);
+			 (unsigned long) die->die_offset);
 }
 
 /* Output the compilation unit that appears at the beginning of the
Index: gcc/sched-vis.c
===================================================================
--- gcc/sched-vis.c	(revision 124837)
+++ gcc/sched-vis.c	(working copy)
@@ -430,7 +430,10 @@
       if (FLOAT_MODE_P (GET_MODE (x)))
 	real_to_decimal (t, CONST_DOUBLE_REAL_VALUE (x), sizeof (t), 0, 1);
       else
-	sprintf (t, "<0x%lx,0x%lx>", (long) CONST_DOUBLE_LOW (x), (long) CONST_DOUBLE_HIGH (x));
+	sprintf (t,
+		 "<" HOST_WIDE_INT_PRINT_HEX "," HOST_WIDE_INT_PRINT_HEX ">",
+		 (unsigned HOST_WIDE_INT) CONST_DOUBLE_LOW (x),
+		 (unsigned HOST_WIDE_INT) CONST_DOUBLE_HIGH (x));
       cur = safe_concat (buf, cur, t);
       break;
     case CONST_STRING:
============================================================

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: fix some printf mismatches
  2007-05-18 23:05 fix some printf mismatches Geoffrey Keating
@ 2007-05-18 23:08 ` Andrew Pinski
  2007-05-18 23:53   ` Geoffrey Keating
  2007-05-20 23:56   ` Rafael Espindola
  2007-05-18 23:19 ` Joseph S. Myers
  1 sibling, 2 replies; 7+ messages in thread
From: Andrew Pinski @ 2007-05-18 23:08 UTC (permalink / raw)
  To: Geoffrey Keating; +Cc: gcc-patches, Rafael Avila de Espindola

On 5/18/07, Geoffrey Keating <gkeating@apple.com> wrote:
>
> Rafael's patch caused GCC to start warning about using %x with signed
> values.  Although the patch had other problems, this warning in itself
> is not wrong; ISO C doesn't strictly permit this (although it is not a
> problem on any platform I know about).  It turns out that looking for
> places where people have been sloppy about this is pretty good at
> finding other problems, as in the sched-vis change below, so I went
> through and fixed them.

Can you wait a second, these warnings are wrong.  This is what exactly
why the patch was incorrect in the first place.  The original patch
still have other issues, see my email about the regressions on
powerpc-linux-gnu/spu-elf.


-- Pinski

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: fix some printf mismatches
  2007-05-18 23:05 fix some printf mismatches Geoffrey Keating
  2007-05-18 23:08 ` Andrew Pinski
@ 2007-05-18 23:19 ` Joseph S. Myers
  2007-05-19  0:05   ` Geoffrey Keating
  1 sibling, 1 reply; 7+ messages in thread
From: Joseph S. Myers @ 2007-05-18 23:19 UTC (permalink / raw)
  To: Geoffrey Keating; +Cc: gcc-patches, Rafael Avila de Espindola

On Fri, 18 May 2007, Geoffrey Keating wrote:

> is not wrong; ISO C doesn't strictly permit this (although it is not a
> problem on any platform I know about).  It turns out that looking for

Whether ISO C permits it (for values representable in both types) is 
heavily disputed (the question is whether the latitude given for va_arg 
also applies to standard library functions).

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: fix some printf mismatches
  2007-05-18 23:08 ` Andrew Pinski
@ 2007-05-18 23:53   ` Geoffrey Keating
  2007-05-20 23:56   ` Rafael Espindola
  1 sibling, 0 replies; 7+ messages in thread
From: Geoffrey Keating @ 2007-05-18 23:53 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: Geoffrey Keating, gcc-patches, Rafael Avila de Espindola

[-- Attachment #1: Type: text/plain, Size: 947 bytes --]


On 18/05/2007, at 4:07 PM, Andrew Pinski wrote:

> On 5/18/07, Geoffrey Keating <gkeating@apple.com> wrote:
>>
>> Rafael's patch caused GCC to start warning about using %x with signed
>> values.  Although the patch had other problems, this warning in  
>> itself
>> is not wrong; ISO C doesn't strictly permit this (although it is  
>> not a
>> problem on any platform I know about).  It turns out that looking for
>> places where people have been sloppy about this is pretty good at
>> finding other problems, as in the sched-vis change below, so I went
>> through and fixed them.
>
> Can you wait a second, these warnings are wrong.  This is what exactly
> why the patch was incorrect in the first place.

The "them" in "looking for places where people have been sloppy about  
this is pretty good at finding other problems, as in the sched-vis  
change below, so I went through and fixed them" refers to "other  
problems" not the warnings.



[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2462 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: fix some printf mismatches
  2007-05-18 23:19 ` Joseph S. Myers
@ 2007-05-19  0:05   ` Geoffrey Keating
  2007-05-19  0:41     ` Joseph S. Myers
  0 siblings, 1 reply; 7+ messages in thread
From: Geoffrey Keating @ 2007-05-19  0:05 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches, Rafael Avila de Espindola

[-- Attachment #1: Type: text/plain, Size: 630 bytes --]

On 18/05/2007, at 4:19 PM, Joseph S. Myers wrote:

> On Fri, 18 May 2007, Geoffrey Keating wrote:
>
>> is not wrong; ISO C doesn't strictly permit this (although it is  
>> not a
>> problem on any platform I know about).  It turns out that looking for
>
> Whether ISO C permits it (for values representable in both types) is
> heavily disputed (the question is whether the latitude given for  
> va_arg
> also applies to standard library functions).

I'd suggest that if it's heavily disputed, perhaps GCC should warn  
about it by default, and certainly GCC's source code shouldn't rely on  
one of the answers being correct...


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2462 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: fix some printf mismatches
  2007-05-19  0:05   ` Geoffrey Keating
@ 2007-05-19  0:41     ` Joseph S. Myers
  0 siblings, 0 replies; 7+ messages in thread
From: Joseph S. Myers @ 2007-05-19  0:41 UTC (permalink / raw)
  To: Geoffrey Keating; +Cc: gcc-patches, Rafael Avila de Espindola

On Fri, 18 May 2007, Geoffrey Keating wrote:

> On 18/05/2007, at 4:19 PM, Joseph S. Myers wrote:
> 
> > On Fri, 18 May 2007, Geoffrey Keating wrote:
> > 
> > > is not wrong; ISO C doesn't strictly permit this (although it is not a
> > > problem on any platform I know about).  It turns out that looking for
> > 
> > Whether ISO C permits it (for values representable in both types) is
> > heavily disputed (the question is whether the latitude given for va_arg
> > also applies to standard library functions).
> 
> I'd suggest that if it's heavily disputed, perhaps GCC should warn about it by
> default, and certainly GCC's source code shouldn't rely on one of the answers
> being correct...

It is undisputed that the point is purely a theoretical one rather than 
one affecting real implementations.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: fix some printf mismatches
  2007-05-18 23:08 ` Andrew Pinski
  2007-05-18 23:53   ` Geoffrey Keating
@ 2007-05-20 23:56   ` Rafael Espindola
  1 sibling, 0 replies; 7+ messages in thread
From: Rafael Espindola @ 2007-05-20 23:56 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: Geoffrey Keating, gcc-patches

> Can you wait a second, these warnings are wrong.  This is what exactly
> why the patch was incorrect in the first place.  The original patch
> still have other issues, see my email about the regressions on
> powerpc-linux-gnu/spu-elf.

I have no strong opinion if we should warn about this or not, but I
would like to note that with my second patch applied we shouldn't
generating this warnings (don't have a x86 to test right now). If
these warnings are desirable, I think we should find a better way to
implement them. They were only present on architectures with
sizeof(int) == sizeof(long) for example.

> -- Pinski
>


-- 
Rafael Avila de Espindola

Google Ireland Ltd.
Gordon House
Barrow Street
Dublin 4
Ireland

Registered in Dublin, Ireland
Registration Number: 368047

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-05-20 23:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-18 23:05 fix some printf mismatches Geoffrey Keating
2007-05-18 23:08 ` Andrew Pinski
2007-05-18 23:53   ` Geoffrey Keating
2007-05-20 23:56   ` Rafael Espindola
2007-05-18 23:19 ` Joseph S. Myers
2007-05-19  0:05   ` Geoffrey Keating
2007-05-19  0:41     ` Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).