]> granicus.if.org Git - clang/commitdiff
in the truncation case, make sure to propagate the sign correctly, this
authorChris Lattner <sabre@nondot.org>
Thu, 23 Aug 2007 22:08:35 +0000 (22:08 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 23 Aug 2007 22:08:35 +0000 (22:08 +0000)
fixes an assertion on:
void f (int z) { switch (z) { case ~0ULL: case -1: return; } }

testcase from Neil.

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

Sema/SemaStmt.cpp

index dff057456e28aa4a64ea4a4c12fcb3fe1db60e19..1895724097448a9609eb267fc989dd5be0b0020f 100644 (file)
@@ -180,13 +180,16 @@ void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val,
     // If this is a truncation, check for overflow.
     llvm::APSInt ConvVal(Val);
     ConvVal.trunc(NewWidth);
+    ConvVal.setIsSigned(NewSign);
     ConvVal.extend(Val.getBitWidth());
+    ConvVal.setIsSigned(Val.isSigned());
     if (ConvVal != Val)
       Diag(Loc, DiagID, Val.toString(), ConvVal.toString());
     
     // Regardless of whether a diagnostic was emitted, really do the
     // truncation.
     Val.trunc(NewWidth);
+    Val.setIsSigned(NewSign);
   } else if (NewSign != Val.isSigned()) {
     // Convert the sign to match the sign of the condition.  This can cause
     // overflow as well: unsigned(INTMIN)