@@ -3294,36 +3294,18 @@ Expr *SILGenFunction::findStorageReferenceExprForMoveOnly(Expr *argExpr,
3294
3294
sawLoad = true ;
3295
3295
}
3296
3296
3297
- // If we have a subscript, strip it off and make sure that our base is
3298
- // something that we can process. If we do and we succeed below, we return the
3299
- // subscript instead.
3300
- SubscriptExpr *subscriptExpr = nullptr ;
3301
- if ((subscriptExpr = dyn_cast<SubscriptExpr>(argExpr))) {
3302
- auto *decl = cast<SubscriptDecl>(subscriptExpr->getDecl ().getDecl ());
3303
- if (decl->getReadImpl () != ReadImplKind::Read) {
3304
- subscriptExpr = nullptr ;
3305
- } else {
3306
- argExpr = subscriptExpr->getBase ();
3307
- }
3308
-
3309
- // If there's a load on the base of the subscript expr, look past it.
3310
- if (auto *li = dyn_cast<LoadExpr>(argExpr)) {
3311
- argExpr = li->getSubExpr ();
3312
- }
3313
- }
3314
-
3315
3297
// If we're consuming instead, then the load _must_ have been there.
3316
3298
if (kind == StorageReferenceOperationKind::Consume && !sawLoad)
3317
3299
return nullptr ;
3318
3300
3319
- // If we did not see a load or a subscript expr and our argExpr is a
3301
+ // If we did not see a load and our argExpr is a
3320
3302
// declref_expr, return nullptr. We have an object not something that will be
3321
3303
// in memory. This can happen with classes or with values captured by a
3322
3304
// closure.
3323
3305
//
3324
3306
// NOTE: If we see a member_ref_expr from a decl_ref_expr, we still process it
3325
3307
// since the declref_expr could be from a class.
3326
- if (!sawLoad && !subscriptExpr ) {
3308
+ if (!sawLoad) {
3327
3309
if (auto *declRef = dyn_cast<DeclRefExpr>(argExpr)) {
3328
3310
assert (!declRef->getType ()->is <LValueType>() &&
3329
3311
" Shouldn't ever have an lvalue type here!" );
@@ -3352,18 +3334,27 @@ Expr *SILGenFunction::findStorageReferenceExprForMoveOnly(Expr *argExpr,
3352
3334
// We want to perform a borrow/consume if the first piece of storage being
3353
3335
// referenced is a move-only type.
3354
3336
3355
- VarDecl *storage = nullptr ;
3337
+ AbstractStorageDecl *storage = nullptr ;
3356
3338
Type type;
3357
3339
if (auto dre = dyn_cast<DeclRefExpr>(result.getStorageRef ())) {
3358
- storage = dyn_cast<VarDecl >(dre->getDecl ());
3340
+ storage = dyn_cast<AbstractStorageDecl >(dre->getDecl ());
3359
3341
type = dre->getType ();
3360
3342
} else if (auto mre = dyn_cast<MemberRefExpr>(result.getStorageRef ())) {
3361
- storage = dyn_cast<VarDecl >(mre->getDecl ().getDecl ());
3343
+ storage = dyn_cast<AbstractStorageDecl >(mre->getDecl ().getDecl ());
3362
3344
type = mre->getType ();
3345
+ } else if (auto se = dyn_cast<SubscriptExpr>(result.getStorageRef ())) {
3346
+ storage = dyn_cast<AbstractStorageDecl>(se->getDecl ().getDecl ());
3347
+ type = se->getType ();
3363
3348
}
3364
3349
3365
3350
if (!storage)
3366
3351
return nullptr ;
3352
+ if (!storage->hasStorage ()
3353
+ && storage->getReadImpl () != ReadImplKind::Read
3354
+ && storage->getReadImpl () != ReadImplKind::Address) {
3355
+ return nullptr ;
3356
+ }
3357
+
3367
3358
assert (type);
3368
3359
3369
3360
SILType ty =
@@ -3376,12 +3367,6 @@ Expr *SILGenFunction::findStorageReferenceExprForMoveOnly(Expr *argExpr,
3376
3367
if (!isMoveOnly)
3377
3368
return nullptr ;
3378
3369
3379
- // If we saw a subscript expr and the base of the subscript expr passed our
3380
- // tests above, we can emit the call to the subscript directly as a borrowed
3381
- // lvalue. Return the subscript expr here so that we emit it appropriately.
3382
- if (subscriptExpr)
3383
- return subscriptExpr;
3384
-
3385
3370
return result.getTransitiveRoot ();
3386
3371
}
3387
3372
0 commit comments