@@ -3230,36 +3230,18 @@ Expr *SILGenFunction::findStorageReferenceExprForMoveOnly(Expr *argExpr,
3230
3230
sawLoad = true ;
3231
3231
}
3232
3232
3233
- // If we have a subscript, strip it off and make sure that our base is
3234
- // something that we can process. If we do and we succeed below, we return the
3235
- // subscript instead.
3236
- SubscriptExpr *subscriptExpr = nullptr ;
3237
- if ((subscriptExpr = dyn_cast<SubscriptExpr>(argExpr))) {
3238
- auto *decl = cast<SubscriptDecl>(subscriptExpr->getDecl ().getDecl ());
3239
- if (decl->getReadImpl () != ReadImplKind::Read) {
3240
- subscriptExpr = nullptr ;
3241
- } else {
3242
- argExpr = subscriptExpr->getBase ();
3243
- }
3244
-
3245
- // If there's a load on the base of the subscript expr, look past it.
3246
- if (auto *li = dyn_cast<LoadExpr>(argExpr)) {
3247
- argExpr = li->getSubExpr ();
3248
- }
3249
- }
3250
-
3251
3233
// If we're consuming instead, then the load _must_ have been there.
3252
3234
if (kind == StorageReferenceOperationKind::Consume && !sawLoad)
3253
3235
return nullptr ;
3254
3236
3255
- // If we did not see a load or a subscript expr and our argExpr is a
3237
+ // If we did not see a load and our argExpr is a
3256
3238
// declref_expr, return nullptr. We have an object not something that will be
3257
3239
// in memory. This can happen with classes or with values captured by a
3258
3240
// closure.
3259
3241
//
3260
3242
// NOTE: If we see a member_ref_expr from a decl_ref_expr, we still process it
3261
3243
// since the declref_expr could be from a class.
3262
- if (!sawLoad && !subscriptExpr ) {
3244
+ if (!sawLoad) {
3263
3245
if (auto *declRef = dyn_cast<DeclRefExpr>(argExpr)) {
3264
3246
assert (!declRef->getType ()->is <LValueType>() &&
3265
3247
" Shouldn't ever have an lvalue type here!" );
@@ -3288,18 +3270,27 @@ Expr *SILGenFunction::findStorageReferenceExprForMoveOnly(Expr *argExpr,
3288
3270
// We want to perform a borrow/consume if the first piece of storage being
3289
3271
// referenced is a move-only type.
3290
3272
3291
- VarDecl *storage = nullptr ;
3273
+ AbstractStorageDecl *storage = nullptr ;
3292
3274
Type type;
3293
3275
if (auto dre = dyn_cast<DeclRefExpr>(result.getStorageRef ())) {
3294
- storage = dyn_cast<VarDecl >(dre->getDecl ());
3276
+ storage = dyn_cast<AbstractStorageDecl >(dre->getDecl ());
3295
3277
type = dre->getType ();
3296
3278
} else if (auto mre = dyn_cast<MemberRefExpr>(result.getStorageRef ())) {
3297
- storage = dyn_cast<VarDecl >(mre->getDecl ().getDecl ());
3279
+ storage = dyn_cast<AbstractStorageDecl >(mre->getDecl ().getDecl ());
3298
3280
type = mre->getType ();
3281
+ } else if (auto se = dyn_cast<SubscriptExpr>(result.getStorageRef ())) {
3282
+ storage = dyn_cast<AbstractStorageDecl>(se->getDecl ().getDecl ());
3283
+ type = se->getType ();
3299
3284
}
3300
3285
3301
3286
if (!storage)
3302
3287
return nullptr ;
3288
+ if (!storage->hasStorage ()
3289
+ && storage->getReadImpl () != ReadImplKind::Read
3290
+ && storage->getReadImpl () != ReadImplKind::Address) {
3291
+ return nullptr ;
3292
+ }
3293
+
3303
3294
assert (type);
3304
3295
3305
3296
SILType ty =
@@ -3312,12 +3303,6 @@ Expr *SILGenFunction::findStorageReferenceExprForMoveOnly(Expr *argExpr,
3312
3303
if (!isMoveOnly)
3313
3304
return nullptr ;
3314
3305
3315
- // If we saw a subscript expr and the base of the subscript expr passed our
3316
- // tests above, we can emit the call to the subscript directly as a borrowed
3317
- // lvalue. Return the subscript expr here so that we emit it appropriately.
3318
- if (subscriptExpr)
3319
- return subscriptExpr;
3320
-
3321
3306
return result.getTransitiveRoot ();
3322
3307
}
3323
3308
0 commit comments