Fix a bug where we would corrupt the offset when evaluating
authorChandler Carruth <chandlerc@gmail.com>
Sun, 25 Aug 2013 10:46:39 +0000 (10:46 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 25 Aug 2013 10:46:39 +0000 (10:46 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189188 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Value.cpp

index afa9291c9ef067032b827d81dbcf9d246ba4c52c..6698f832b256f4b9a5ca8535b50ee1c1603eabdb 100644 (file)
@@ -411,8 +411,10 @@ Value *Value::stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,
     if (GEPOperator *GEP = dyn_cast<GEPOperator>(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<Operator>(V)->getOperand(0);