@@ -382,22 +382,47 @@ static bool isReinitToInitConvertibleInst(SILInstruction *memInst) {
382
382
}
383
383
}
384
384
385
- static void convertMemoryReinitToInitForm (SILInstruction *memInst) {
385
+ static void insertDebugValueBefore (SILInstruction *insertPt,
386
+ DebugVarCarryingInst debugVar,
387
+ SILValue operand) {
388
+ if (!debugVar) {
389
+ return ;
390
+ }
391
+ auto varInfo = debugVar.getVarInfo ();
392
+ if (!varInfo) {
393
+ return ;
394
+ }
395
+ SILBuilderWithScope debugInfoBuilder (insertPt);
396
+ debugInfoBuilder.setCurrentDebugScope (debugVar->getDebugScope ());
397
+ debugInfoBuilder.createDebugValue (debugVar->getLoc (), operand,
398
+ *varInfo, false , true );
399
+ }
400
+
401
+ static void convertMemoryReinitToInitForm (SILInstruction *memInst,
402
+ DebugVarCarryingInst debugVar) {
403
+ SILValue dest;
386
404
switch (memInst->getKind ()) {
387
405
default :
388
406
llvm_unreachable (" unsupported?!" );
389
407
390
408
case SILInstructionKind::CopyAddrInst: {
391
409
auto *cai = cast<CopyAddrInst>(memInst);
392
410
cai->setIsInitializationOfDest (IsInitialization_t::IsInitialization);
393
- return ;
411
+ dest = cai->getDest ();
412
+ break ;
394
413
}
395
414
case SILInstructionKind::StoreInst: {
396
415
auto *si = cast<StoreInst>(memInst);
397
416
si->setOwnershipQualifier (StoreOwnershipQualifier::Init);
398
- return ;
417
+ dest = si->getDest ();
418
+ break ;
399
419
}
400
420
}
421
+
422
+ // Insert a new debug_value instruction after the reinitialization, so that
423
+ // the debugger knows that the variable is in a usable form again.
424
+ insertDebugValueBefore (memInst->getNextInstruction (), debugVar,
425
+ stripAccessMarkers (dest));
401
426
}
402
427
403
428
static bool memInstMustConsume (Operand *memOper) {
@@ -1151,7 +1176,8 @@ struct MoveOnlyAddressCheckerPImpl {
1151
1176
FieldSensitiveMultiDefPrunedLiveRange &liveness,
1152
1177
FieldSensitivePrunedLivenessBoundary &boundary);
1153
1178
1154
- void rewriteUses (FieldSensitiveMultiDefPrunedLiveRange &liveness,
1179
+ void rewriteUses (MarkMustCheckInst *markedValue,
1180
+ FieldSensitiveMultiDefPrunedLiveRange &liveness,
1155
1181
const FieldSensitivePrunedLivenessBoundary &boundary);
1156
1182
1157
1183
void handleSingleBlockDestroy (SILInstruction *destroy, bool isReinit);
@@ -2210,17 +2236,9 @@ void MoveOnlyAddressCheckerPImpl::insertDestroysOnBoundary(
2210
2236
if (!debugVar) {
2211
2237
return ;
2212
2238
}
2213
- auto varInfo = debugVar.getVarInfo ();
2214
- if (!varInfo) {
2215
- return ;
2216
- }
2217
- SILBuilderWithScope debugInfoBuilder (insertPt);
2218
- debugInfoBuilder.setCurrentDebugScope (debugVar->getDebugScope ());
2219
- debugInfoBuilder.createDebugValue (
2220
- debugVar->getLoc (),
2221
- SILUndef::get (debugVar.getOperandForDebugValueClone ()->getType (),
2222
- insertPt->getModule ()),
2223
- *varInfo, false , true );
2239
+ insertDebugValueBefore (insertPt, debugVar,
2240
+ SILUndef::get (debugVar.getOperandForDebugValueClone ()->getType (),
2241
+ insertPt->getModule ()));
2224
2242
};
2225
2243
2226
2244
for (auto &pair : boundary.getLastUsers ()) {
@@ -2326,6 +2344,7 @@ void MoveOnlyAddressCheckerPImpl::insertDestroysOnBoundary(
2326
2344
}
2327
2345
2328
2346
void MoveOnlyAddressCheckerPImpl::rewriteUses (
2347
+ MarkMustCheckInst *markedValue,
2329
2348
FieldSensitiveMultiDefPrunedLiveRange &liveness,
2330
2349
const FieldSensitivePrunedLivenessBoundary &boundary) {
2331
2350
LLVM_DEBUG (llvm::dbgs () << " MoveOnlyAddressChecker Rewrite Uses!\n " );
@@ -2336,12 +2355,15 @@ void MoveOnlyAddressCheckerPImpl::rewriteUses(
2336
2355
}
2337
2356
}
2338
2357
2358
+ auto debugVar = DebugVarCarryingInst::getFromValue (
2359
+ stripAccessMarkers (markedValue->getOperand ()));
2360
+
2339
2361
// Then convert all claimed reinits to inits.
2340
2362
for (auto reinitPair : addressUseState.reinitInsts ) {
2341
2363
if (!isReinitToInitConvertibleInst (reinitPair.first ))
2342
2364
continue ;
2343
2365
if (!consumes.claimConsume (reinitPair.first , reinitPair.second ))
2344
- convertMemoryReinitToInitForm (reinitPair.first );
2366
+ convertMemoryReinitToInitForm (reinitPair.first , debugVar );
2345
2367
}
2346
2368
2347
2369
// Check all takes.
@@ -2524,7 +2546,7 @@ bool MoveOnlyAddressCheckerPImpl::performSingleCheck(
2524
2546
FieldSensitivePrunedLivenessBoundary boundary (liveness.getNumSubElements ());
2525
2547
liveness.computeBoundary (boundary);
2526
2548
insertDestroysOnBoundary (markedAddress, liveness, boundary);
2527
- rewriteUses (liveness, boundary);
2549
+ rewriteUses (markedAddress, liveness, boundary);
2528
2550
2529
2551
return true ;
2530
2552
}
0 commit comments