Skip to content

Commit e67d8bf

Browse files
committed
Fix IRGen debug info for swift_task_alloc'ed variables.
The old code attempted to load the variable despite not knowing its size. Fixed by describing the variable's address on the task heap.
1 parent 0b05a1e commit e67d8bf

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
@@ -5390,8 +5390,11 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
53905390
assert(isa<llvm::AllocaInst>(addr) || isa<llvm::UndefValue>(addr) ||
53915391
isa<llvm::IntrinsicInst>(addr) || isCallToSwiftTaskAlloc(addr));
53925392

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

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