forked from OSchip/llvm-project
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. llvm-svn: 41343
This commit is contained in:
parent
8ddb23a6c5
commit
247ef955bc
|
@ -180,13 +180,16 @@ void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val,
|
||||||
// If this is a truncation, check for overflow.
|
// If this is a truncation, check for overflow.
|
||||||
llvm::APSInt ConvVal(Val);
|
llvm::APSInt ConvVal(Val);
|
||||||
ConvVal.trunc(NewWidth);
|
ConvVal.trunc(NewWidth);
|
||||||
|
ConvVal.setIsSigned(NewSign);
|
||||||
ConvVal.extend(Val.getBitWidth());
|
ConvVal.extend(Val.getBitWidth());
|
||||||
|
ConvVal.setIsSigned(Val.isSigned());
|
||||||
if (ConvVal != Val)
|
if (ConvVal != Val)
|
||||||
Diag(Loc, DiagID, Val.toString(), ConvVal.toString());
|
Diag(Loc, DiagID, Val.toString(), ConvVal.toString());
|
||||||
|
|
||||||
// Regardless of whether a diagnostic was emitted, really do the
|
// Regardless of whether a diagnostic was emitted, really do the
|
||||||
// truncation.
|
// truncation.
|
||||||
Val.trunc(NewWidth);
|
Val.trunc(NewWidth);
|
||||||
|
Val.setIsSigned(NewSign);
|
||||||
} else if (NewSign != Val.isSigned()) {
|
} else if (NewSign != Val.isSigned()) {
|
||||||
// Convert the sign to match the sign of the condition. This can cause
|
// Convert the sign to match the sign of the condition. This can cause
|
||||||
// overflow as well: unsigned(INTMIN)
|
// overflow as well: unsigned(INTMIN)
|
||||||
|
|
Loading…
Reference in New Issue