Skip to content

Commit 23adcba

Browse files
committed
[region-isolation] Eliminate some UB caused by dereferencing unchecked optionals.
llvm::Optional<T> used to make it so that in asserts builds if one dereferenced the optional and nothing was there, one would get an assert. std::optional<T> does not have that property.
1 parent 9303c40 commit 23adcba

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,8 @@ void InferredCallerArgumentTypeInfo::initForApply(
762762

763763
void InferredCallerArgumentTypeInfo::initForApply(const Operand *op,
764764
ApplyExpr *sourceApply) {
765-
auto isolationCrossing = *sourceApply->getIsolationCrossing();
765+
auto isolationCrossing = sourceApply->getIsolationCrossing();
766+
assert(isolationCrossing && "Should have valid isolation crossing?!");
766767

767768
// Grab out full apply site and see if we can find a better expr.
768769
SILInstruction *i = const_cast<SILInstruction *>(op->getUser());

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class UseDiagnosticInfo {
127127
UseDiagnosticInfoKind getKind() const { return kind; }
128128

129129
ApplyIsolationCrossing getIsolationCrossing() const {
130+
assert(isolationCrossing && "Isolation crossing must be non-null");
130131
return *isolationCrossing;
131132
}
132133

@@ -189,7 +190,8 @@ void InferredCallerArgumentTypeInfo::initForApply(
189190

190191
void InferredCallerArgumentTypeInfo::initForApply(const Operand *op,
191192
ApplyExpr *sourceApply) {
192-
auto isolationCrossing = *sourceApply->getIsolationCrossing();
193+
auto isolationCrossing = sourceApply->getIsolationCrossing();
194+
assert(isolationCrossing);
193195

194196
// Grab out full apply site and see if we can find a better expr.
195197
SILInstruction *i = const_cast<SILInstruction *>(op->getUser());
@@ -215,7 +217,7 @@ void InferredCallerArgumentTypeInfo::initForApply(const Operand *op,
215217
foundExpr ? foundExpr->findOriginalType() : baseInferredType;
216218
applyUses.emplace_back(
217219
inferredArgType,
218-
UseDiagnosticInfo::forIsolationCrossing(isolationCrossing));
220+
UseDiagnosticInfo::forIsolationCrossing(*isolationCrossing));
219221
}
220222

221223
namespace {

0 commit comments

Comments
 (0)