Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🍒][6.1] Pass correct SubExpr as source location when emitting Load of LValue #79584

Open
wants to merge 2 commits into
base: release/6.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/SIL/IR/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ llvm::cl::opt<bool>
SILPrintDebugInfo("sil-print-debuginfo", llvm::cl::init(false),
llvm::cl::desc("Include debug info in SIL output"));

llvm::cl::opt<bool>
SILPrintDebugInfoVerbose("sil-print-debuginfo-verbose",
llvm::cl::init(false),
llvm::cl::desc("Print verbose debug info output"));

llvm::cl::opt<bool>
SILPrintSourceInfo("sil-print-sourceinfo", llvm::cl::init(false),
llvm::cl::desc("Include source annotation in SIL output"));
Expand Down Expand Up @@ -1071,6 +1076,22 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
*this << "* ";
*this << QuotedString(DL.filename) << ':' << DL.line << ':'
<< (unsigned)DL.column;
if (SILPrintDebugInfoVerbose) {
if (Loc.isImplicit())
*this << " isImplicit: " << "true";
else
*this << " isImplicit: " << "false";

if (Loc.isAutoGenerated())
*this << ", isAutoGenerated: " << "true";
else
*this << ", isAutoGenerated: " << "false";

if (Loc.isHiddenFromDebugInfo())
*this << ", isHiddenFromDebugInfo: " << "true";
else
*this << ", isHiddenFromDebugInfo: " << "false";
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/SILGen/SILGenExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,8 @@ RValue RValueEmitter::visitLoadExpr(LoadExpr *E, SGFContext C) {
// We can't load at immediate +0 from the lvalue without deeper analysis,
// since the access will be immediately ended and might invalidate the value
// we loaded.
return SGF.emitLoadOfLValue(E, std::move(lv), C.withFollowingSideEffects());
return SGF.emitLoadOfLValue(E->getSubExpr(), std::move(lv),
C.withFollowingSideEffects());
}

SILValue SILGenFunction::emitTemporaryAllocation(SILLocation loc, SILType ty,
Expand Down
38 changes: 26 additions & 12 deletions test/DebugInfo/shadowcopy-linetable.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s

// RUN: %target-swift-frontend %s -emit-sil -Xllvm -sil-print-debuginfo -Xllvm -sil-print-debuginfo-verbose -g -o - | %FileCheck %s --check-prefix=SILCHECK
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s --check-prefix=IRCHECK
func markUsed<T>(_ t: T) {}

func foo(_ x: inout Int64) {

// Make sure that the begin_access, load, and end_access instructions
// are not marked as isImplicit: true. They should not be implicit
// because they are generated from a member_ref_expr which is the
// lvalue SubExpr of a LoadExpr. LoadExpr's are always implicit, but
// that doesn't necessarily mean their SubExprs are implicit as well.
// SILCHECK: sil hidden @$s4main3fooyys5Int64VzF
// SILCHECK: debug_value %0 : $*Int64, var, name "x", argno 1, expr op_deref, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false, scope 7 // id: %1
// SILCHECK: begin_access [read] [static] %0 : $*Int64, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
// SILCHECK-NEXT: load %2 : $*Int64, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
// SILCHECK-NEXT: end_access %2 : $*Int64, loc * {{.*}} isImplicit: false, isAutoGenerated: true, isHiddenFromDebugInfo: true

// Make sure the shadow copy is being made in the prologue or (at
// line 0), but the code to load the value from the inout storage is
// not.
// CHECK: define hidden swiftcc void @"$s4main3fooyys5Int64VzF"
// CHECK: %[[X:.*]] = alloca ptr, align {{(4|8)}}
// CHECK-NEXT: #dbg_declare
// CHECK-NEXT: call void @llvm.memset.{{.*}}(ptr align {{(4|8)}} %[[X]], i8 0
// CHECK: store ptr %0, ptr %[[X]], align {{(4|8)}}
// CHECK-SAME: !dbg ![[LOC0:.*]]
// CHECK-NEXT: getelementptr inbounds %Ts5Int64V, ptr %0, i32 0, i32 0,
// CHECK-SAME: !dbg ![[LOC0]]
// CHECK: ![[LOC0]] = !DILocation(line: 0,
// CHECK: !DILocation(line: [[@LINE+1]],
// IRCHECK: define hidden swiftcc void @"$s4main3fooyys5Int64VzF"
// IRCHECK: %[[X:.*]] = alloca ptr, align {{(4|8)}}
// IRCHECK-NEXT: #dbg_declare
// IRCHECK-NEXT: call void @llvm.memset.{{.*}}(ptr align {{(4|8)}} %[[X]], i8 0
// IRCHECK: store ptr %0, ptr %[[X]], align {{(4|8)}}
// IRCHECK-SAME: !dbg ![[LOC0:.*]]
// IRCHECK-NEXT: %[[VALUE:.*]] = getelementptr inbounds %Ts5Int64V, ptr %0, i32 0, i32 0,
// IRCHECK-SAME: !dbg ![[LOCLOAD:.*]]
// IRCHECK-NEXT: load i64, ptr %[[VALUE]], align {{(4|8)}}
// IRCHECK-SAME: !dbg ![[LOCLOAD]]
// IRCHECK: ![[LOC0]] = !DILocation(line: 0,
// IRCHECK: !DILocation(line: [[@LINE+1]],
x = x + 2
}

Expand Down
12 changes: 12 additions & 0 deletions test/DebugInfo/sil-print-debuginfo-verbose.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %target-swift-frontend %s -Xllvm -sil-print-debuginfo -Xllvm -sil-print-debuginfo-verbose -emit-sil -Onone -g -o - | %FileCheck %s
// CHECK: %0 = alloc_stack [var_decl] $Int64, var, name "x", type $Int64, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
// CHECK-NEXT: %1 = integer_literal $Builtin.Int64, 1, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
// CHECK-NEXT: %2 = struct $Int64 (%1 : $Builtin.Int64), loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
// CHECK-NEXT: store %2 to %0 : $*Int64, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
// CHECK-NEXT: dealloc_stack %0 : $*Int64, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
// CHECK-NEXT: %5 = tuple (), loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
// CHECK-NEXT: return %5 : $(), loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false

func main() {
var x : Int64 = 1
}