Skip to content

Commit fd60461

Browse files
authored
Merge pull request swiftlang#72861 from augusto2112/cast-base
Use dyn_cast_or_null when casting AccessPathWithBase's base
2 parents c2696cc + ddeba61 commit fd60461

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerUtils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ void UseState::initializeLiveness(
12271227
auto accessPathWithBase =
12281228
AccessPathWithBase::computeInScope(li->getOperand());
12291229
if (auto *beginAccess =
1230-
dyn_cast<BeginAccessInst>(accessPathWithBase.base)) {
1230+
dyn_cast_or_null<BeginAccessInst>(accessPathWithBase.base)) {
12311231
for (auto *endAccess : beginAccess->getEndAccesses()) {
12321232
liveness.updateForUse(endAccess, livenessInstAndValue.second,
12331233
false /*lifetime ending*/);
@@ -1247,7 +1247,7 @@ void UseState::initializeLiveness(
12471247
auto accessPathWithBase =
12481248
AccessPathWithBase::computeInScope(lbi->getOperand());
12491249
if (auto *beginAccess =
1250-
dyn_cast<BeginAccessInst>(accessPathWithBase.base)) {
1250+
dyn_cast_or_null<BeginAccessInst>(accessPathWithBase.base)) {
12511251
for (auto *endAccess : beginAccess->getEndAccesses()) {
12521252
liveness.updateForUse(endAccess, livenessInstAndValue.second,
12531253
false /*lifetime ending*/);
@@ -2003,7 +2003,7 @@ struct GatherUsesVisitor : public TransitiveAddressWalker<GatherUsesVisitor> {
20032003
// TODO: Make this a we don't understand error.
20042004
assert(accessPath.isValid() && "Invalid access path?!");
20052005

2006-
auto *bai = dyn_cast<BeginAccessInst>(accessPathWithBase.base);
2006+
auto *bai = dyn_cast_or_null<BeginAccessInst>(accessPathWithBase.base);
20072007

20082008
if (!bai) {
20092009
LLVM_DEBUG(llvm::dbgs()
@@ -3333,7 +3333,7 @@ void MoveOnlyAddressCheckerPImpl::rewriteUses(
33333333
if (auto *li = dyn_cast<LoadInst>(copyInst.first)) {
33343334
// Convert this to its take form.
33353335
auto accessPath = AccessPathWithBase::computeInScope(li->getOperand());
3336-
if (auto *access = dyn_cast<BeginAccessInst>(accessPath.base))
3336+
if (auto *access = dyn_cast_or_null<BeginAccessInst>(accessPath.base))
33373337
access->setAccessKind(SILAccessKind::Modify);
33383338
li->setOwnershipQualifier(LoadOwnershipQualifier::Take);
33393339
changed = true;
@@ -3343,7 +3343,7 @@ void MoveOnlyAddressCheckerPImpl::rewriteUses(
33433343
if (auto *copy = dyn_cast<CopyAddrInst>(copyInst.first)) {
33443344
// Convert this to its take form.
33453345
auto accessPath = AccessPathWithBase::computeInScope(copy->getSrc());
3346-
if (auto *access = dyn_cast<BeginAccessInst>(accessPath.base))
3346+
if (auto *access = dyn_cast_or_null<BeginAccessInst>(accessPath.base))
33473347
access->setAccessKind(SILAccessKind::Modify);
33483348
copy->setIsTakeOfSrc(IsTake);
33493349
continue;

0 commit comments

Comments
 (0)