Skip to content

Commit 4aa3001

Browse files
author
Andrew Lenharth
committed
Handle some kernel code than ends in [0 x sbyte]. I think this is safe
llvm-svn: 27672
1 parent 709eaac commit 4aa3001

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

llvm/lib/Analysis/DataStructure/Local.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,17 @@ void GraphBuilder::MergeConstantInitIntoNode(DSNodeHandle &NH, Constant *C) {
11161116
const StructLayout *SL = TD.getStructLayout(CS->getType());
11171117
for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) {
11181118
DSNode *NHN = NH.getNode();
1119-
DSNodeHandle NewNH(NHN, NH.getOffset()+(unsigned)SL->MemberOffsets[i]);
1120-
MergeConstantInitIntoNode(NewNH, cast<Constant>(CS->getOperand(i)));
1119+
//Some programmers think ending a structure with a [0 x sbyte] is cute
1120+
//This should be ok as the allocation type should grow this type when
1121+
//it is merged in if it is bigger.
1122+
if (SL->MemberOffsets[i] < SL->StructSize) {
1123+
DSNodeHandle NewNH(NHN, NH.getOffset()+(unsigned)SL->MemberOffsets[i]);
1124+
MergeConstantInitIntoNode(NewNH, cast<Constant>(CS->getOperand(i)));
1125+
} else if (SL->MemberOffsets[i] == SL->StructSize) {
1126+
DEBUG(std::cerr << "Zero size element at end of struct\n");
1127+
} else {
1128+
assert(0 && "type was smaller than offsets of of struct layout indicate");
1129+
}
11211130
}
11221131
} else if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C)) {
11231132
// Noop

0 commit comments

Comments
 (0)