+2017-07-27 Marek Polacek <polacek@redhat.com>
+
+ PR c/81417
+ * c-warn.c (warn_for_sign_compare): Tweak the warning message. Print
+ the types.
+
2017-07-27 Jakub Jelinek <jakub@redhat.com>
* c-attribs.c (c_common_attribute_table): Add noipa attribute.
c_common_signed_type (base_type)))
/* OK */;
else
- warning_at (location,
- OPT_Wsign_compare,
- "comparison between signed and unsigned integer expressions");
+ warning_at (location, OPT_Wsign_compare,
+ "comparison of integer expressions of different "
+ "signedness: %qT and %qT", TREE_TYPE (orig_op0),
+ TREE_TYPE (orig_op1));
}
/* Warn if two unsigned values are being compared in a size larger
+2017-07-27 Marek Polacek <polacek@redhat.com>
+
+ PR c/81417
+ * c-c++-common/Wsign-compare-1.c: New test.
+ * g++.dg/warn/Wsign-compare-2.C: Update dg-warning.
+ * g++.dg/warn/Wsign-compare-4.C: Likewise.
+ * g++.dg/warn/Wsign-compare-6.C: Likewise.
+ * g++.dg/warn/compare1.C: Likewise.
+ * gcc.dg/compare1.c: Likewise.
+ * gcc.dg/compare2.c: Likewise.
+ * gcc.dg/compare4.c: Likewise.
+ * gcc.dg/compare5.c: Likewise.
+ * gcc.dg/pr35430.c: Likewise.
+ * gcc.dg/pr60087.c: Likewise.
+
2017-07-27 Peter Bergner <bergner@vnet.ibm.com>
PR middle-end/81564
--- /dev/null
+/* PR c/81417 */
+/* { dg-do compile } */
+/* { dg-options "-Wsign-compare" } */
+
+int
+fn1 (signed int a, unsigned int b)
+{
+ return a < b; /* { dg-warning "comparison of integer expressions of different signedness: 'int' and 'unsigned int'" } */
+}
+
+int
+fn2 (signed int a, unsigned int b)
+{
+ return b < a; /* { dg-warning "comparison of integer expressions of different signedness: 'unsigned int' and 'int'" } */
+}
+
+int
+fn3 (signed long int a, unsigned long int b)
+{
+ return b < a; /* { dg-warning "comparison of integer expressions of different signedness: 'long unsigned int' and 'long int'" } */
+}
+
+int
+fn4 (signed short int a, unsigned int b)
+{
+ return b < a; /* { dg-warning "comparison of integer expressions of different signedness: 'unsigned int' and 'short int'" } */
+}
+
+int
+fn5 (unsigned int a, signed int b)
+{
+ return a < b; /* { dg-warning "comparison of integer expressions of different signedness: 'unsigned int' and 'int'" } */
+}
foo (__complex__ int i)
{
i == 0u;
- i == ~1u; // { dg-warning "comparison between signed and unsigned integer expressions" }
+ i == ~1u; // { dg-warning "comparison of integer expressions of different signedness" }
}
int foo(unsigned int *a, int b)
{
- return (*a) <= b; // { dg-warning "comparison between signed and unsigned" }
+ return (*a) <= b; // { dg-warning "comparison of integer expressions of different signedness" }
}
int bar(unsigned int *a, int b)
{
- return *a <= b; // { dg-warning "comparison between signed and unsigned" }
+ return *a <= b; // { dg-warning "comparison of integer expressions of different signedness" }
}
int i = 5;
int const ic = 5;
- i < 5u; // { dg-warning "5:comparison between signed and unsigned" }
+ i < 5u; // { dg-warning "5:comparison of integer expressions of different signedness" }
ic < 5u;
FIVE < 5u;
}
int f(unsigned a, int b)
{
- return a < b; /* { dg-warning "signed and unsigned" } */
+ return a < b; /* { dg-warning "comparison of integer expressions of different signedness" } */
}
int i(enum mm2 x)
{
- return x == (tf?DI2:-1); /* { dg-warning "signed and unsigned" "case 4" } */
+ return x == (tf?DI2:-1); /* { dg-warning "different signedness" "case 4" } */
}
/* ?: branches are signed constants. */
x > (tf?64:-1); /* { dg-bogus "signed and unsigned" "case 5" } */
- y > (tf?64:-1); /* { dg-warning "signed and unsigned" "case 6" } */
+ y > (tf?64:-1); /* { dg-warning "different signedness" "case 6" } */
/* ?: branches are (recursively) signed constants. */
x > (tf?64:(tf?128:-1)); /* { dg-bogus "signed and unsigned" "case 7" } */
- y > (tf?64:(tf?128:-1)); /* { dg-warning "signed and unsigned" "case 8" } */
+ y > (tf?64:(tf?128:-1)); /* { dg-warning "different signedness" "case 8" } */
/* Statement expression. */
x > ({tf; 64;}); /* { dg-bogus "signed and unsigned" "case 9" } */
/* Statement expression with signed ?:. */
x > ({tf; tf?64:-1;}); /* { dg-bogus "signed and unsigned" "case 13" } */
- y > ({tf; tf?64:-1;}); /* { dg-warning "signed and unsigned" "case 14" } */
+ y > ({tf; tf?64:-1;}); /* { dg-warning "different signedness" "case 14" } */
/* Statement expression with recursive signed ?:. */
x > ({tf; tf?64:(tf?128:-1);}); /* { dg-bogus "signed and unsigned" "case 15" } */
- y > ({tf; tf?64:(tf?128:-1);}); /* { dg-warning "signed and unsigned" "case 16" } */
+ y > ({tf; tf?64:(tf?128:-1);}); /* { dg-warning "different signedness" "case 16" } */
/* ?: branches are constants. */
tf ? x : (tf?64:32); /* { dg-bogus "conditional expression" "case 17" } */
{
/* A COMPOUND_EXPR is non-negative if the last element is known to
be non-negative. */
- if (u < (bar(), -1)) /*{ dg-warning "9:signed and unsigned" "COMPOUND_EXPR" }*/
+ if (u < (bar(), -1)) /*{ dg-warning "9:different signedness" "COMPOUND_EXPR" }*/
return x;
if (u < (bar(), 10))
return x;
/* A MODIFY_EXPR is non-negative if the new value is known to be
non-negative. */
- if (u < (x = -1)) /* { dg-warning "9:signed and unsigned" "MODIFY_EXPR" } */
+ if (u < (x = -1)) /* { dg-warning "9:different signedness" "MODIFY_EXPR" } */
return x;
if (u < (x = 10))
return x;
{
/* A *_DIV_EXPR is non-negative if both operands are. */
- if (u < ((x=-22)/33)) /* { dg-warning "signed and unsigned" "DIV_EXPR" } */
+ if (u < ((x=-22)/33)) /* { dg-warning "different signedness" "DIV_EXPR" } */
return x;
if (u < ((x=22)/33))
/* A *_MOD_EXPR is non-negative if the first operand is. */
- if (u < ((x=-22)%33)) /* { dg-warning "signed and unsigned" "MOD_EXPR" } */
+ if (u < ((x=-22)%33)) /* { dg-warning "different signedness" "MOD_EXPR" } */
return x;
if (u < ((x=22)%-33))
foo (__complex__ int i)
{
i == 0u;
- i == ~1u; /* { dg-warning "comparison between signed and unsigned integer expressions" } */
+ i == ~1u; /* { dg-warning "comparison of integer expressions of different signedness" } */
}
b = 0 != ~uc; /* { dg-warning "9:promoted ~unsigned is always non-zero" } */
b = 2 != ~uc; /* { dg-warning "9:comparison of promoted ~unsigned with constant" } */
b = uc == ~uc; /* { dg-warning "10:comparison of promoted ~unsigned with unsigned" } */
- b = i == ui; /* { dg-warning "9:comparison between signed and unsigned integer expressions" } */
+ b = i == ui; /* { dg-warning "9:comparison of integer expressions of different signedness" } */
}