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
This commit is contained in:
Evan Cheng 2006-03-10 23:52:03 +00:00
parent 7907b6950b
commit 0937103368
3 changed files with 12 additions and 6 deletions

View File

@ -93,8 +93,10 @@ public:
/// getStringValue - Turn an LLVM constant pointer that eventually points to a /// 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. /// 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 } // End llvm namespace

View File

@ -1941,7 +1941,7 @@ void SelectionDAGLowering::visitMemIntrinsic(CallInst &I, unsigned Op) {
if (G) { if (G) {
GlobalVariable *GV = dyn_cast<GlobalVariable>(G->getGlobal()); GlobalVariable *GV = dyn_cast<GlobalVariable>(G->getGlobal());
if (GV) { if (GV) {
Str = GV->getStringValue(); Str = GV->getStringValue(false);
if (!Str.empty()) { if (!Str.empty()) {
CopyFromStr = true; CopyFromStr = true;
SrcOff += SrcDelta; SrcOff += SrcDelta;

View File

@ -1715,8 +1715,10 @@ void Constant::clearAllValueMaps() {
/// getStringValue - Turn an LLVM constant pointer that eventually points to a /// 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. /// 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 (GlobalVariable *GV = dyn_cast<GlobalVariable>(this)) {
if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) { if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
ConstantArray *Init = cast<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); Result.erase(Result.begin(), Result.begin()+Offset);
// Take off the null terminator, and any string fragments after it. // Take off the null terminator, and any string fragments after it.
std::string::size_type NullPos = Result.find_first_of((char)0); if (Chop) {
if (NullPos != std::string::npos) std::string::size_type NullPos = Result.find_first_of((char)0);
Result.erase(Result.begin()+NullPos, Result.end()); if (NullPos != std::string::npos)
Result.erase(Result.begin()+NullPos, Result.end());
}
return Result; return Result;
} }
} }