Fix handling of implicit locations for variables

This commit is contained in:
Adrian Prantl
2023-04-10 17:44:44 -07:00
parent c877a4a802
commit bccc080888
4 changed files with 41 additions and 21 deletions

View File

@@ -176,7 +176,7 @@ SILGenFunction::getSILDebugLocation(SILBuilder &B, SILLocation Loc,
const SILDebugScope *Scope = B.getCurrentDebugScope();
if (!Scope)
Scope = F.getDebugScope();
if (auto *SILScope = getScopeOrNull(Loc)) {
if (auto *SILScope = getScopeOrNull(Loc, ForMetaInstruction)) {
Scope = SILScope;
// Metainstructions such as a debug_value may break the flow of scopes and
// should not change the state of the builder.
@@ -187,14 +187,16 @@ SILGenFunction::getSILDebugLocation(SILBuilder &B, SILLocation Loc,
return SILDebugLocation(overriddenLoc, Scope);
}
const SILDebugScope *SILGenFunction::getScopeOrNull(SILLocation Loc) {
if (Loc.getKind() == SILLocation::CleanupKind ||
Loc.getKind() == SILLocation::ImplicitReturnKind ||
// The source locations produced by the ResultBuilder transformation are
// all over the place.
Loc.isImplicit() ||
Loc.isAutoGenerated())
return nullptr;
const SILDebugScope *SILGenFunction::getScopeOrNull(SILLocation Loc,
bool ForMetaInstruction) {
if (!ForMetaInstruction) {
if (Loc.getKind() == SILLocation::CleanupKind ||
Loc.getKind() == SILLocation::ImplicitReturnKind ||
// The source locations produced by the ResultBuilder transformation are
// all over the place.
Loc.isImplicit() || Loc.isAutoGenerated())
return nullptr;
}
SourceLoc SLoc = Loc.getSourceLoc();//ForDebugging();
if (!SF || LastSourceLoc == SLoc)

View File

@@ -713,7 +713,8 @@ public:
Optional<SILLocation> CurDebugLocOverride,
bool ForMetaInstruction);
const SILDebugScope *getScopeOrNull(SILLocation Loc);
const SILDebugScope *getScopeOrNull(SILLocation Loc,
bool ForMetaInstruction = false);
private:
const SILDebugScope *getOrCreateScope(SourceLoc SLoc);

View File

@@ -1,6 +1,5 @@
// RUN: %target-swift-frontend -module-name a -parse-as-library -emit-sil -g %s | %FileCheck %s
public enum E<T> {
case A(T)
case B(T)
@@ -13,15 +12,15 @@ func sink<T>(_ t: T) {}
public func f<T>(_ e: E<T>) -> [T] {
switch e {
case .A(let a), .B(let a): return [a]
case .D(let a, _, let c): return [a, c]
default:
return []
case .D(let a, _, let c): return [a, c]
default: return []
}
}
// CHECK: sil_scope [[F:[0-9]+]] { loc "{{.*}}":13:13 parent @$s1a1fySayxGAA1EOyxGlF
// CHECK: sil_scope [[S0:[0-9]+]] { loc "{{.*}}":14:3 parent [[F]] }
// CHECK: sil_scope [[A0:[0-9]+]] { loc "{{.*}}":15:3 parent [[S0]] }
// CHECK: sil_scope [[A1:[0-9]+]] { loc "{{.*}}":16:3 parent [[S0]] }
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:15:15, scope [[A0]]
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:15:26, scope [[A0]]
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:16:15, scope [[A1]]
// CHECK: sil_scope [[F:[0-9]+]] { loc "{{.*}}":12:13 parent @$s1a1fySayxGAA1EOyxGlF
// CHECK: sil_scope [[S0:[0-9]+]] { loc "{{.*}}":13:3 parent [[F]] }
// CHECK: sil_scope [[A0:[0-9]+]] { loc "{{.*}}":14:3 parent [[S0]] }
// CHECK: sil_scope [[A1:[0-9]+]] { loc "{{.*}}":15:3 parent [[S0]] }
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:14:15, scope [[A0]]
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:14:26, scope [[A0]]
// CHECK: alloc_stack {{.*}} $T, let, name "a", {{.*}}:15:15, scope [[A1]]

View File

@@ -0,0 +1,18 @@
// RUN: %target-swift-frontend -module-name a -parse-as-library -emit-sil -g %s | %FileCheck %s
func consume<T>(_ t: T) {}
// CHECK: sil_scope [[F:[0-9]+]] { loc "{{.*}}":9:13 parent @$s1a1fyyShySiGSg_ADtF
// CHECK: sil_scope [[S0:[0-9]+]] { loc "{{.*}}":10:3 parent [[F]] }
// CHECK: sil_scope [[S1:[0-9]+]] { loc "{{.*}}":11:3 parent [[S0]] }
// CHECK: sil_scope [[S2:[0-9]+]] { loc "{{.*}}":13:5 parent [[S1]] }
// CHECK: sil_scope [[S3:[0-9]+]] { loc "{{.*}}":14:3 parent [[S0]] }
public func f(_ s1: Set<Int>?, _ s2: Set<Int>?) {
switch (s1, s2) {
case (nil, let a), (let a, nil):
// CHECK: debug_value {{.*}} $Optional<Set<Int>>, let, name "a", {{.*}}:[[@LINE-1]]:18, scope [[S1]]
consume(a)
case (let a?, _):
// CHECK: debug_value {{.*}} $Set<Int>, let, name "a", {{.*}}:[[@LINE-1]]:13, scope [[S3]]
consume((a))
}
}