aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorJay Foad <jay.foad@gmail.com>2010-12-07 08:25:34 +0000
committerJay Foad <jay.foad@gmail.com>2010-12-07 08:25:34 +0000
commit9f71a8f4c7a182a5236da9e747d57cc1d1bd24c2 (patch)
treede2e74ed442ebccd54b82089e7953960c93a27ec /lib/CodeGen/CGExprConstant.cpp
parentdd182ff10b9145e432dea1fd2fb67100ccca3b10 (diff)
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
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--lib/CodeGen/CGExprConstant.cpp28
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index 9002253e72..51b1de37a9 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -142,11 +142,11 @@ void ConstStructBuilder::AppendBitField(const FieldDecl *Field,
// constants are cast to bool, and because clang is not enforcing bitfield
// width limits.
if (FieldSize > FieldValue.getBitWidth())
- FieldValue.zext(FieldSize);
+ FieldValue = FieldValue.zext(FieldSize);
// Truncate the size of FieldValue to the bit field size.
if (FieldSize < FieldValue.getBitWidth())
- FieldValue.trunc(FieldSize);
+ FieldValue = FieldValue.trunc(FieldSize);
if (FieldOffset < NextFieldOffsetInBytes * 8) {
// Either part of the field or the entire field can go into the previous
@@ -166,20 +166,20 @@ void ConstStructBuilder::AppendBitField(const FieldDecl *Field,
if (CGM.getTargetData().isBigEndian()) {
Tmp = Tmp.lshr(NewFieldWidth);
- Tmp.trunc(BitsInPreviousByte);
+ Tmp = Tmp.trunc(BitsInPreviousByte);
// We want the remaining high bits.
- FieldValue.trunc(NewFieldWidth);
+ FieldValue = FieldValue.trunc(NewFieldWidth);
} else {
- Tmp.trunc(BitsInPreviousByte);
+ Tmp = Tmp.trunc(BitsInPreviousByte);
// We want the remaining low bits.
FieldValue = FieldValue.lshr(BitsInPreviousByte);
- FieldValue.trunc(NewFieldWidth);
+ FieldValue = FieldValue.trunc(NewFieldWidth);
}
}
- Tmp.zext(8);
+ Tmp = Tmp.zext(8);
if (CGM.getTargetData().isBigEndian()) {
if (FitsCompletelyInPreviousByte)
Tmp = Tmp.shl(BitsInPreviousByte - FieldValue.getBitWidth());
@@ -231,13 +231,10 @@ void ConstStructBuilder::AppendBitField(const FieldDecl *Field,
if (CGM.getTargetData().isBigEndian()) {
// We want the high bits.
- Tmp = FieldValue;
- Tmp = Tmp.lshr(Tmp.getBitWidth() - 8);
- Tmp.trunc(8);
+ Tmp = FieldValue.lshr(Tmp.getBitWidth() - 8).trunc(8);
} else {
// We want the low bits.
- Tmp = FieldValue;
- Tmp.trunc(8);
+ Tmp = FieldValue.trunc(8);
FieldValue = FieldValue.lshr(8);
}
@@ -245,7 +242,7 @@ void ConstStructBuilder::AppendBitField(const FieldDecl *Field,
Elements.push_back(llvm::ConstantInt::get(CGM.getLLVMContext(), Tmp));
NextFieldOffsetInBytes++;
- FieldValue.trunc(FieldValue.getBitWidth() - 8);
+ FieldValue = FieldValue.trunc(FieldValue.getBitWidth() - 8);
}
assert(FieldValue.getBitWidth() > 0 &&
@@ -257,10 +254,9 @@ void ConstStructBuilder::AppendBitField(const FieldDecl *Field,
if (CGM.getTargetData().isBigEndian()) {
unsigned BitWidth = FieldValue.getBitWidth();
- FieldValue.zext(8);
- FieldValue = FieldValue << (8 - BitWidth);
+ FieldValue = FieldValue.zext(8) << (8 - BitWidth);
} else
- FieldValue.zext(8);
+ FieldValue = FieldValue.zext(8);
}
// Append the last element.