From 958a1577b530ea5d5d5caf9c165245144cd52581 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Wed, 31 May 2023 17:41:26 -0700 Subject: [PATCH] Ensure calls to getters have a source location. Calls to getters are implicit because the compiler inserts them on a property access, but the location is useful in backtraces so it should be preserved. rdar://109123395 --- include/swift/SIL/SILLocation.h | 5 ++++- lib/SILGen/SILGenApply.cpp | 5 +++++ test/DebugInfo/lazy-getter.swift | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/DebugInfo/lazy-getter.swift diff --git a/include/swift/SIL/SILLocation.h b/include/swift/SIL/SILLocation.h index ce615155369cf..671eb25443d58 100644 --- a/include/swift/SIL/SILLocation.h +++ b/include/swift/SIL/SILLocation.h @@ -343,7 +343,7 @@ class SILLocation { /// Marks the location as coming from auto-generated body. void markAutoGenerated() { kindAndFlags.fields.autoGenerated = true; } - /// Marks the location as not bein auto-generated. + /// Marks the location as not being auto-generated. /// FIXME: This functionality is only used to work around bugs and should be /// removed. void markNonAutoGenerated() { kindAndFlags.fields.autoGenerated = false; } @@ -364,6 +364,9 @@ class SILLocation { /// and these two properties should be merged. bool isImplicit() const { return kindAndFlags.fields.implicit; } + /// Mark this location as not being implicit. + void markExplicit() { kindAndFlags.fields.implicit = false; } + /// Returns false if the location should be represented in debuginfo. bool isHiddenFromDebugInfo() const { return (isAutoGenerated() || isImplicit()) && !hasASTNodeForDebugging(); diff --git a/lib/SILGen/SILGenApply.cpp b/lib/SILGen/SILGenApply.cpp index b795785437863..c391500da4406 100644 --- a/lib/SILGen/SILGenApply.cpp +++ b/lib/SILGen/SILGenApply.cpp @@ -6635,6 +6635,11 @@ RValue SILGenFunction::emitGetAccessor( // Scope any further writeback just within this operation. FormalEvaluationScope writebackScope(*this); + // Calls to getters are implicit because the compiler inserts them on a + // property access, but the location is useful in backtraces so it should be + // preserved. + loc.markExplicit(); + Callee getter = emitSpecializedAccessorFunctionRef( *this, loc, get, substitutions, selfValue, isSuper, isDirectUse, isOnSelfParameter); diff --git a/test/DebugInfo/lazy-getter.swift b/test/DebugInfo/lazy-getter.swift new file mode 100644 index 0000000000000..4323a3d5c63dd --- /dev/null +++ b/test/DebugInfo/lazy-getter.swift @@ -0,0 +1,10 @@ +// RUN: %target-swift-frontend %s -Onone -emit-ir -g -o - -parse-as-library -module-name a | %FileCheck %s +func use(_ t : T) {} +public func f() -> (() -> ()) { + lazy var i : Int = 0 + return { + // CHECK: call {{.*}} @"$s1a1fyycyF1iL_Sivg"({{.*}}), !dbg ![[GETTER_LOC:[0-9]+]] + // CHECK: ![[GETTER_LOC]] = !DILocation(line: [[@LINE+1]], column: 11 + use(i) + } +}