Skip to content

Commit fbe83d5

Browse files
committed
SILPrinter: improve printing of debug locations
* Indicate auto-generated locations: instead of "loc", print "loc *" for auto-generated locations * Print the debug location and scope of SILFunctions
1 parent 6711c90 commit fbe83d5

File tree

6 files changed

+31
-15
lines changed

6 files changed

+31
-15
lines changed

lib/SIL/IR/SILPrinter.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,10 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
10121012
if (!DL.filename.empty()) {
10131013
if (PrintComma)
10141014
*this << ", ";
1015-
*this << "loc " << QuotedString(DL.filename) << ':' << DL.line << ':'
1015+
*this << "loc ";
1016+
if (Loc.isAutoGenerated())
1017+
*this << "* ";
1018+
*this << QuotedString(DL.filename) << ':' << DL.line << ':'
10161019
<< (unsigned)DL.column;
10171020
}
10181021
}
@@ -3012,7 +3015,14 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
30123015
}
30133016
}
30143017

3015-
OS << "// " << demangleSymbol(getName()) << '\n';
3018+
OS << "// " << demangleSymbol(getName());
3019+
if (PrintCtx.printDebugInfo()) {
3020+
auto &SM = getModule().getASTContext().SourceMgr;
3021+
SILPrinter P(PrintCtx);
3022+
P.printDebugLocRef(getLocation(), SM);
3023+
P.printDebugScopeRef(getDebugScope(), SM);
3024+
}
3025+
OS << '\n';
30163026
printClangQualifiedNameCommentIfPresent(OS, getClangDecl());
30173027

30183028
OS << "sil ";

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,12 @@ bool SILParser::parseSILLocation(SILLocation &Loc) {
21172117
if (parseVerbatim("loc"))
21182118
return true;
21192119

2120+
bool isAutoGenerated = false;
2121+
if (P.Tok.isAnyOperator() && P.Tok.getText().startswith("*")) {
2122+
isAutoGenerated = true;
2123+
P.consumeStartingCharacterOfCurrentToken();
2124+
}
2125+
21202126
if (P.Tok.getKind() != tok::string_literal) {
21212127
P.diagnose(P.Tok, diag::expected_tok_in_sil_instr, "string");
21222128
return true;
@@ -2140,7 +2146,7 @@ bool SILParser::parseSILLocation(SILLocation &Loc) {
21402146

21412147
Loc = RegularLocation(fnl);
21422148

2143-
if (*fnl == *SILLocation::getCompilerGeneratedLoc())
2149+
if (isAutoGenerated)
21442150
Loc.markAutoGenerated();
21452151

21462152
return false;

test/DebugInfo/linetable-assign.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
public func g<T>(_ t: T) {}
55
public func f(_ i: Int32) {
66
// CHECK: function_ref @$s4main1fyys5Int32VFyycfU_
7-
// CHECK-SAME: loc "{{.*}}":13:3,
7+
// CHECK-SAME: loc * "{{.*}}":13:3,
88
// CHECK: %[[CLOSURE:.*]] = partial_apply
9-
// CHECK-SAME: loc "{{.*}}":13:3,{{.*}}auto_gen
9+
// CHECK-SAME: loc * "{{.*}}":13:3,{{.*}}auto_gen
1010
// CHECK: store %[[CLOSURE]]
1111
// CHECK-SAME: loc "{{.*}}":12:3,
1212
var closure = // line 12

test/DebugInfo/sroa_mem2reg.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ bb0(%0 : $Int64, %1 : $Int64):
3636
// CHECK-SROA: alloc_stack $Int64, var
3737
// CHECK-SROA-SAME: (name "my_struct", loc "sroa.swift":8:9
3838
// CHECK-SROA-SAME: type $*MyStruct, expr op_fragment:#MyStruct.x
39-
// CHECK-SROA-SAME: loc "<compiler-generated>":0:0
39+
// CHECK-SROA-SAME: loc * "<compiler-generated>":0:0
4040
// CHECK-SROA: alloc_stack $Int64, var
4141
// CHECK-SROA-SAME: (name "my_struct", loc "sroa.swift":8:9
4242
// CHECK-SROA-SAME: type $*MyStruct, expr op_fragment:#MyStruct.y
43-
// CHECK-SROA-SAME: loc "<compiler-generated>":0:0
43+
// CHECK-SROA-SAME: loc * "<compiler-generated>":0:0
4444
%5 = metatype $@thin MyStruct.Type, loc "sroa.swift":8:21, scope 2
4545
%6 = integer_literal $Builtin.Int64, 0, loc "sroa.swift":8:33, scope 2
4646
%7 = struct $Int64 (%6 : $Builtin.Int64), loc "sroa.swift":8:33, scope 2

test/SILGen/concurrent_prologue.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
@MainActor func f() async -> Int {
88
// CHECK: {{^sil .*}}@$s1a1fSiyYaF
9-
// CHECK: %0 = metatype {{.*}}loc "{{.*}}.swift":[[@LINE-2]]:17,{{.*}}:auto_gen
10-
// CHECK: %1 = function_ref {{.*}}loc "{{.*}}.swift":[[@LINE-3]]:17,{{.*}}:auto_gen
11-
// CHECK: %2 = apply %1(%0) {{.*}}loc "{{.*}}.swift":[[@LINE-4]]:17,{{.*}}:auto_gen
12-
// CHECK: begin_borrow {{.*}}loc "{{.*}}.swift":[[@LINE-5]]:17,{{.*}}:auto_gen
13-
// CHECK: hop_to_executor {{.*}}loc "{{.*}}.swift":[[@LINE-6]]:17,{{.*}}
9+
// CHECK: %0 = metatype {{.*}}loc * "{{.*}}.swift":[[@LINE-2]]:17,{{.*}}:auto_gen
10+
// CHECK: %1 = function_ref {{.*}}loc * "{{.*}}.swift":[[@LINE-3]]:17,{{.*}}:auto_gen
11+
// CHECK: %2 = apply %1(%0) {{.*}}loc * "{{.*}}.swift":[[@LINE-4]]:17,{{.*}}:auto_gen
12+
// CHECK: begin_borrow {{.*}}loc * "{{.*}}.swift":[[@LINE-5]]:17,{{.*}}:auto_gen
13+
// CHECK: hop_to_executor {{.*}}loc * "{{.*}}.swift":[[@LINE-6]]:17,{{.*}}
1414
// CHECK: // end sil function '$s1a1fSiyYaF'
1515
return 23
1616
}

test/SILGen/sil_locations.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func captures_tuple<T, U>(x: (T, U)) -> () -> (T, U) {
213213
// CHECK-LABEL: sil hidden [ossa] @$s13sil_locations14captures_tuple{{[_0-9a-zA-Z]*}}F
214214
// CHECK: tuple_element_addr {{.*}}, loc "{{.*}}":[[@LINE-3]]:27
215215
// CHECK: copy_addr {{.*}}, loc "{{.*}}":[[@LINE-4]]:27
216-
// CHECK: function_ref {{.*}}, loc "{{.*}}":[[@LINE-4]]:10
216+
// CHECK: function_ref {{.*}}, loc * "{{.*}}":[[@LINE-4]]:10
217217

218218
// CHECK-LABEL: sil private [ossa] @$s13sil_locations14captures_tuple{{.*}}fU_
219219
// CHECK: copy_addr {{.*}}, loc "{{.*}}":[[@LINE-7]]:11
@@ -438,8 +438,8 @@ func testKeyPathGetterSetterAutogen() -> Struct.InnerStruct {
438438
return s[keyPath: kp]
439439
// Autogenerated keypath getter
440440
// CHECK-LABEL: sil shared [thunk] [ossa] @$s13sil_locations6StructV14structProperty{{[_0-9a-zA-Z]*}}TK
441-
// CHECK: load {{.*}} loc "<compiler-generated>":0:0{{.*}}<invalid loc>:auto_gen
441+
// CHECK: load {{.*}} loc * "<compiler-generated>":0:0{{.*}}<invalid loc>:auto_gen
442442
// Autogenerated keypath setter
443443
// CHECK-LABEL: sil shared [thunk] [ossa] @$s13sil_locations6StructV14structProperty{{[_0-9a-zA-Z]*}}Tk
444-
// CHECK: load {{.*}} loc "<compiler-generated>":0:0{{.*}}<invalid loc>:auto_gen
444+
// CHECK: load {{.*}} loc * "<compiler-generated>":0:0{{.*}}<invalid loc>:auto_gen
445445
}

0 commit comments

Comments
 (0)