[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #19 from Marek Polacek mpolacek at gcc dot gnu.org ---
Author: mpolacek
Date: Fri Feb 27 14:11:53 2015
New Revision: 221061

URL: https://gcc.gnu.org/viewcvs?rev=221061root=gccview=rev
Log:
PR c/65040
* doc/invoke.texi: Update to reflect that -Wformat=2 doesn't enable
-Wformat-signedness anymore.

* c.opt (Wformat-signedness): Don't enable by -Wformat=2.

* gcc.dg/pr65066.c: Use -Wformat -Wformat-signedness and not
-Wformat=2.

Modified:
trunk/gcc/ChangeLog
trunk/gcc/c-family/ChangeLog
trunk/gcc/c-family/c.opt
trunk/gcc/doc/invoke.texi
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gcc.dg/pr65066.c


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-27 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

Marek Polacek mpolacek at gcc dot gnu.org changed:

   What|Removed |Added

 Status|REOPENED|RESOLVED
 Resolution|--- |FIXED

--- Comment #20 from Marek Polacek mpolacek at gcc dot gnu.org ---
Closing.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-24 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #15 from Richard Biener rguenth at gcc dot gnu.org ---
I'd also say that warnings for formats that do not have a signed form are
useless,
thus for %o, %x and %X.  But I guess you beg to differ.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-24 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #18 from Richard Biener rguenth at gcc dot gnu.org ---
And it was just mentioned that the diagnostic should print

 [-Wformat-signedness]

not

 [-Wformat=]

(or both)


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-24 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #16 from Marek Polacek mpolacek at gcc dot gnu.org ---
Ok, I can fix the integer constant case as well.

(In reply to Richard Biener from comment #15)
 I'd also say that warnings for formats that do not have a signed form are
 useless,
 thus for %o, %x and %X.  But I guess you beg to differ.

I don't know - it wasn't me who implemented this warning, I'm just doing it
less verbose ;).


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-24 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

Richard Biener rguenth at gcc dot gnu.org changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 Resolution|FIXED   |---

--- Comment #14 from Richard Biener rguenth at gcc dot gnu.org ---
#include stdio.h
int main()
{
  printf (%x%u\n, 4, 4);
}
 gcc-5 -Wall t.c -Wformat=2
t.c: In function 'main':
t.c:4:11: warning: format '%x' expects argument of type 'unsigned int', but
argument 2 has type 'int' [-Wformat=]
   printf (%x%u\n, 4, 4);
   ^
t.c:4:11: warning: format '%u' expects argument of type 'unsigned int', but
argument 3 has type 'int' [-Wformat=]

that's undesirable as well (the constant fits in an unsigned int).


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-24 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #17 from Jakub Jelinek jakub at gcc dot gnu.org ---
IMHO the warning is completely useless, but perhaps some people disagree.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-16 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #13 from Marek Polacek mpolacek at gcc dot gnu.org ---
Note that this patch had a followup: PR65066.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-14 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #10 from Marek Polacek mpolacek at gcc dot gnu.org ---
That's because on your architecture char is signed by default.  Try adding
unsigned or using -funsigned-char and the warning should be gone.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-14 Thread jirislaby at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #9 from Jiri Slaby jirislaby at gmail dot com ---
What about this?

#include stdio.h

void x(char *ch)
{
printf(%x\n, ch[10]);
}

It still produces the warning. (I cannot reopen as I am not a reporter.)


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-14 Thread jirislaby at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #12 from Jiri Slaby jirislaby at gmail dot com ---
(In reply to Marek Polacek from comment #10)
 That's because on your architecture char is signed by default.  Try adding
 unsigned or using -funsigned-char and the warning should be gone.

Ok, I wanted to make sure, that the format string is really wrong here. It
should be %hhx.

Ouch, that will be pain to fix all those 400 bad format strings in grub2, given
they use Werror  WFormat :D.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-14 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #11 from Jakub Jelinek jakub at gcc dot gnu.org ---
-funsigned-char is an option that shouldn't be used without serious
consideration.
That said, I think in that case the warning is intentional, you are indeed
passing a signed value to unsigned format.  If you don't care about that, don't
use -Wformat=2 or use -Wno-format-signedness.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-12 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #4 from Jakub Jelinek jakub at gcc dot gnu.org ---
(In reply to Marek Polacek from comment #2)
 Taking.  I think check_format_types needs a small tweak to look thru
 NOP_EXPRs.

Well, more like do some lame VR computation and not warn if the signedness
doesn't really matter.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-12 Thread mark at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

Mark Wielaard mark at gcc dot gnu.org changed:

   What|Removed |Added

 CC||mark at gcc dot gnu.org

--- Comment #5 from Mark Wielaard mark at gcc dot gnu.org ---
Note that this also triggers for code that looks just fine to the user:

#include stdio.h
#include inttypes.h

int
main (int argc, char **argv)
{
  uint8_t u = 16;
  printf (u = %02 PRIx8 \n, u);
  return 0;
}

m.c: In function ‘main’:
m.c:8:11: warning: format ‘%x’ expects argument of type ‘unsigned int’, but
argument 2 has type ‘int’ [-Wformat=]
   printf (u = %02 PRIx8 \n, u);
   ^

Which is somewhat surprising since the user explicitly matched the type and
format specifier.

This is caused by the definition of the PRIx format specifiers all mapping back
to x in inttypes.h

/* lowercase hexadecimal notation.  */
# define PRIx8  x
# define PRIx16 x
# define PRIx32 x

[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-12 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

Marek Polacek mpolacek at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

--- Comment #2 from Marek Polacek mpolacek at gcc dot gnu.org ---
Taking.  I think check_format_types needs a small tweak to look thru NOP_EXPRs.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-12 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

Jakub Jelinek jakub at gcc dot gnu.org changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek jakub at gcc dot gnu.org ---
Started with r209328.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-12 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

Richard Biener rguenth at gcc dot gnu.org changed:

   What|Removed |Added

   Target Milestone|--- |5.0


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-12 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

Marek Polacek mpolacek at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2015-02-12
 CC||mpolacek at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Marek Polacek mpolacek at gcc dot gnu.org ---
Confirmed.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-12 Thread fche at redhat dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

Frank Ch. Eigler fche at redhat dot com changed:

   What|Removed |Added

 CC||fche at redhat dot com

--- Comment #6 from Frank Ch. Eigler fche at redhat dot com ---
Note that printf is a varargs function, and is defined to widen
smaller-than-int parameters to at least int.  unsigned short is
subsumed in int.


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-12 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

--- Comment #7 from Marek Polacek mpolacek at gcc dot gnu.org ---
Author: mpolacek
Date: Fri Feb 13 07:56:14 2015
New Revision: 220677

URL: https://gcc.gnu.org/viewcvs?rev=220677root=gccview=rev
Log:
PR c/65040
* c-format.c (check_format_types): Don't warn about different
signedness if the original value is in the range of WANTED_TYPE.

* c-c++-common/pr65040.c: New test.

Added:
trunk/gcc/testsuite/c-c++-common/pr65040.c
Modified:
trunk/gcc/c-family/ChangeLog
trunk/gcc/c-family/c-format.c
trunk/gcc/testsuite/ChangeLog


[Bug c/65040] [5 Regression] gcc-5 -Wformat broken

2015-02-12 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65040

Marek Polacek mpolacek at gcc dot gnu.org changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #8 from Marek Polacek mpolacek at gcc dot gnu.org ---
Should be better now.