New testcase (compare2.c) for bogus -Wsign-compare warnings
Kaveh R. Ghazi
ghazi@caip.rutgers.edu
Thu Apr 6 09:46:00 GMT 2000
Bootstraps have recently exposed another limitation of the
sign-compare warnings. Gcc normally excuses "(unsigned) > 64", but it
does not excuse "(unsigned) > (expr ? 64 : 32)".
IMHO, gcc should be able to check that the branches of a ?: stmt are
INTEGER_CST and int_fits_type_p() and let those cases pass also.
Ditto for statement expressions. Ditto for subexpressions containing
these constructs.
Admittedly, I'm not volunteering to supply a patch to gcc to allow
this. But I'm hoping a testcase might inspire someone. :-)
Okay to install as gcc.dg/compare2.c ?
--Kaveh
/* Test for a bogus warning on comparison between signed and unsigned.
This was inspired by code in gcc. */
/* { dg-do compile } */
/* { dg-options "-Wsign-compare" } */
int tf = 1;
void f(int x, unsigned int y)
{
/* ?: branches are constants. */
x > (tf?64:128); /* { dg-bogus "signed and unsigned" "case 1" } */
y > (tf?64:128); /* { dg-bogus "signed and unsigned" "case 2" } */
/* ?: branches are constants. */
x > (tf?64:(tf?128:256)); /* { dg-bogus "signed and unsigned" "case 3" } */
y > (tf?64:(tf?128:256)); /* { dg-bogus "signed and unsigned" "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" } */
/* ?: branches are 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" } */
/* Statement expression. */
x > ({tf; 64;}); /* { dg-bogus "signed and unsigned" "case 9" } */
y > ({tf; 64;}); /* { dg-bogus "signed and unsigned" "case 10" } */
/* Statement expression with ?: . */
x > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "signed and unsigned" "case 11" } */
y > ({tf; tf?64:(tf?128:256);}); /* { dg-bogus "signed and unsigned" "case 12" } */
/* 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" } */
/* Statement expression with 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" } */
}
More information about the Gcc-patches
mailing list