@@ -197,7 +197,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
197
197
void emitDbgIntrinsic (IRBuilder &Builder, llvm::Value *Storage,
198
198
llvm::DILocalVariable *Var, llvm::DIExpression *Expr,
199
199
unsigned Line, unsigned Col, llvm::DILocalScope *Scope,
200
- const SILDebugScope *DS);
200
+ const SILDebugScope *DS, bool InCoroContext = false );
201
201
void emitGlobalVariableDeclaration (llvm::GlobalVariable *Storage,
202
202
StringRef Name, StringRef LinkageName,
203
203
DebugTypeInfo DebugType,
@@ -2367,7 +2367,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
2367
2367
2368
2368
for (llvm::Value *Piece : Storage) {
2369
2369
SmallVector<uint64_t , 3 > Operands;
2370
- if (Indirection)
2370
+ if (Indirection == IndirectValue || Indirection == CoroIndirectValue )
2371
2371
Operands.push_back (llvm::dwarf::DW_OP_deref);
2372
2372
2373
2373
if (IsPiece) {
@@ -2389,7 +2389,9 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
2389
2389
Operands.push_back (SizeInBits);
2390
2390
}
2391
2391
emitDbgIntrinsic (Builder, Piece, Var, DBuilder.createExpression (Operands),
2392
- Line, Loc.Column , Scope, DS);
2392
+ Line, Loc.Column , Scope, DS,
2393
+ Indirection == CoroDirectValue ||
2394
+ Indirection == CoroIndirectValue);
2393
2395
}
2394
2396
2395
2397
// Emit locationless intrinsic for variables that were optimized away.
@@ -2401,7 +2403,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
2401
2403
void IRGenDebugInfoImpl::emitDbgIntrinsic (
2402
2404
IRBuilder &Builder, llvm::Value *Storage, llvm::DILocalVariable *Var,
2403
2405
llvm::DIExpression *Expr, unsigned Line, unsigned Col,
2404
- llvm::DILocalScope *Scope, const SILDebugScope *DS) {
2406
+ llvm::DILocalScope *Scope, const SILDebugScope *DS, bool InCoroContext ) {
2405
2407
// Set the location/scope of the intrinsic.
2406
2408
auto *InlinedAt = createInlinedAt (DS);
2407
2409
auto DL = llvm::DebugLoc::get (Line, Col, Scope, InlinedAt);
@@ -2420,13 +2422,23 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic(
2420
2422
DBuilder.insertDeclare (Alloca, Var, Expr, DL, &*InsertBefore);
2421
2423
else
2422
2424
DBuilder.insertDeclare (Alloca, Var, Expr, DL, ParentBB);
2423
- } else if (isa<llvm::IntrinsicInst>(Storage) &&
2424
- cast<llvm::IntrinsicInst>(Storage)->getIntrinsicID () ==
2425
- llvm::Intrinsic::coro_alloca_get) {
2425
+ } else if (( isa<llvm::IntrinsicInst>(Storage) &&
2426
+ cast<llvm::IntrinsicInst>(Storage)->getIntrinsicID () ==
2427
+ llvm::Intrinsic::coro_alloca_get) ) {
2426
2428
// FIXME: The live range of a coroutine alloca within the function may be
2427
2429
// limited, so using a dbg.addr instead of a dbg.declare would be more
2428
2430
// appropriate.
2429
2431
DBuilder.insertDeclare (Storage, Var, Expr, DL, BB);
2432
+ } else if (InCoroContext && (Var->getArg () || Var->isArtificial ())) {
2433
+ // Function arguments in async functions are emitted without a shadow copy
2434
+ // (that would interfer with coroutine splitting) but with a dbg.declare to
2435
+ // give CoroSplit.cpp license to emit a shadow copy for them pointing inside
2436
+ // the Swift Context argument that is valid throughout the function.
2437
+ auto &EntryBlock = BB->getParent ()->getEntryBlock ();
2438
+ if (auto *InsertBefore = &*EntryBlock.getFirstInsertionPt ())
2439
+ DBuilder.insertDeclare (Storage, Var, Expr, DL, InsertBefore);
2440
+ else
2441
+ DBuilder.insertDeclare (Storage, Var, Expr, DL, &EntryBlock);
2430
2442
} else {
2431
2443
// Insert a dbg.value at the current insertion point.
2432
2444
DBuilder.insertDbgValueIntrinsic (Storage, Var, Expr, DL, BB);
@@ -2506,7 +2518,8 @@ void IRGenDebugInfoImpl::emitTypeMetadata(IRGenFunction &IGF,
2506
2518
// swift.type is already a pointer type,
2507
2519
// having a shadow copy doesn't add another
2508
2520
// layer of indirection.
2509
- DirectValue, ArtificialValue);
2521
+ IGF.isAsync () ? CoroDirectValue : DirectValue,
2522
+ ArtificialValue);
2510
2523
}
2511
2524
2512
2525
SILLocation::DebugLoc IRGenDebugInfoImpl::decodeSourceLoc (SourceLoc SL) {
@@ -2609,9 +2622,10 @@ void IRGenDebugInfo::emitDbgIntrinsic(IRBuilder &Builder, llvm::Value *Storage,
2609
2622
llvm::DILocalVariable *Var,
2610
2623
llvm::DIExpression *Expr, unsigned Line,
2611
2624
unsigned Col, llvm::DILocalScope *Scope,
2612
- const SILDebugScope *DS) {
2625
+ const SILDebugScope *DS,
2626
+ bool InCoroContext) {
2613
2627
static_cast <IRGenDebugInfoImpl *>(this )->emitDbgIntrinsic (
2614
- Builder, Storage, Var, Expr, Line, Col, Scope, DS);
2628
+ Builder, Storage, Var, Expr, Line, Col, Scope, DS, InCoroContext );
2615
2629
}
2616
2630
2617
2631
void IRGenDebugInfo::emitGlobalVariableDeclaration (
0 commit comments