PR5207: Change APInt methods trunc(), sext(), zext(), sextOrTrunc() and
zextOrTrunc(), and APSInt methods extend(), extOrTrunc() and new method
trunc(), to be const and to return a new value instead of modifying the
object in place.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121121 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index d6aa4ce..f53086e 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -2243,7 +2243,7 @@
return IntRange(value.getMinSignedBits(), false);
if (value.getBitWidth() > MaxWidth)
- value.trunc(MaxWidth);
+ value = value.trunc(MaxWidth);
// isNonNegative() just checks the sign bit without considering
// signedness.
@@ -2656,16 +2656,15 @@
if (OriginalWidth <= FieldWidth)
return false;
- llvm::APSInt TruncatedValue = Value;
- TruncatedValue.trunc(FieldWidth);
+ llvm::APSInt TruncatedValue = Value.trunc(FieldWidth);
// It's fairly common to write values into signed bitfields
// that, if sign-extended, would end up becoming a different
// value. We don't want to warn about that.
if (Value.isSigned() && Value.isNegative())
- TruncatedValue.sext(OriginalWidth);
+ TruncatedValue = TruncatedValue.sext(OriginalWidth);
else
- TruncatedValue.zext(OriginalWidth);
+ TruncatedValue = TruncatedValue.zext(OriginalWidth);
if (Value == TruncatedValue)
return false;
@@ -2712,7 +2711,7 @@
llvm::APSInt ValueInRange = Value;
ValueInRange.setIsSigned(!Range.NonNegative);
- ValueInRange.trunc(Range.Width);
+ ValueInRange = ValueInRange.trunc(Range.Width);
return ValueInRange.toString(10);
}