Skip to content

Commit df6d25f

Browse files
committed
[gardening] Be more defensive around a potentially uninitialized Store by initializing it to nullptr and asserting that it is not nullptr (i.e. was assigned) before using it.
1 parent 1ddb916 commit df6d25f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/SILOptimizer/IPO/GlobalOpt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ static SILFunction *genGetterFromInit(SILOptFunctionBuilder &FunctionBuilder,
567567
// Find the store instruction
568568
auto *BB = GetterF->getEntryBlock();
569569
SILValue Val;
570-
SILInstruction *Store;
570+
SILInstruction *Store = nullptr;
571571
for (auto II = BB->begin(), E = BB->end(); II != E;) {
572572
auto &I = *II++;
573573
if (isa<AllocGlobalInst>(&I)) {
@@ -586,6 +586,7 @@ static SILFunction *genGetterFromInit(SILOptFunctionBuilder &FunctionBuilder,
586586
B.createReturn(RI->getLoc(), Val);
587587
eraseUsesOfInstruction(RI);
588588
recursivelyDeleteTriviallyDeadInstructions(RI, true);
589+
assert(Store && "Did not find a store?!");
589590
recursivelyDeleteTriviallyDeadInstructions(Store, true);
590591
return GetterF;
591592
}

lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,13 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
164164
// %addr = pointer_to_address %ptr, [strict] $T
165165
// %result = index_addr %addr, %distance
166166
//
167-
BuiltinInst *Bytes;
167+
BuiltinInst *Bytes = nullptr;
168168
if (match(PTAI->getOperand(),
169169
m_IndexRawPointerInst(
170170
m_ValueBase(),
171171
m_TupleExtractOperation(m_BuiltinInst(Bytes), 0)))) {
172+
assert(Bytes != nullptr &&
173+
"Bytes should have been assigned a non-null value");
172174
if (match(Bytes, m_ApplyInst(BuiltinValueKind::SMulOver, m_ValueBase(),
173175
m_ApplyInst(BuiltinValueKind::Strideof,
174176
m_MetatypeInst(Metatype)),

0 commit comments

Comments
 (0)