Skip to content

Commit 256171b

Browse files
Merge pull request #79584 from rastogishubham/FixASANBug6.1
[🍒][6.1] Pass correct SubExpr as source location when emitting Load of LValue
2 parents 8aff1bd + e225a80 commit 256171b

File tree

4 files changed

+61
-13
lines changed

4 files changed

+61
-13
lines changed

lib/SIL/IR/SILPrinter.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ llvm::cl::opt<bool>
7373
SILPrintDebugInfo("sil-print-debuginfo", llvm::cl::init(false),
7474
llvm::cl::desc("Include debug info in SIL output"));
7575

76+
llvm::cl::opt<bool>
77+
SILPrintDebugInfoVerbose("sil-print-debuginfo-verbose",
78+
llvm::cl::init(false),
79+
llvm::cl::desc("Print verbose debug info output"));
80+
7681
llvm::cl::opt<bool>
7782
SILPrintSourceInfo("sil-print-sourceinfo", llvm::cl::init(false),
7883
llvm::cl::desc("Include source annotation in SIL output"));
@@ -1071,6 +1076,22 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
10711076
*this << "* ";
10721077
*this << QuotedString(DL.filename) << ':' << DL.line << ':'
10731078
<< (unsigned)DL.column;
1079+
if (SILPrintDebugInfoVerbose) {
1080+
if (Loc.isImplicit())
1081+
*this << " isImplicit: " << "true";
1082+
else
1083+
*this << " isImplicit: " << "false";
1084+
1085+
if (Loc.isAutoGenerated())
1086+
*this << ", isAutoGenerated: " << "true";
1087+
else
1088+
*this << ", isAutoGenerated: " << "false";
1089+
1090+
if (Loc.isHiddenFromDebugInfo())
1091+
*this << ", isHiddenFromDebugInfo: " << "true";
1092+
else
1093+
*this << ", isHiddenFromDebugInfo: " << "false";
1094+
}
10741095
}
10751096
}
10761097

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,8 @@ RValue RValueEmitter::visitLoadExpr(LoadExpr *E, SGFContext C) {
10941094
// We can't load at immediate +0 from the lvalue without deeper analysis,
10951095
// since the access will be immediately ended and might invalidate the value
10961096
// we loaded.
1097-
return SGF.emitLoadOfLValue(E, std::move(lv), C.withFollowingSideEffects());
1097+
return SGF.emitLoadOfLValue(E->getSubExpr(), std::move(lv),
1098+
C.withFollowingSideEffects());
10981099
}
10991100

11001101
SILValue SILGenFunction::emitTemporaryAllocation(SILLocation loc, SILType ty,

test/DebugInfo/shadowcopy-linetable.swift

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1-
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
2-
1+
// RUN: %target-swift-frontend %s -emit-sil -Xllvm -sil-print-debuginfo -Xllvm -sil-print-debuginfo-verbose -g -o - | %FileCheck %s --check-prefix=SILCHECK
2+
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s --check-prefix=IRCHECK
33
func markUsed<T>(_ t: T) {}
44

55
func foo(_ x: inout Int64) {
6+
7+
// Make sure that the begin_access, load, and end_access instructions
8+
// are not marked as isImplicit: true. They should not be implicit
9+
// because they are generated from a member_ref_expr which is the
10+
// lvalue SubExpr of a LoadExpr. LoadExpr's are always implicit, but
11+
// that doesn't necessarily mean their SubExprs are implicit as well.
12+
// SILCHECK: sil hidden @$s4main3fooyys5Int64VzF
13+
// SILCHECK: debug_value %0 : $*Int64, var, name "x", argno 1, expr op_deref, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false, scope 7 // id: %1
14+
// SILCHECK: begin_access [read] [static] %0 : $*Int64, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
15+
// SILCHECK-NEXT: load %2 : $*Int64, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
16+
// SILCHECK-NEXT: end_access %2 : $*Int64, loc * {{.*}} isImplicit: false, isAutoGenerated: true, isHiddenFromDebugInfo: true
17+
618
// Make sure the shadow copy is being made in the prologue or (at
719
// line 0), but the code to load the value from the inout storage is
820
// not.
9-
// CHECK: define hidden swiftcc void @"$s4main3fooyys5Int64VzF"
10-
// CHECK: %[[X:.*]] = alloca ptr, align {{(4|8)}}
11-
// CHECK-NEXT: #dbg_declare
12-
// CHECK-NEXT: call void @llvm.memset.{{.*}}(ptr align {{(4|8)}} %[[X]], i8 0
13-
// CHECK: store ptr %0, ptr %[[X]], align {{(4|8)}}
14-
// CHECK-SAME: !dbg ![[LOC0:.*]]
15-
// CHECK-NEXT: getelementptr inbounds %Ts5Int64V, ptr %0, i32 0, i32 0,
16-
// CHECK-SAME: !dbg ![[LOC0]]
17-
// CHECK: ![[LOC0]] = !DILocation(line: 0,
18-
// CHECK: !DILocation(line: [[@LINE+1]],
21+
// IRCHECK: define hidden swiftcc void @"$s4main3fooyys5Int64VzF"
22+
// IRCHECK: %[[X:.*]] = alloca ptr, align {{(4|8)}}
23+
// IRCHECK-NEXT: #dbg_declare
24+
// IRCHECK-NEXT: call void @llvm.memset.{{.*}}(ptr align {{(4|8)}} %[[X]], i8 0
25+
// IRCHECK: store ptr %0, ptr %[[X]], align {{(4|8)}}
26+
// IRCHECK-SAME: !dbg ![[LOC0:.*]]
27+
// IRCHECK-NEXT: %[[VALUE:.*]] = getelementptr inbounds %Ts5Int64V, ptr %0, i32 0, i32 0,
28+
// IRCHECK-SAME: !dbg ![[LOCLOAD:.*]]
29+
// IRCHECK-NEXT: load i64, ptr %[[VALUE]], align {{(4|8)}}
30+
// IRCHECK-SAME: !dbg ![[LOCLOAD]]
31+
// IRCHECK: ![[LOC0]] = !DILocation(line: 0,
32+
// IRCHECK: !DILocation(line: [[@LINE+1]],
1933
x = x + 2
2034
}
2135

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend %s -Xllvm -sil-print-debuginfo -Xllvm -sil-print-debuginfo-verbose -emit-sil -Onone -g -o - | %FileCheck %s
2+
// CHECK: %0 = alloc_stack [var_decl] $Int64, var, name "x", type $Int64, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
3+
// CHECK-NEXT: %1 = integer_literal $Builtin.Int64, 1, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
4+
// CHECK-NEXT: %2 = struct $Int64 (%1 : $Builtin.Int64), loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
5+
// CHECK-NEXT: store %2 to %0 : $*Int64, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
6+
// CHECK-NEXT: dealloc_stack %0 : $*Int64, loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
7+
// CHECK-NEXT: %5 = tuple (), loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
8+
// CHECK-NEXT: return %5 : $(), loc {{.*}} isImplicit: false, isAutoGenerated: false, isHiddenFromDebugInfo: false
9+
10+
func main() {
11+
var x : Int64 = 1
12+
}

0 commit comments

Comments
 (0)