Skip to content

Commit 2aae121

Browse files
Merge pull request swiftlang#36301 from adrian-prantl/75012612
Support local variables in virtual async backtraces.
2 parents 06a8902 + 3401f8a commit 2aae121

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2457,7 +2457,7 @@ void IRGenDebugInfoImpl::emitDbgIntrinsic(
24572457
// limited, so using a dbg.addr instead of a dbg.declare would be more
24582458
// appropriate.
24592459
DBuilder.insertDeclare(Storage, Var, Expr, DL, BB);
2460-
} else if (InCoroContext && (Var->getArg() || Var->isArtificial())) {
2460+
} else if (InCoroContext) {
24612461
// Function arguments in async functions are emitted without a shadow copy
24622462
// (that would interfer with coroutine splitting) but with a dbg.declare to
24632463
// give CoroSplit.cpp license to emit a shadow copy for them pointing inside

lib/IRGen/IRGenSIL.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,7 @@ class IRGenSILFunction :
962962
if (ValueVariables.insert(Value).second)
963963
ValueDomPoints.push_back({Value, getActiveDominancePoint()});
964964
if (IGM.IRGen.Opts.DisableDebuggerShadowCopies ||
965-
IGM.IRGen.Opts.shouldOptimize() || IsAnonymous ||
966-
(CurSILFn->isAsync() && VarInfo.ArgNo) ||
965+
IGM.IRGen.Opts.shouldOptimize() || IsAnonymous || CurSILFn->isAsync() ||
967966
isa<llvm::AllocaInst>(Storage) || isa<llvm::UndefValue>(Storage) ||
968967
!needsShadowCopy(Storage))
969968
return Storage;
@@ -991,7 +990,7 @@ class IRGenSILFunction :
991990
// Only do this at -O0.
992991
if (IGM.IRGen.Opts.DisableDebuggerShadowCopies ||
993992
IGM.IRGen.Opts.shouldOptimize() || IsAnonymous ||
994-
(CurSILFn->isAsync() && VarInfo.ArgNo)) {
993+
(CurSILFn->isAsync())) {
995994
auto vals = e.claimAll();
996995
copy.append(vals.begin(), vals.end());
997996

@@ -4566,13 +4565,14 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
45664565
return;
45674566

45684567
IndirectionKind Indirection = DirectValue;
4569-
if (CurSILFn->isAsync() && VarInfo->ArgNo &&
4568+
if (CurSILFn->isAsync() &&
45704569
!i->getDebugScope()->InlinedCallSite) {
4571-
for (auto &Val : Copy) {
4572-
Val = getDirectCoroutineArgument(Val);
4573-
assert(IGM.DebugInfo->verifyCoroutineArgument(Val) &&
4574-
"arg expected to be load from inside %swift.context");
4575-
}
4570+
if (VarInfo->ArgNo)
4571+
for (auto &Val : Copy) {
4572+
Val = getDirectCoroutineArgument(Val);
4573+
assert(IGM.DebugInfo->verifyCoroutineArgument(Val) &&
4574+
"arg expected to be load from inside %swift.context");
4575+
}
45764576
Indirection = CoroDirectValue;
45774577
}
45784578

@@ -4602,9 +4602,8 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
46024602
auto *Addr = getLoweredAddress(SILVal).getAddress();
46034603
SILType SILTy = SILVal->getType();
46044604
auto RealType = SILTy.getASTType();
4605-
if (CurSILFn->isAsync() && VarInfo->ArgNo &&
4606-
!i->getDebugScope()->InlinedCallSite) {
4607-
if (IGM.DebugInfo)
4605+
if (CurSILFn->isAsync() && !i->getDebugScope()->InlinedCallSite) {
4606+
if (IGM.DebugInfo && VarInfo->ArgNo)
46084607
assert(IGM.DebugInfo->verifyCoroutineArgument(Addr) &&
46094608
"arg expected to be load from inside %swift.context");
46104609
Indirection = CoroIndirectValue;

test/DebugInfo/async-lifetime-extension.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
// CHECK-LABEL: define {{.*}} void @"$s1a4fiboyS2iYF.resume.0"
1212
// CHECK-NEXT: entryresume.0:
13+
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[RHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
1314
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[R:[0-9]+]], {{.*}}!DIExpression(DW_OP
1415
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[LHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
15-
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[RHS:[0-9]+]], {{.*}}!DIExpression(DW_OP
1616
// CHECK-NEXT: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[N:[0-9]+]], {{.*}}!DIExpression(DW_OP
1717
// CHECK-NOT: {{ ret }}
1818
// CHECK: call void asm sideeffect ""
19+
// CHECK: ![[RHS]] = !DILocalVariable(name: "rhs"
1920
// CHECK: ![[R]] = !DILocalVariable(name: "retval"
2021
// CHECK: ![[LHS]] = !DILocalVariable(name: "lhs"
21-
// CHECK: ![[RHS]] = !DILocalVariable(name: "rhs"
2222
// CHECK: ![[N]] = !DILocalVariable(name: "n"
2323
public func fibo(_ n: Int) async -> Int {
2424
var retval = n

test/DebugInfo/async-local-var.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o - \
2+
// RUN: -module-name a -enable-experimental-concurrency \
3+
// RUN: | %FileCheck %s --check-prefix=CHECK
4+
// REQUIRES: concurrency
5+
6+
// UNSUPPORTED: CPU=arm64e
7+
8+
func getString() async -> String {
9+
return ""
10+
}
11+
12+
func wait() async throws {}
13+
14+
public func makeDinner() async throws -> String {
15+
let local = await getString()
16+
try await wait()
17+
// CHECK-LABEL: define {{.*}} void @"$s1a10makeDinnerSSyYKF.resume.0"
18+
// CHECK-NEXT: entryresume.0:
19+
// CHECK-NOT: {{ ret }}
20+
// CHECK: call void @llvm.dbg.declare(metadata {{.*}}%2, metadata ![[LOCAL:[0-9]+]], {{.*}}!DIExpression(DW_OP_deref
21+
// CHECK: ![[LOCAL]] = !DILocalVariable(name: "local"
22+
return local
23+
}

0 commit comments

Comments
 (0)