diff options
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 677c3d92d02..5bf5539f5c9 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -17,6 +17,7 @@ //===----------------------------------------------------------------------===// #include "llvm/Analysis/ConstantFolding.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" @@ -564,7 +565,7 @@ Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, // directly if string length is small enough. StringRef Str; if (getConstantStringInfo(CE, Str) && !Str.empty()) { - unsigned StrLen = Str.size(); + size_t StrLen = Str.size(); unsigned NumBits = Ty->getPrimitiveSizeInBits(); // Replace load with immediate integer if the result is an integer or fp // value. @@ -573,15 +574,13 @@ Constant *llvm::ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, APInt StrVal(NumBits, 0); APInt SingleChar(NumBits, 0); if (DL.isLittleEndian()) { - for (signed i = StrLen-1; i >= 0; i--) { - SingleChar = (uint64_t) Str[i] & - std::numeric_limits<unsigned char>::max(); + for (unsigned char C : reverse(Str.bytes())) { + SingleChar = static_cast<uint64_t>(C); StrVal = (StrVal << 8) | SingleChar; } } else { - for (unsigned i = 0; i < StrLen; i++) { - SingleChar = (uint64_t) Str[i] & - std::numeric_limits<unsigned char>::max(); + for (unsigned char C : Str.bytes()) { + SingleChar = static_cast<uint64_t>(C); StrVal = (StrVal << 8) | SingleChar; } // Append NULL at the end. |