aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2015-02-13 07:56:14 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2015-02-13 07:56:14 +0000
commitfa008882f27cd22c65dcbffa78f05c81ebb23e66 (patch)
tree749b780b2047e9aab9e7b593ac410e7335f5586d
parentfc06280eb11be2316b12a51112cb62614141f32d (diff)
downloadgcc-fa008882f27cd22c65dcbffa78f05c81ebb23e66.zip
gcc-fa008882f27cd22c65dcbffa78f05c81ebb23e66.tar.gz
gcc-fa008882f27cd22c65dcbffa78f05c81ebb23e66.tar.bz2
re PR c/65040 (gcc-5 -Wformat broken)
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. From-SVN: r220677
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-format.c17
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/c-c++-common/pr65040.c21
4 files changed, 47 insertions, 2 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index c63384b..804c1db 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2015-02-13 Marek Polacek <polacek@redhat.com>
+
+ 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.
+
2015-02-12 Jason Merrill <jason@redhat.com>
PR c++/64956
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index faaca09..2f49b2d 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -2456,8 +2456,7 @@ check_format_types (location_t loc, format_wanted_type *types)
cur_type = TYPE_MAIN_VARIANT (cur_type);
/* Check whether the argument type is a character type. This leniency
- only applies to certain formats, flagged with 'c'.
- */
+ only applies to certain formats, flagged with 'c'. */
if (types->char_lenient_flag)
char_type_flag = (cur_type == char_type_node
|| cur_type == signed_char_type_node
@@ -2486,6 +2485,20 @@ check_format_types (location_t loc, format_wanted_type *types)
? wanted_type == c_common_unsigned_type (cur_type)
: wanted_type == c_common_signed_type (cur_type)))
continue;
+ /* Don't warn about differences merely in signedness if we know
+ that the current type is integer-promoted and its original type
+ was unsigned such as that it is in the range of WANTED_TYPE. */
+ if (TREE_CODE (wanted_type) == INTEGER_TYPE
+ && TREE_CODE (cur_type) == INTEGER_TYPE
+ && warn_format_signedness
+ && TYPE_UNSIGNED (wanted_type)
+ && TREE_CODE (cur_param) == NOP_EXPR)
+ {
+ tree t = TREE_TYPE (TREE_OPERAND (cur_param, 0));
+ if (TYPE_UNSIGNED (t)
+ && cur_type == lang_hooks.types.type_promotes_to (t))
+ continue;
+ }
/* Likewise, "signed char", "unsigned char" and "char" are
equivalent but the above test won't consider them equivalent. */
if (wanted_type == char_type_node
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 729f92d..d958264 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-02-13 Marek Polacek <polacek@redhat.com>
+
+ PR c/65040
+ * c-c++-common/pr65040.c: New test.
+
2015-02-13 Bin Cheng <bin.cheng@arm.com>
PR tree-optimization/64705
diff --git a/gcc/testsuite/c-c++-common/pr65040.c b/gcc/testsuite/c-c++-common/pr65040.c
new file mode 100644
index 0000000..80da8f9
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr65040.c
@@ -0,0 +1,21 @@
+/* PR c/65040 */
+/* { dg-do compile } */
+/* { dg-options "-Wformat -Wformat-signedness" } */
+
+unsigned char uc;
+signed char sc;
+unsigned short us;
+signed short ss;
+unsigned int u;
+int i;
+
+void
+foo (void)
+{
+ __builtin_printf ("%u\n", uc); /* { dg-bogus "expects argument of type" } */
+ __builtin_printf ("%u\n", sc); /* { dg-warning "expects argument of type" } */
+ __builtin_printf ("%u\n", us); /* { dg-bogus "expects argument of type" } */
+ __builtin_printf ("%u\n", ss); /* { dg-warning "expects argument of type" } */
+ __builtin_printf ("%u\n", u); /* { dg-bogus "expects argument of type" } */
+ __builtin_printf ("%u\n", i); /* { dg-warning "expects argument of type" } */
+}