Skip to content

Commit

Permalink
Merge pull request #66260 from adrian-prantl/109123395
Browse files Browse the repository at this point in the history
Ensure calls to getters have a source location.
  • Loading branch information
adrian-prantl committed Jun 1, 2023
2 parents d16329c + 958a157 commit e74720b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/swift/SIL/SILLocation.h
Expand Up @@ -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; }
Expand All @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions lib/SILGen/SILGenApply.cpp
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions 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 : 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)
}
}

0 comments on commit e74720b

Please sign in to comment.