Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IRGen debug info for swift_task_alloc'ed variables. #62542

Merged
merged 1 commit into from Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 5 additions & 21 deletions lib/IRGen/IRGenSIL.cpp
Expand Up @@ -5390,8 +5390,11 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
assert(isa<llvm::AllocaInst>(addr) || isa<llvm::UndefValue>(addr) ||
isa<llvm::IntrinsicInst>(addr) || isCallToSwiftTaskAlloc(addr));

auto Indirection =
InCoroContext(*CurSILFn, *i) ? CoroDirectValue : DirectValue;
auto Indirection = DirectValue;
if (InCoroContext(*CurSILFn, *i))
Indirection =
isCallToSwiftTaskAlloc(addr) ? CoroIndirectValue : CoroDirectValue;

if (!IGM.IRGen.Opts.DisableDebuggerShadowCopies &&
!IGM.IRGen.Opts.shouldOptimize())
if (auto *Alloca = dyn_cast<llvm::AllocaInst>(addr))
Expand Down Expand Up @@ -5435,25 +5438,6 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
} else
return;

// Async functions use the value of the artificial address.
auto shadow = addr;
if (CurSILFn->isAsync() && emitLifetimeExtendingUse(shadow) &&
!isa<llvm::UndefValue>(shadow)) {
if (ValueVariables.insert(shadow).second)
ValueDomPoints.push_back({shadow, getActiveDominancePoint()});
auto shadowInst = cast<llvm::Instruction>(shadow);
llvm::IRBuilder<> builder(shadowInst->getNextNode());
llvm::Type *shadowTy = IGM.IntPtrTy;
if (auto *alloca = dyn_cast<llvm::AllocaInst>(shadow)) {
shadowTy = alloca->getAllocatedType();
} else if (isCallToSwiftTaskAlloc(shadow)) {
shadowTy = IGM.Int8Ty;
}
assert(!IGM.getLLVMContext().supportsTypedPointers() ||
shadowTy == shadow->getType()->getNonOpaquePointerElementType());
addr = builder.CreateLoad(shadowTy, shadow);
}

bindArchetypes(DbgTy.getType());
if (IGM.DebugInfo) {
emitDebugVariableDeclaration(addr, DbgTy, SILTy, DS, i->getLoc(), *VarInfo,
Expand Down
2 changes: 1 addition & 1 deletion test/DebugInfo/async-lifetime-extension.swift
Expand Up @@ -8,8 +8,8 @@

// CHECK-LABEL: define {{.*}} void @"$s1a4fiboyS2iYaFTY0_"
// CHECK-NEXT: entryresume.0:
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[R:[0-9]+]], {{.*}}!DIExpression(DW_OP
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[N:[0-9]+]], {{.*}}!DIExpression(DW_OP
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[R:[0-9]+]], {{.*}}!DIExpression(DW_OP
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[LHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[RHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
// CHECK-NOT: {{ ret }}
Expand Down
20 changes: 20 additions & 0 deletions test/DebugInfo/async-task-alloc.swift
@@ -0,0 +1,20 @@
// RUN: %target-swift-frontend %s -emit-ir -g -o - \
// RUN: -module-name a -disable-availability-checking \
// RUN: | %FileCheck %s --check-prefix=CHECK
// REQUIRES: concurrency

// Test dynamically allocated local variables in async functions.

// CHECK-LABEL: define {{.*}} void @"$s1a1fyxxYalF"
// CHECK: swift_task_alloc
// CHECK-LABEL: define {{.*}} void @"$s1a1fyxxYalFTY0_"
// CHECK-NEXT: entryresume.0:
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[T:[0-9]+]], {{.*}}!DIExpression({{.*}}DW_OP_deref
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%0, metadata ![[DYNA:[0-9]+]], {{.*}}!DIExpression({{.*}}DW_OP_deref

// CHECK: ![[DYNA]] = !DILocalVariable(name: "dyna"
// CHECK: ![[T]] = !DILocalVariable(name: "t"
public func f<T>(_ t: T) async -> T {
let dyna = t
return dyna
}