+2020-01-23 Jason Merrill <jason@redhat.com>
+
+ * c-warn.c (conversion_warning): Change -Wsign-conversion handling.
+
2020-01-23 Martin Sebor <msebor@redhat.com>
PR c/84919
for (int i = 0; i < arith_ops; ++i)
{
tree op = TREE_OPERAND (expr, i);
- tree opr = convert (type, op);
/* Avoid -Wsign-conversion for (unsigned)(x + (-1)). */
- bool minus = TREE_CODE (expr) == PLUS_EXPR && i == 1;
- if (unsafe_conversion_p (type, op, opr, !minus))
+ if (TREE_CODE (expr) == PLUS_EXPR && i == 1
+ && INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
+ && TREE_CODE (op) == INTEGER_CST
+ && tree_int_cst_sgn (op) < 0)
+ op = fold_build1 (NEGATE_EXPR, TREE_TYPE (op), op);
+ tree opr = convert (type, op);
+ if (unsafe_conversion_p (type, op, opr, true))
goto op_unsafe;
}
/* The operands seem safe, we might still want to warn if
+2020-01-23 Jason Merrill <jason@redhat.com>
+
+ * lib/target-supports.exp (check_effective_target_unsigned_char):
+ New.
+
2020-01-23 Jakub Jelinek <jakub@redhat.com>
PR target/93376
c *= 2; /* { dg-warning "conversion" } */
c *= c2; /* { dg-warning "conversion" } */
c /= 2;
- c /= c2; /* { dg-warning "conversion" } */
+ /* If char is unsigned we avoid promoting to int. */
+ c /= c2; /* { dg-warning "conversion" "" { target { ! unsigned_char } } } */
c %= 2;
- c %= c2; /* { dg-warning "conversion" } */
+ c %= c2; /* { dg-warning "conversion" "" { target { ! unsigned_char } } } */
c = -c2; /* { dg-warning "conversion" } */
c = ~c2; /* { dg-warning "conversion" } */
c = c2++;
}]
}
+# Return 1 iff target has unsigned plain 'char' by default.
+
+proc check_effective_target_unsigned_char {} {
+ return [check_no_compiler_messages unsigned_char assembly {
+ char ar[(char)-1];
+ }]
+}
+
proc check_effective_target_powerpc_popcntb_ok { } {
return [check_cached_effective_target powerpc_popcntb_ok {