diff options
author | David Blaikie <dblaikie@gmail.com> | 2015-08-21 20:16:51 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2015-08-21 20:16:51 +0000 |
commit | 88208840b56ec5ceafd4c3d34a43d22dbba3a611 (patch) | |
tree | 7ab6c5c34f0b0d1268ca795d97903cd98f9fcc3e /llvm/lib/IR/Constants.cpp | |
parent | fa0e11efdd5252fd33bfdf7970f5bd0f6a613302 (diff) | |
download | llvm-88208840b56ec5ceafd4c3d34a43d22dbba3a611.zip llvm-88208840b56ec5ceafd4c3d34a43d22dbba3a611.tar.gz llvm-88208840b56ec5ceafd4c3d34a43d22dbba3a611.tar.bz2 |
[opaque pointer type]: Pass explicit pointee type when building a constant GEP.
Gets a bit tricky in the ValueMapper, of course - not sure if we should
just expose a list of explicit types for each Value so that the
ValueMapper can be neutral to these special cases (it's OK for things
like load, where the explicit type is the result type - but when that's
not the case, it means plumbing through another "special" type... )
llvm-svn: 245728
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 9365653..798ea24 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -1245,7 +1245,7 @@ ConstantExpr::getWithOperandReplaced(unsigned OpNo, Constant *Op) const { /// operands replaced with the specified values. The specified array must /// have the same number of operands as our current one. Constant *ConstantExpr::getWithOperands(ArrayRef<Constant *> Ops, Type *Ty, - bool OnlyIfReduced) const { + bool OnlyIfReduced, Type *SrcTy) const { assert(Ops.size() == getNumOperands() && "Operand count mismatch!"); // If no operands changed return self. @@ -1283,10 +1283,13 @@ Constant *ConstantExpr::getWithOperands(ArrayRef<Constant *> Ops, Type *Ty, case Instruction::ShuffleVector: return ConstantExpr::getShuffleVector(Ops[0], Ops[1], Ops[2], OnlyIfReducedTy); - case Instruction::GetElementPtr: - return ConstantExpr::getGetElementPtr(nullptr, Ops[0], Ops.slice(1), - cast<GEPOperator>(this)->isInBounds(), - OnlyIfReducedTy); + case Instruction::GetElementPtr: { + auto *GEPO = cast<GEPOperator>(this); + assert(SrcTy || (Ops[0]->getType() == getOperand(0)->getType())); + return ConstantExpr::getGetElementPtr( + SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.slice(1), + GEPO->isInBounds(), OnlyIfReducedTy); + } case Instruction::ICmp: case Instruction::FCmp: return ConstantExpr::getCompare(getPredicate(), Ops[0], Ops[1], |