]> granicus.if.org Git - clang/commitdiff
Don't diagnose overflow in case statements when the conversion is a
authorDouglas Gregor <dgregor@apple.com>
Thu, 18 Feb 2010 00:56:01 +0000 (00:56 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 18 Feb 2010 00:56:01 +0000 (00:56 +0000)
signed<->unsigned conversion with the same bit width. Fixes
<rdar://problem/7658121>.

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

lib/Sema/SemaStmt.cpp
test/Sema/switch.c

index d9f5b38eb90664888e92c67890d00042556e9d2d..bdd0962a11bfd03d8e78e3fbfacad41f0aaedc32 100644 (file)
@@ -340,11 +340,11 @@ void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val,
   } else if (NewSign != Val.isSigned()) {
     // Convert the sign to match the sign of the condition.  This can cause
     // overflow as well: unsigned(INTMIN)
+    // We don't diagnose this overflow, because it is implementation-defined 
+    // behavior.
+    // FIXME: Introduce a second, default-ignored warning for this case?
     llvm::APSInt OldVal(Val);
     Val.setIsSigned(NewSign);
-
-    if (Val.isNegative())  // Sign bit changes meaning.
-      Diag(Loc, DiagID) << OldVal.toString(10) << Val.toString(10);
   }
 }
 
index 9905c4b025f7ed96c1025c53191c2302eac1854b..213cd0a75be55e6dacba607b406fcf891c70700d 100644 (file)
@@ -240,3 +240,17 @@ int test13(my_type_t t) {
   }
   return -1;
 }
+
+// <rdar://problem/7658121>
+enum {
+  EC0 = 0xFFFF0000,
+  EC1 = 0xFFFF0001,
+};
+
+int test14(int a) {
+  switch(a) {
+  case EC0: return 0;
+  case EC1: return 1;
+  }
+  return 0;
+}