Skip to content

Commit 2dc7585

Browse files
Merge pull request #62542 from adrian-prantl/task-alloc
Fix IRGen debug info for swift_task_alloc'ed variables.
2 parents 58aaa4f + e67d8bf commit 2dc7585

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5389,8 +5389,11 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
53895389
assert(isa<llvm::AllocaInst>(addr) || isa<llvm::UndefValue>(addr) ||
53905390
isa<llvm::IntrinsicInst>(addr) || isCallToSwiftTaskAlloc(addr));
53915391

5392-
auto Indirection =
5393-
InCoroContext(*CurSILFn, *i) ? CoroDirectValue : DirectValue;
5392+
auto Indirection = DirectValue;
5393+
if (InCoroContext(*CurSILFn, *i))
5394+
Indirection =
5395+
isCallToSwiftTaskAlloc(addr) ? CoroIndirectValue : CoroDirectValue;
5396+
53945397
if (!IGM.IRGen.Opts.DisableDebuggerShadowCopies &&
53955398
!IGM.IRGen.Opts.shouldOptimize())
53965399
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(addr))
@@ -5434,25 +5437,6 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
54345437
} else
54355438
return;
54365439

5437-
// Async functions use the value of the artificial address.
5438-
auto shadow = addr;
5439-
if (CurSILFn->isAsync() && emitLifetimeExtendingUse(shadow) &&
5440-
!isa<llvm::UndefValue>(shadow)) {
5441-
if (ValueVariables.insert(shadow).second)
5442-
ValueDomPoints.push_back({shadow, getActiveDominancePoint()});
5443-
auto shadowInst = cast<llvm::Instruction>(shadow);
5444-
llvm::IRBuilder<> builder(shadowInst->getNextNode());
5445-
llvm::Type *shadowTy = IGM.IntPtrTy;
5446-
if (auto *alloca = dyn_cast<llvm::AllocaInst>(shadow)) {
5447-
shadowTy = alloca->getAllocatedType();
5448-
} else if (isCallToSwiftTaskAlloc(shadow)) {
5449-
shadowTy = IGM.Int8Ty;
5450-
}
5451-
assert(!IGM.getLLVMContext().supportsTypedPointers() ||
5452-
shadowTy == shadow->getType()->getNonOpaquePointerElementType());
5453-
addr = builder.CreateLoad(shadowTy, shadow);
5454-
}
5455-
54565440
bindArchetypes(DbgTy.getType());
54575441
if (IGM.DebugInfo) {
54585442
emitDebugVariableDeclaration(addr, DbgTy, SILTy, DS, i->getLoc(), *VarInfo,

test/DebugInfo/async-lifetime-extension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
// CHECK-LABEL: define {{.*}} void @"$s1a4fiboyS2iYaFTY0_"
1010
// CHECK-NEXT: entryresume.0:
11-
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[R:[0-9]+]], {{.*}}!DIExpression(DW_OP
1211
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[N:[0-9]+]], {{.*}}!DIExpression(DW_OP
12+
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[R:[0-9]+]], {{.*}}!DIExpression(DW_OP
1313
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[LHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
1414
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[RHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
1515
// CHECK-NOT: {{ ret }}

test/DebugInfo/async-task-alloc.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o - \
2+
// RUN: -module-name a -disable-availability-checking \
3+
// RUN: | %FileCheck %s --check-prefix=CHECK
4+
// REQUIRES: concurrency
5+
6+
// Test dynamically allocated local variables in async functions.
7+
8+
// CHECK-LABEL: define {{.*}} void @"$s1a1fyxxYalF"
9+
// CHECK: swift_task_alloc
10+
// CHECK-LABEL: define {{.*}} void @"$s1a1fyxxYalFTY0_"
11+
// CHECK-NEXT: entryresume.0:
12+
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[T:[0-9]+]], {{.*}}!DIExpression({{.*}}DW_OP_deref
13+
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[DYNA:[0-9]+]], {{.*}}!DIExpression({{.*}}DW_OP_deref
14+
15+
// CHECK: ![[DYNA]] = !DILocalVariable(name: "dyna"
16+
// CHECK: ![[T]] = !DILocalVariable(name: "t"
17+
public func f<T>(_ t: T) async -> T {
18+
let dyna = t
19+
return dyna
20+
}

0 commit comments

Comments
 (0)