[cfe-commits] r146634 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/compare.c

Eli Friedman eli.friedman at gmail.com
Wed Dec 14 18:41:53 PST 2011


Author: efriedma
Date: Wed Dec 14 20:41:52 2011
New Revision: 146634

URL: http://llvm.org/viewvc/llvm-project?rev=146634&view=rev
Log:
Enhance the -Wsign-compare handling to suppress the -Wsign-compare warning in the case of a shifted bitfield.  PR11572.


Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/compare.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=146634&r1=146633&r2=146634&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Dec 14 20:41:52 2011
@@ -3257,7 +3257,7 @@
   // 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());

Modified: cfe/trunk/test/Sema/compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=146634&r1=146633&r2=146634&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compare.c (original)
+++ cfe/trunk/test/Sema/compare.c Wed Dec 14 20:41:52 2011
@@ -327,3 +327,9 @@
   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
+}





More information about the cfe-commits mailing list