summaryrefslogtreecommitdiff
path: root/gcc/c-family/c-format.c
diff options
context:
space:
mode:
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>2015-02-13 07:56:14 +0000
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>2015-02-13 07:56:14 +0000
commit46173d1b4fdbd7a0df69ff2d0e05802bd5be595b (patch)
tree749b780b2047e9aab9e7b593ac410e7335f5586d /gcc/c-family/c-format.c
parent02acb8f313c9ecf0fe3f47562a32c9dc34f305bd (diff)
downloadgcc-46173d1b4fdbd7a0df69ff2d0e05802bd5be595b.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@220677 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-family/c-format.c')
-rw-r--r--gcc/c-family/c-format.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index faaca093070..2f49b2d2d5c 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