summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-06-28 04:37:04 +0000
committerChris Lattner <sabre@nondot.org>2008-06-28 04:37:04 +0000
commitebf1f67193edc93adaacc1d0d3829bd21f2684b4 (patch)
tree0e72f3a8efebf75e732e5833aeb8c9303148bfa9 /llvm/lib/Analysis/ValueTracking.cpp
parent6f7b5a6392957c2d9fe82a50b24fc51b337fe9cc (diff)
downloadbcm5719-llvm-ebf1f67193edc93adaacc1d0d3829bd21f2684b4.tar.gz
bcm5719-llvm-ebf1f67193edc93adaacc1d0d3829bd21f2684b4.zip
Tighten up checking.
llvm-svn: 52850
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 8c6a7f582fb..c80489153aa 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -950,6 +950,8 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset) {
if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(V)) {
GEP = GEPI;
} else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
+ if (CE->getOpcode() == Instruction::BitCast)
+ return GetConstantStringInfo(CE->getOperand(0), Str, Offset);
if (CE->getOpcode() != Instruction::GetElementPtr)
return false;
GEP = CE;
@@ -960,12 +962,16 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset) {
if (GEP->getNumOperands() != 3)
return false;
+ // Make sure the index-ee is a pointer to array of i8.
+ const PointerType *PT = cast<PointerType>(GEP->getOperand(0)->getType());
+ const ArrayType *AT = dyn_cast<ArrayType>(PT->getElementType());
+ if (AT == 0 || AT->getElementType() != Type::Int8Ty)
+ return false;
+
// Check to make sure that the first operand of the GEP is an integer and
// has value 0 so that we are sure we're indexing into the initializer.
- if (ConstantInt *Idx = dyn_cast<ConstantInt>(GEP->getOperand(1))) {
- if (!Idx->isZero())
- return false;
- } else
+ ConstantInt *FirstIdx = dyn_cast<ConstantInt>(GEP->getOperand(1));
+ if (FirstIdx == 0 || !FirstIdx->isZero())
return false;
// If the second index isn't a ConstantInt, then this is a variable index
OpenPOWER on IntegriCloud