Skip to content

Commit db3c33e

Browse files
committed
Fix handling of implicit locations for variables
(cherry picked from commit bccc080)
1 parent d026627 commit db3c33e

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

lib/SILGen/SILGenFunction.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ SILGenFunction::getSILDebugLocation(SILBuilder &B, SILLocation Loc,
176176
const SILDebugScope *Scope = B.getCurrentDebugScope();
177177
if (!Scope)
178178
Scope = F.getDebugScope();
179-
if (auto *SILScope = getScopeOrNull(Loc)) {
179+
if (auto *SILScope = getScopeOrNull(Loc, ForMetaInstruction)) {
180180
Scope = SILScope;
181181
// Metainstructions such as a debug_value may break the flow of scopes and
182182
// should not change the state of the builder.
@@ -187,14 +187,16 @@ SILGenFunction::getSILDebugLocation(SILBuilder &B, SILLocation Loc,
187187
return SILDebugLocation(overriddenLoc, Scope);
188188
}
189189

190-
const SILDebugScope *SILGenFunction::getScopeOrNull(SILLocation Loc) {
191-
if (Loc.getKind() == SILLocation::CleanupKind ||
192-
Loc.getKind() == SILLocation::ImplicitReturnKind ||
193-
// The source locations produced by the ResultBuilder transformation are
194-
// all over the place.
195-
Loc.isImplicit() ||
196-
Loc.isAutoGenerated())
197-
return nullptr;
190+
const SILDebugScope *SILGenFunction::getScopeOrNull(SILLocation Loc,
191+
bool ForMetaInstruction) {
192+
if (!ForMetaInstruction) {
193+
if (Loc.getKind() == SILLocation::CleanupKind ||
194+
Loc.getKind() == SILLocation::ImplicitReturnKind ||
195+
// The source locations produced by the ResultBuilder transformation are
196+
// all over the place.
197+
Loc.isImplicit() || Loc.isAutoGenerated())
198+
return nullptr;
199+
}
198200

199201
SourceLoc SLoc = Loc.getSourceLoc();
200202
if (!SF || LastSourceLoc == SLoc)

lib/SILGen/SILGenFunction.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
713713
Optional<SILLocation> CurDebugLocOverride,
714714
bool ForMetaInstruction);
715715

716-
const SILDebugScope *getScopeOrNull(SILLocation Loc);
716+
const SILDebugScope *getScopeOrNull(SILLocation Loc,
717+
bool ForMetaInstruction = false);
717718

718719
private:
719720
const SILDebugScope *getOrCreateScope(SourceLoc SLoc);

test/DebugInfo/case-scope.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// RUN: %target-swift-frontend -module-name a -parse-as-library -emit-sil -g %s | %FileCheck %s
22

3-
43
public enum E<T> {
54
case A(T)
65
case B(T)
@@ -13,15 +12,15 @@ func sink<T>(_ t: T) {}
1312
public func f<T>(_ e: E<T>) -> [T] {
1413
switch e {
1514
case .A(let a), .B(let a): return [a]
16-
case .D(let a, _, let c): return [a, c]
17-
default:
18-
return []
15+
case .D(let a, _, let c): return [a, c]
16+
default: return []
1917
}
2018
}
21-
// CHECK: sil_scope [[F:[0-9]+]] { loc "{{.*}}":13:13 parent @$s1a1fySayxGAA1EOyxGlF
22-
// CHECK: sil_scope [[S0:[0-9]+]] { loc "{{.*}}":14:3 parent [[F]] }
23-
// CHECK: sil_scope [[A0:[0-9]+]] { loc "{{.*}}":15:3 parent [[S0]] }
24-
// CHECK: sil_scope [[A1:[0-9]+]] { loc "{{.*}}":16:3 parent [[S0]] }
25-
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:15:15, scope [[A0]]
26-
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:15:26, scope [[A0]]
27-
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:16:15, scope [[A1]]
19+
20+
// CHECK: sil_scope [[F:[0-9]+]] { loc "{{.*}}":12:13 parent @$s1a1fySayxGAA1EOyxGlF
21+
// CHECK: sil_scope [[S0:[0-9]+]] { loc "{{.*}}":13:3 parent [[F]] }
22+
// CHECK: sil_scope [[A0:[0-9]+]] { loc "{{.*}}":14:3 parent [[S0]] }
23+
// CHECK: sil_scope [[A1:[0-9]+]] { loc "{{.*}}":15:3 parent [[S0]] }
24+
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:14:15, scope [[A0]]
25+
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:14:26, scope [[A0]]
26+
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:15:15, scope [[A1]]

test/DebugInfo/case-scope2.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend -module-name a -parse-as-library -emit-sil -g %s | %FileCheck %s
2+
func consume<T>(_ t: T) {}
3+
4+
// CHECK: sil_scope [[F:[0-9]+]] { loc "{{.*}}":9:13 parent @$s1a1fyyShySiGSg_ADtF
5+
// CHECK: sil_scope [[S0:[0-9]+]] { loc "{{.*}}":10:3 parent [[F]] }
6+
// CHECK: sil_scope [[S1:[0-9]+]] { loc "{{.*}}":11:3 parent [[S0]] }
7+
// CHECK: sil_scope [[S2:[0-9]+]] { loc "{{.*}}":13:5 parent [[S1]] }
8+
// CHECK: sil_scope [[S3:[0-9]+]] { loc "{{.*}}":14:3 parent [[S0]] }
9+
public func f(_ s1: Set<Int>?, _ s2: Set<Int>?) {
10+
switch (s1, s2) {
11+
case (nil, let a), (let a, nil):
12+
// CHECK: debug_value {{.*}} $Optional<Set<Int>>, let, name "a", {{.*}}:[[@LINE-1]]:18, scope [[S1]]
13+
consume(a)
14+
case (let a?, _):
15+
// CHECK: debug_value {{.*}} $Set<Int>, let, name "a", {{.*}}:[[@LINE-1]]:13, scope [[S3]]
16+
consume((a))
17+
}
18+
}

0 commit comments

Comments
 (0)