From 3284d42c17a7f95a07b73e414b50b3d0e10733a1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 28 Jun 2008 04:37:04 +0000 Subject: [PATCH] Tighten up checking. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52850 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ValueTracking.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index 8c6a7f582fb..c80489153aa 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -950,6 +950,8 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset) { if (GetElementPtrInst *GEPI = dyn_cast(V)) { GEP = GEPI; } else if (ConstantExpr *CE = dyn_cast(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(GEP->getOperand(0)->getType()); + const ArrayType *AT = dyn_cast(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(GEP->getOperand(1))) { - if (!Idx->isZero()) - return false; - } else + ConstantInt *FirstIdx = dyn_cast(GEP->getOperand(1)); + if (FirstIdx == 0 || !FirstIdx->isZero()) return false; // If the second index isn't a ConstantInt, then this is a variable index -- 2.34.1