From ba689b33152d195202e58471d16a49930c8435b3 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Sun, 25 Aug 2013 10:46:39 +0000 Subject: Fix a bug where we would corrupt the offset when evaluating a non-constant GEP. I don't have any test case that demonstrates this, Nadav (indirectly) pointed this out in code review. I'm not sure how possible it is to contrive a test case for the current users of this code that triggers the bad issue sadly. llvm-svn: 189188 --- llvm/lib/IR/Value.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'llvm/lib/IR/Value.cpp') diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index afa9291c9ef..6698f832b25 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -411,8 +411,10 @@ Value *Value::stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, if (GEPOperator *GEP = dyn_cast(V)) { if (!GEP->isInBounds()) return V; - if (!GEP->accumulateConstantOffset(DL, Offset)) + APInt GEPOffset(Offset); + if (!GEP->accumulateConstantOffset(DL, GEPOffset)) return V; + Offset = GEPOffset; V = GEP->getPointerOperand(); } else if (Operator::getOpcode(V) == Instruction::BitCast) { V = cast(V)->getOperand(0); -- cgit v1.2.3