Skip to content

[DebugInfo] Use Stmt EndLoc if SILLocation passed in is the Stmt EndLoc. #79833

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

Merged
merged 1 commit into from
Mar 19, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/SIL/IR/SILLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,14 @@ RegularLocation::getDebugOnlyExtendedASTNodeLoc(SILLocation L,
return new (Module) ExtendedASTNodeLoc(Empty, {D, 0});
if (auto E = L.getAsASTNode<Expr>())
return new (Module) ExtendedASTNodeLoc(Empty, {E, 0});
if (auto S = L.getAsASTNode<Stmt>())
if (auto S = L.getAsASTNode<Stmt>()) {
// If the source location of the SILLocation passed in matches the EndLoc of
// the Stmt, set the primary ASTNodeTy integer to 1, so that
// SILLocation::getSourceLoc returns the EndLoc when queried.
if (L.getSourceLocForDebugging() == S->getEndLoc())
Empty.setInt(1);
return new (Module) ExtendedASTNodeLoc(Empty, {S, 0});
}
auto P = L.getAsASTNode<Pattern>();
return new (Module) ExtendedASTNodeLoc(Empty, {P, 0});
}
Expand Down
24 changes: 24 additions & 0 deletions test/DebugInfo/hop_to_executor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %target-swiftc_driver %s -c -g -Onone -o - -Xllvm -sil-print-debuginfo -emit-sil -parse-as-library -module-name m | %FileCheck %s

// This test ensures that the hop_to_executor source location matches the end of the do block

func getTimestamp(x: Int) async -> Int {
return 40 + x
}
func work() {}
func foo() async {
do {
work()
async let timestamp2 = getTimestamp(x:2)
print(await timestamp2)
// CHECK: %[[REG:[0-9]+]] = function_ref @swift_asyncLet_finish : $@convention(thin) @async (Builtin.RawPointer, Builtin.RawPointer) -> (), loc {{.*}}:[[@LINE+3]]
// CHECK-NEXT: %{{[0-9]+}} = apply %[[REG]](%{{[0-9]+}}, %{{[0-9]+}}) : $@convention(thin) @async (Builtin.RawPointer, Builtin.RawPointer) -> (), loc{{.*}}:[[@LINE+2]]
// CHECK-NEXT: hop_to_executor %0, loc * {{.*}}:[[@LINE+1]]
}
work()
}
@main enum entry {
static func main() async {
await foo()
}
}