diff options
author | Evan Cheng <evan.cheng@apple.com> | 2006-03-10 23:52:03 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2006-03-10 23:52:03 +0000 |
commit | 0937103368992af8d3d8032d31a7d152aeae32d5 (patch) | |
tree | 7c696840b9a28e8b6f4449cf156342120d280f0e | |
parent | 7907b6950bd6c7b1dc2b19930ff81371013000f8 (diff) | |
download | external_llvm-0937103368992af8d3d8032d31a7d152aeae32d5.zip external_llvm-0937103368992af8d3d8032d31a7d152aeae32d5.tar.gz external_llvm-0937103368992af8d3d8032d31a7d152aeae32d5.tar.bz2 |
Added a parameter to control whether Constant::getStringValue() would chop
off the result string at the first null terminator.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26704 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Constant.h | 4 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/Constants.cpp | 12 |
3 files changed, 12 insertions, 6 deletions
diff --git a/include/llvm/Constant.h b/include/llvm/Constant.h index 13b4cb3..4411540 100644 --- a/include/llvm/Constant.h +++ b/include/llvm/Constant.h @@ -93,8 +93,10 @@ public: /// getStringValue - Turn an LLVM constant pointer that eventually points to a /// global into a string value. Return an empty string if we can't do it. + /// Parameter Chop determines if the result is chopped at the first null + /// terminator. /// - std::string getStringValue(unsigned Offset = 0); + std::string getStringValue(bool Chop = true, unsigned Offset = 0); }; } // End llvm namespace diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 96694da..f1afeb9 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1941,7 +1941,7 @@ void SelectionDAGLowering::visitMemIntrinsic(CallInst &I, unsigned Op) { if (G) { GlobalVariable *GV = dyn_cast<GlobalVariable>(G->getGlobal()); if (GV) { - Str = GV->getStringValue(); + Str = GV->getStringValue(false); if (!Str.empty()) { CopyFromStr = true; SrcOff += SrcDelta; diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 1beb5bc..28ca2a4 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1715,8 +1715,10 @@ void Constant::clearAllValueMaps() { /// getStringValue - Turn an LLVM constant pointer that eventually points to a /// global into a string value. Return an empty string if we can't do it. +/// Parameter Chop determines if the result is chopped at the first null +/// terminator. /// -std::string Constant::getStringValue(unsigned Offset) { +std::string Constant::getStringValue(bool Chop, unsigned Offset) { if (GlobalVariable *GV = dyn_cast<GlobalVariable>(this)) { if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) { ConstantArray *Init = cast<ConstantArray>(GV->getInitializer()); @@ -1727,9 +1729,11 @@ std::string Constant::getStringValue(unsigned Offset) { Result.erase(Result.begin(), Result.begin()+Offset); // Take off the null terminator, and any string fragments after it. - std::string::size_type NullPos = Result.find_first_of((char)0); - if (NullPos != std::string::npos) - Result.erase(Result.begin()+NullPos, Result.end()); + if (Chop) { + std::string::size_type NullPos = Result.find_first_of((char)0); + if (NullPos != std::string::npos) + Result.erase(Result.begin()+NullPos, Result.end()); + } return Result; } } |