Skip to content

Commit 6f09b80

Browse files
Merge pull request #79833 from rastogishubham/FixHopToExe
[DebugInfo] Use Stmt EndLoc if SILLocation passed in is the Stmt EndLoc.
2 parents dc41b21 + 7a6070e commit 6f09b80

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/SIL/IR/SILLocation.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,14 @@ RegularLocation::getDebugOnlyExtendedASTNodeLoc(SILLocation L,
290290
return new (Module) ExtendedASTNodeLoc(Empty, {D, 0});
291291
if (auto E = L.getAsASTNode<Expr>())
292292
return new (Module) ExtendedASTNodeLoc(Empty, {E, 0});
293-
if (auto S = L.getAsASTNode<Stmt>())
293+
if (auto S = L.getAsASTNode<Stmt>()) {
294+
// If the source location of the SILLocation passed in matches the EndLoc of
295+
// the Stmt, set the primary ASTNodeTy integer to 1, so that
296+
// SILLocation::getSourceLoc returns the EndLoc when queried.
297+
if (L.getSourceLocForDebugging() == S->getEndLoc())
298+
Empty.setInt(1);
294299
return new (Module) ExtendedASTNodeLoc(Empty, {S, 0});
300+
}
295301
auto P = L.getAsASTNode<Pattern>();
296302
return new (Module) ExtendedASTNodeLoc(Empty, {P, 0});
297303
}

test/DebugInfo/hop_to_executor.swift

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-swiftc_driver %s -c -g -Onone -o - -Xllvm -sil-print-debuginfo -emit-sil -parse-as-library -module-name m | %FileCheck %s
2+
3+
// This test ensures that the hop_to_executor source location matches the end of the do block
4+
5+
func getTimestamp(x: Int) async -> Int {
6+
return 40 + x
7+
}
8+
func work() {}
9+
func foo() async {
10+
do {
11+
work()
12+
async let timestamp2 = getTimestamp(x:2)
13+
print(await timestamp2)
14+
// CHECK: %[[REG:[0-9]+]] = function_ref @swift_asyncLet_finish : $@convention(thin) @async (Builtin.RawPointer, Builtin.RawPointer) -> (), loc {{.*}}:[[@LINE+3]]
15+
// CHECK-NEXT: %{{[0-9]+}} = apply %[[REG]](%{{[0-9]+}}, %{{[0-9]+}}) : $@convention(thin) @async (Builtin.RawPointer, Builtin.RawPointer) -> (), loc{{.*}}:[[@LINE+2]]
16+
// CHECK-NEXT: hop_to_executor %0, loc * {{.*}}:[[@LINE+1]]
17+
}
18+
work()
19+
}
20+
@main enum entry {
21+
static func main() async {
22+
await foo()
23+
}
24+
}

0 commit comments

Comments
 (0)