Collapsing node if variable length struct with final field of length zero

llvm-svn: 24621
This commit is contained in:
Sumant Kowshik 2005-12-06 18:04:30 +00:00
parent 1473162af0
commit a69fcbdeb8
1 changed files with 18 additions and 1 deletions

View File

@ -434,6 +434,23 @@ void GraphBuilder::visitGetElementPtrInst(User &GEP) {
// Add in the offset calculated... // Add in the offset calculated...
Value.setOffset(Value.getOffset()+Offset); Value.setOffset(Value.getOffset()+Offset);
// Check the offset
DSNode *N = Value.getNode();
if (N &&
!N->isNodeCompletelyFolded() &&
(N->getSize() != 0 || Offset != 0) &&
!N->isForwarding()) {
if ((Offset >= N->getSize()) || int(Offset) < 0) {
// Accessing offsets out of node size range
// This is seen in the "magic" struct in named (from bind), where the
// fourth field is an array of length 0, presumably used to create struct
// instances of different sizes
// Collapse the node since its size is now variable
N->foldNodeCompletely();
}
}
// Value is now the pointer we want to GEP to be... // Value is now the pointer we want to GEP to be...
setDestTo(GEP, Value); setDestTo(GEP, Value);
} }