summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/Constants.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2008-06-30 07:31:25 +0000
committerEvan Cheng <evan.cheng@apple.com>2008-06-30 07:31:25 +0000
commitda3db11db30ae459a5bd25dd71eb1ec902c8164a (patch)
treeff5fbb67881d32866669572601431e1778b8d856 /llvm/lib/VMCore/Constants.cpp
parentd68c04f16238158c7ea89cf72a3da49b103fa6d9 (diff)
downloadbcm5719-llvm-da3db11db30ae459a5bd25dd71eb1ec902c8164a.tar.gz
bcm5719-llvm-da3db11db30ae459a5bd25dd71eb1ec902c8164a.zip
- Re-apply 52748 and friends with fix. GetConstantStringInfo() returns an empty string for ConstantAggregateZero case which surprises selectiondag.
- Correctly handle memcpy from constant string which is zero-initialized. llvm-svn: 52891
Diffstat (limited to 'llvm/lib/VMCore/Constants.cpp')
-rw-r--r--llvm/lib/VMCore/Constants.cpp42
1 files changed, 1 insertions, 41 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index b9976a72070..7a08b5fb8f2 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -2658,44 +2658,4 @@ void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV,
// Delete the old constant!
destroyConstant();
-}
-
-
-/// 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(bool Chop, unsigned Offset) {
- if (GlobalVariable *GV = dyn_cast<GlobalVariable>(this)) {
- if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
- ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
- if (Init->isString()) {
- std::string Result = Init->getAsString();
- if (Offset < Result.size()) {
- // If we are pointing INTO The string, erase the beginning...
- Result.erase(Result.begin(), Result.begin()+Offset);
-
- // Take off the null terminator, and any string fragments after it.
- 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;
- }
- }
- }
- } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(this)) {
- if (CE->getOpcode() == Instruction::GetElementPtr) {
- // Turn a gep into the specified offset.
- if (CE->getNumOperands() == 3 &&
- cast<Constant>(CE->getOperand(1))->isNullValue() &&
- isa<ConstantInt>(CE->getOperand(2))) {
- Offset += cast<ConstantInt>(CE->getOperand(2))->getZExtValue();
- return CE->getOperand(0)->getStringValue(Chop, Offset);
- }
- }
- }
- return "";
-}
+} \ No newline at end of file
OpenPOWER on IntegriCloud