@@ -383,22 +383,47 @@ static bool isReinitToInitConvertibleInst(SILInstruction *memInst) {
383
383
}
384
384
}
385
385
386
- static void convertMemoryReinitToInitForm (SILInstruction *memInst) {
386
+ static void insertDebugValueBefore (SILInstruction *insertPt,
387
+ DebugVarCarryingInst debugVar,
388
+ SILValue operand) {
389
+ if (!debugVar) {
390
+ return ;
391
+ }
392
+ auto varInfo = debugVar.getVarInfo ();
393
+ if (!varInfo) {
394
+ return ;
395
+ }
396
+ SILBuilderWithScope debugInfoBuilder (insertPt);
397
+ debugInfoBuilder.setCurrentDebugScope (debugVar->getDebugScope ());
398
+ debugInfoBuilder.createDebugValue (debugVar->getLoc (), operand,
399
+ *varInfo, false , true );
400
+ }
401
+
402
+ static void convertMemoryReinitToInitForm (SILInstruction *memInst,
403
+ DebugVarCarryingInst debugVar) {
404
+ SILValue dest;
387
405
switch (memInst->getKind ()) {
388
406
default :
389
407
llvm_unreachable (" unsupported?!" );
390
408
391
409
case SILInstructionKind::CopyAddrInst: {
392
410
auto *cai = cast<CopyAddrInst>(memInst);
393
411
cai->setIsInitializationOfDest (IsInitialization_t::IsInitialization);
394
- return ;
412
+ dest = cai->getDest ();
413
+ break ;
395
414
}
396
415
case SILInstructionKind::StoreInst: {
397
416
auto *si = cast<StoreInst>(memInst);
398
417
si->setOwnershipQualifier (StoreOwnershipQualifier::Init);
399
- return ;
418
+ dest = si->getDest ();
419
+ break ;
400
420
}
401
421
}
422
+
423
+ // Insert a new debug_value instruction after the reinitialization, so that
424
+ // the debugger knows that the variable is in a usable form again.
425
+ insertDebugValueBefore (memInst->getNextInstruction (), debugVar,
426
+ stripAccessMarkers (dest));
402
427
}
403
428
404
429
static bool memInstMustConsume (Operand *memOper) {
@@ -1238,7 +1263,8 @@ struct MoveOnlyAddressCheckerPImpl {
1238
1263
FieldSensitiveMultiDefPrunedLiveRange &liveness,
1239
1264
FieldSensitivePrunedLivenessBoundary &boundary);
1240
1265
1241
- void rewriteUses (FieldSensitiveMultiDefPrunedLiveRange &liveness,
1266
+ void rewriteUses (MarkMustCheckInst *markedValue,
1267
+ FieldSensitiveMultiDefPrunedLiveRange &liveness,
1242
1268
const FieldSensitivePrunedLivenessBoundary &boundary);
1243
1269
1244
1270
void handleSingleBlockDestroy (SILInstruction *destroy, bool isReinit);
@@ -2310,17 +2336,9 @@ void MoveOnlyAddressCheckerPImpl::insertDestroysOnBoundary(
2310
2336
if (!debugVar) {
2311
2337
return ;
2312
2338
}
2313
- auto varInfo = debugVar.getVarInfo ();
2314
- if (!varInfo) {
2315
- return ;
2316
- }
2317
- SILBuilderWithScope debugInfoBuilder (insertPt);
2318
- debugInfoBuilder.setCurrentDebugScope (debugVar->getDebugScope ());
2319
- debugInfoBuilder.createDebugValue (
2320
- debugVar->getLoc (),
2321
- SILUndef::get (debugVar.getOperandForDebugValueClone ()->getType (),
2322
- insertPt->getModule ()),
2323
- *varInfo, false , true );
2339
+ insertDebugValueBefore (insertPt, debugVar,
2340
+ SILUndef::get (debugVar.getOperandForDebugValueClone ()->getType (),
2341
+ insertPt->getModule ()));
2324
2342
};
2325
2343
2326
2344
for (auto &pair : boundary.getLastUsers ()) {
@@ -2426,6 +2444,7 @@ void MoveOnlyAddressCheckerPImpl::insertDestroysOnBoundary(
2426
2444
}
2427
2445
2428
2446
void MoveOnlyAddressCheckerPImpl::rewriteUses (
2447
+ MarkMustCheckInst *markedValue,
2429
2448
FieldSensitiveMultiDefPrunedLiveRange &liveness,
2430
2449
const FieldSensitivePrunedLivenessBoundary &boundary) {
2431
2450
LLVM_DEBUG (llvm::dbgs () << " MoveOnlyAddressChecker Rewrite Uses!\n " );
@@ -2436,12 +2455,15 @@ void MoveOnlyAddressCheckerPImpl::rewriteUses(
2436
2455
}
2437
2456
}
2438
2457
2458
+ auto debugVar = DebugVarCarryingInst::getFromValue (
2459
+ stripAccessMarkers (markedValue->getOperand ()));
2460
+
2439
2461
// Then convert all claimed reinits to inits.
2440
2462
for (auto reinitPair : addressUseState.reinitInsts ) {
2441
2463
if (!isReinitToInitConvertibleInst (reinitPair.first ))
2442
2464
continue ;
2443
2465
if (!consumes.claimConsume (reinitPair.first , reinitPair.second ))
2444
- convertMemoryReinitToInitForm (reinitPair.first );
2466
+ convertMemoryReinitToInitForm (reinitPair.first , debugVar );
2445
2467
}
2446
2468
2447
2469
// Check all takes.
@@ -2624,7 +2646,7 @@ bool MoveOnlyAddressCheckerPImpl::performSingleCheck(
2624
2646
FieldSensitivePrunedLivenessBoundary boundary (liveness.getNumSubElements ());
2625
2647
liveness.computeBoundary (boundary);
2626
2648
insertDestroysOnBoundary (markedAddress, liveness, boundary);
2627
- rewriteUses (liveness, boundary);
2649
+ rewriteUses (markedAddress, liveness, boundary);
2628
2650
2629
2651
return true ;
2630
2652
}
0 commit comments