Skip to content

Commit 994d05a

Browse files
committed
Add overflow when adding offset and element size
1 parent 50c8466 commit 994d05a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

llvm/lib/Analysis/Loads.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ bool llvm::isDereferenceableAndAlignedInLoop(LoadInst *LI, Loop *L,
321321
// TODO: generalize if a case found which warrants
322322
if (Offset->getAPInt().urem(Alignment.value()) != 0)
323323
return false;
324+
325+
bool Overflow = false;
324326
if (StepIsNegative) {
325327
// In the last iteration of the loop the address we access we will be
326328
// lower than the first by (TC - 1) * Step. So we need to make sure
@@ -331,13 +333,11 @@ bool llvm::isDereferenceableAndAlignedInLoop(LoadInst *LI, Loop *L,
331333
// We can safely use the new base because the decrementing pointer is
332334
// always guaranteed to be >= new base. The total access size needs to
333335
// take into account the start offset and the loaded element size.
334-
AccessSize = Offset->getAPInt() + EltSize;
335-
} else {
336-
bool Overflow = false;
336+
AccessSize = Offset->getAPInt().uadd_ov(EltSize, Overflow);
337+
} else
337338
AccessSize = AccessSize.uadd_ov(Offset->getAPInt(), Overflow);
338-
if (Overflow)
339-
return false;
340-
}
339+
if (Overflow)
340+
return false;
341341
Base = NewBase->getValue();
342342
}
343343
}

0 commit comments

Comments
 (0)