Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit e5a9de1

Browse files
committed
Merging r276510:
------------------------------------------------------------------------ r276510 | majnemer | 2016-07-22 19:56:49 -0700 (Fri, 22 Jul 2016) | 9 lines [LoopUnrollAnalyzer] Handle out of bounds accesses in visitLoad While we handed loads past the end of an array, we didn't handle loads _before_ the array. This fixes PR28062. N.B. While the bug in the code is obvious, I am struggling to craft a test case which is reasonable in size. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@276688 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent fc9c4d6 commit e5a9de1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/Analysis/LoopUnrollAnalyzer.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,19 @@ bool UnrolledInstAnalyzer::visitLoad(LoadInst &I) {
115115
// We might have a vector load from an array. FIXME: for now we just bail
116116
// out in this case, but we should be able to resolve and simplify such
117117
// loads.
118-
if(CDS->getElementType() != I.getType())
118+
if (CDS->getElementType() != I.getType())
119119
return false;
120120

121-
int ElemSize = CDS->getElementType()->getPrimitiveSizeInBits() / 8U;
122-
if (SimplifiedAddrOp->getValue().getActiveBits() >= 64)
121+
unsigned ElemSize = CDS->getElementType()->getPrimitiveSizeInBits() / 8U;
122+
if (SimplifiedAddrOp->getValue().getActiveBits() > 64)
123123
return false;
124-
int64_t Index = SimplifiedAddrOp->getSExtValue() / ElemSize;
124+
int64_t SimplifiedAddrOpV = SimplifiedAddrOp->getSExtValue();
125+
if (SimplifiedAddrOpV < 0) {
126+
// FIXME: For now we conservatively ignore out of bound accesses, but
127+
// we're allowed to perform the optimization in this case.
128+
return false;
129+
}
130+
uint64_t Index = static_cast<uint64_t>(SimplifiedAddrOpV) / ElemSize;
125131
if (Index >= CDS->getNumElements()) {
126132
// FIXME: For now we conservatively ignore out of bound accesses, but
127133
// we're allowed to perform the optimization in this case.

0 commit comments

Comments
 (0)