diff options
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 03087d8370d5..245f2d4e442a 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -89,10 +89,12 @@ static Value *convertStrToInt(CallInst *CI, StringRef &Str, Value *EndPtr, // Fail for an invalid base (required by POSIX). return nullptr; + // Current offset into the original string to reflect in EndPtr. + size_t Offset = 0; // Strip leading whitespace. - for (unsigned i = 0; i != Str.size(); ++i) - if (!isSpace((unsigned char)Str[i])) { - Str = Str.substr(i); + for ( ; Offset != Str.size(); ++Offset) + if (!isSpace((unsigned char)Str[Offset])) { + Str = Str.substr(Offset); break; } @@ -108,6 +110,7 @@ static Value *convertStrToInt(CallInst *CI, StringRef &Str, Value *EndPtr, if (Str.empty()) // Fail for a sign with nothing after it. return nullptr; + ++Offset; } // Set Max to the absolute value of the minimum (for signed), or @@ -127,6 +130,7 @@ static Value *convertStrToInt(CallInst *CI, StringRef &Str, Value *EndPtr, return nullptr; Str = Str.drop_front(2); + Offset += 2; Base = 16; } else if (Base == 0) @@ -167,7 +171,7 @@ static Value *convertStrToInt(CallInst *CI, StringRef &Str, Value *EndPtr, if (EndPtr) { // Store the pointer to the end. - Value *Off = B.getInt64(Str.size()); + Value *Off = B.getInt64(Offset + Str.size()); Value *StrBeg = CI->getArgOperand(0); Value *StrEnd = B.CreateInBoundsGEP(B.getInt8Ty(), StrBeg, Off, "endptr"); B.CreateStore(StrEnd, EndPtr); |