From: Chris Lattner Date: Thu, 23 Aug 2007 22:08:35 +0000 (+0000) Subject: in the truncation case, make sure to propagate the sign correctly, this X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2137ae3f1bd0aadb0552189af2824a324ffaa69;p=clang in the truncation case, make sure to propagate the sign correctly, this 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 --- diff --git a/Sema/SemaStmt.cpp b/Sema/SemaStmt.cpp index dff057456e..1895724097 100644 --- a/Sema/SemaStmt.cpp +++ b/Sema/SemaStmt.cpp @@ -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)