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

John McCall rjmccall at apple.com
Tue Jul 12 23:35:24 PDT 2011


Author: rjmccall
Date: Wed Jul 13 01:35:24 2011
New Revision: 135034

URL: http://llvm.org/viewvc/llvm-project?rev=135034&view=rev
Log:
Make the integer-range analysis recognize ^= correctly,
and (while I'm at it) teach it to grok the results of simple
assignments.

The first is PR10336.


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=135034&r1=135033&r2=135034&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Jul 13 01:35:24 2011
@@ -2586,15 +2586,24 @@
     case BO_NE:
       return IntRange::forBoolType();
 
-    // The type of these compound assignments is the type of the LHS,
-    // so the RHS is not necessarily an integer.
+    // The type of the assignments is the type of the LHS, so the RHS
+    // is not necessarily the same type.
     case BO_MulAssign:
     case BO_DivAssign:
     case BO_RemAssign:
     case BO_AddAssign:
     case BO_SubAssign:
+    case BO_XorAssign:
+    case BO_OrAssign:
+      // TODO: bitfields?
       return IntRange::forValueOfType(C, E->getType());
 
+    // Simple assignments just pass through the RHS, which will have
+    // been coerced to the LHS type.
+    case BO_Assign:
+      // TODO: bitfields?
+      return GetExprRange(C, BO->getRHS(), MaxWidth);
+
     // Operations with opaque sources are black-listed.
     case BO_PtrMemD:
     case BO_PtrMemI:

Modified: cfe/trunk/test/Sema/compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=135034&r1=135033&r2=135034&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compare.c (original)
+++ cfe/trunk/test/Sema/compare.c Wed Jul 13 01:35:24 2011
@@ -312,3 +312,18 @@
     return 0;
   return 20;
 }
+
+// PR10336
+int test9(int sv, unsigned uv, long slv) {
+  return sv == (uv ^= slv); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}}
+}
+
+void test10(void) {
+  int si;
+  unsigned int ui;
+  long sl;
+
+  _Bool b;
+  b = (si == (ui = sl)); // expected-warning {{comparison of integers of different signs: 'int' and 'unsigned int'}}
+  b = (si == (ui = sl&15));
+}





More information about the cfe-commits mailing list