Commit 06bd22f6 by Marek Polacek Committed by Marek Polacek

re PR c/81417 (-Wsign-compare should print types being compared)

	PR c/81417
	* c-warn.c (warn_for_sign_compare): Tweak the warning message.  Print
	the types.

	* 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.

From-SVN: r250630
parent 27c8b49b
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.
......
......@@ -1891,9 +1891,10 @@ warn_for_sign_compare (location_t location,
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
......
/* 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'" } */
}
......@@ -6,5 +6,5 @@ void
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" }
}
......@@ -3,10 +3,10 @@
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" }
}
......@@ -8,7 +8,7 @@ int main()
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;
}
......@@ -6,5 +6,5 @@
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" } */
}
......@@ -37,5 +37,5 @@ int h(enum mm2 x)
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" } */
}
......@@ -18,11 +18,11 @@ void f(int x, unsigned int y)
/* ?: 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" } */
......@@ -34,11 +34,11 @@ void f(int x, unsigned int y)
/* 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" } */
......
......@@ -10,7 +10,7 @@ int foo(int x, int y, unsigned u)
{
/* 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;
......@@ -34,7 +34,7 @@ int foo(int x, int y, unsigned u)
/* 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;
......
......@@ -10,7 +10,7 @@ int foo(int x, int y, unsigned u)
{
/* 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))
......@@ -25,7 +25,7 @@ int foo(int x, int y, unsigned u)
/* 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))
......
......@@ -6,5 +6,5 @@ void
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" } */
}
......@@ -10,5 +10,5 @@ foo (unsigned int ui, int i)
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" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment