]> granicus.if.org Git - clang/commitdiff
Don't warn about case-value conversions from a negative value to a
authorDouglas Gregor <dgregor@apple.com>
Mon, 1 Mar 2010 01:04:55 +0000 (01:04 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 1 Mar 2010 01:04:55 +0000 (01:04 +0000)
larger unsigned value, since this is implementation-defined
behavior. (We previously suppressed this warning when converting from
a signed value to an unsigned value of the same size).

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

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

index bdd0962a11bfd03d8e78e3fbfacad41f0aaedc32..540189cd830788243bc3df44fe5f179c56eddf9b 100644 (file)
@@ -314,15 +314,13 @@ void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val,
   // Perform a conversion to the promoted condition type if needed.
   if (NewWidth > Val.getBitWidth()) {
     // If this is an extension, just do it.
-    llvm::APSInt OldVal(Val);
     Val.extend(NewWidth);
-
-    // If the input was signed and negative and the output is unsigned,
-    // warn.
-    if (!NewSign && OldVal.isSigned() && OldVal.isNegative())
-      Diag(Loc, DiagID) << OldVal.toString(10) << Val.toString(10);
-
     Val.setIsSigned(NewSign);
+
+    // If the input was signed and negative and the output is
+    // unsigned, don't bother to warn: this is implementation-defined
+    // behavior.
+    // FIXME: Introduce a second, default-ignored warning for this case?
   } else if (NewWidth < Val.getBitWidth()) {
     // If this is a truncation, check for overflow.
     llvm::APSInt ConvVal(Val);
index 213cd0a75be55e6dacba607b406fcf891c70700d..e63a1942bba5a2c64553b4756f9b253a3b850a24 100644 (file)
@@ -254,3 +254,10 @@ int test14(int a) {
   }
   return 0;
 }
+
+void f1(unsigned x) {
+  switch (x) {
+  case -1: break;
+  default: break;
+  }
+}