Enhance the -Wsign-compare handling to suppress the -Wsign-compare warning in the case of a shifted bitfield. PR11572.

llvm-svn: 146634
This commit is contained in:
Eli Friedman 2011-12-15 02:41:52 +00:00
parent a2510070ee
commit 8349dc1fd6
2 changed files with 7 additions and 1 deletions

View File

@ -3257,7 +3257,7 @@ IntRange GetExprRange(ASTContext &C, Expr *E, unsigned MaxWidth) {
// user has an explicit widening cast, we should treat the value as
// being of the new, wider type.
if (ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(E)) {
if (CE->getCastKind() == CK_NoOp)
if (CE->getCastKind() == CK_NoOp || CE->getCastKind() == CK_LValueToRValue)
return GetExprRange(C, CE->getSubExpr(), MaxWidth);
IntRange OutputTypeRange = IntRange::forValueOfType(C, CE->getType());

View File

@ -327,3 +327,9 @@ void test10(void) {
b = (si == (ui = sl)); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}}
b = (si == (ui = sl&15));
}
// PR11572
struct test11S { unsigned x : 30; };
int test11(unsigned y, struct test11S *p) {
return y > (p->x >> 24); // no-warning
}