Skip to content

Commit 33e547c

Browse files
authored
Merge pull request #17540 from adrian-prantl/scopelocs
2 parents 70e757a + 60c71c9 commit 33e547c

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

include/swift/SIL/SILLocation.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,13 @@ class SILLocation {
406406
/// Return the location as a DeclContext or null.
407407
DeclContext *getAsDeclContext() const;
408408

409+
/// Convert a specialized location kind into a regular location.
410+
SILLocation getAsRegularLocation() {
411+
SILLocation RegularLoc = *this;
412+
RegularLoc.setLocationKind(RegularKind);
413+
return RegularLoc;
414+
}
415+
409416
SourceLoc getDebugSourceLoc() const;
410417
SourceLoc getSourceLoc() const;
411418
SourceLoc getStartSourceLoc() const;

lib/SILGen/SILGenFunction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
441441
void enterDebugScope(SILLocation Loc) {
442442
auto *Parent =
443443
DebugScopeStack.size() ? DebugScopeStack.back() : F.getDebugScope();
444-
auto *DS = new (SGM.M) SILDebugScope(Loc, &getFunction(), Parent);
444+
auto *DS = new (SGM.M)
445+
SILDebugScope(Loc.getAsRegularLocation(), &getFunction(), Parent);
445446
DebugScopeStack.push_back(DS);
446447
B.setCurrentDebugScope(DS);
447448
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %target-swift-frontend -parse-as-library -module-name A -Xllvm -sil-print-debuginfo %s -g -O -o - -emit-sil | %FileCheck %s --check-prefix=SIL
2+
3+
@inline(never)
4+
func yes() -> Bool { return true }
5+
6+
@inline(never)
7+
func use<V>(_ v: V) {}
8+
9+
@inline(__always)
10+
func h<U>(_ u: U) {
11+
yes()
12+
use(u)
13+
}
14+
15+
#sourceLocation(file: "g.swift", line: 1)
16+
@inline(__always) func g<T>(_ t: T) {
17+
if (yes()) {
18+
use(t)
19+
}
20+
}
21+
22+
// SIL: sil_scope [[F:.*]] { {{.*}}parent @$S1A1CC1fyyqd__lF
23+
// SIL: sil_scope [[F0:.*]] { loc "f.swift":1:29 parent [[F]] }
24+
// SIL: sil_scope [[F_G_S:.*]] { loc "f.swift":5:5 parent [[F0]] }
25+
// SIL: sil_scope [[G_S:.*]] { loc "g.swift":2:3 {{.*}} inlined_at [[F_G_S]] }
26+
27+
#sourceLocation(file: "C.swift", line: 1)
28+
public class C<R> {
29+
let r : R
30+
init(_ _r: R) { r = _r }
31+
32+
// SIL: // C.f<A>(_:)
33+
#sourceLocation(file: "f.swift", line: 1)
34+
public func f<S> (_ s: S) {
35+
// SIL: debug_value_addr %0 : $*S, let, name "s", argno 1,
36+
// SIL-SAME: scope [[F]]
37+
// SIL: function_ref {{.*}}yes{{.*}} scope [[G_S]]
38+
g(s)
39+
g(r)
40+
g((s, s))
41+
}
42+
}

0 commit comments

Comments
 (0)