diff --git a/lib/SIL/IR/SILPrinter.cpp b/lib/SIL/IR/SILPrinter.cpp index a0d29d2692ab2..21715c837ebf7 100644 --- a/lib/SIL/IR/SILPrinter.cpp +++ b/lib/SIL/IR/SILPrinter.cpp @@ -73,6 +73,11 @@ llvm::cl::opt SILPrintDebugInfo("sil-print-debuginfo", llvm::cl::init(false), llvm::cl::desc("Include debug info in SIL output")); +llvm::cl::opt + SILPrintDebugInfoVerbose("sil-print-debuginfo-verbose", + llvm::cl::init(false), + llvm::cl::desc("Print verbose debug info output")); + llvm::cl::opt SILPrintSourceInfo("sil-print-sourceinfo", llvm::cl::init(false), llvm::cl::desc("Include source annotation in SIL output")); @@ -1071,6 +1076,22 @@ class SILPrinter : public SILInstructionVisitor { *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"; + } } } diff --git a/lib/SILGen/SILGenExpr.cpp b/lib/SILGen/SILGenExpr.cpp index 6c82055ef77c5..2e8d199d3f8d8 100644 --- a/lib/SILGen/SILGenExpr.cpp +++ b/lib/SILGen/SILGenExpr.cpp @@ -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, diff --git a/test/DebugInfo/shadowcopy-linetable.swift b/test/DebugInfo/shadowcopy-linetable.swift index a71f6b02e423b..7b62ffd9ab8e3 100644 --- a/test/DebugInfo/shadowcopy-linetable.swift +++ b/test/DebugInfo/shadowcopy-linetable.swift @@ -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) {} 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 } diff --git a/test/DebugInfo/sil-print-debuginfo-verbose.swift b/test/DebugInfo/sil-print-debuginfo-verbose.swift new file mode 100644 index 0000000000000..2bba90512f227 --- /dev/null +++ b/test/DebugInfo/sil-print-debuginfo-verbose.swift @@ -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 +} \ No newline at end of file