diff options
| author | Jay Foad <jay.foad@gmail.com> | 2010-12-07 08:25:34 +0000 |
|---|---|---|
| committer | Jay Foad <jay.foad@gmail.com> | 2010-12-07 08:25:34 +0000 |
| commit | 6d4db0c8850543661493af107a1d601d12a89509 (patch) | |
| tree | 8d09f8cde8e18587dc50e42150992071c57f9e43 /clang/lib/CodeGen/CGExprConstant.cpp | |
| parent | 583abbc4df3d9b9e5a86a56ae581970b98dc5249 (diff) | |
| download | bcm5719-llvm-6d4db0c8850543661493af107a1d601d12a89509.tar.gz bcm5719-llvm-6d4db0c8850543661493af107a1d601d12a89509.zip | |
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.
llvm-svn: 121121
Diffstat (limited to 'clang/lib/CodeGen/CGExprConstant.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGExprConstant.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/clang/lib/CodeGen/CGExprConstant.cpp b/clang/lib/CodeGen/CGExprConstant.cpp index 9002253e721..51b1de37a95 100644 --- a/clang/lib/CodeGen/CGExprConstant.cpp +++ b/clang/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. |

