]> granicus.if.org Git - clang/commitdiff
Make the integer-range analysis recognize ^= correctly,
authorJohn McCall <rjmccall@apple.com>
Wed, 13 Jul 2011 06:35:24 +0000 (06:35 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 13 Jul 2011 06:35:24 +0000 (06:35 +0000)
and (while I'm at it) teach it to grok the results of simple
assignments.

The first is PR10336.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135034 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/compare.c

index 8bad032911f995a1f3cdc3ef03c4b4172ec9f786..267cda8f4016ca935873eac6d22bb82906201051 100644 (file)
@@ -2586,15 +2586,24 @@ IntRange GetExprRange(ASTContext &C, Expr *E, unsigned MaxWidth) {
     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:
index 5221b172a602720d0865f26af3da0f51b0c8a514..cd973d4885c7c141af470c4d597a8e3efe4bb01d 100644 (file)
@@ -312,3 +312,18 @@ int rdar8511238() {
     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));
+}