Skip to content

Commit 674d2e7

Browse files
committed
Switch to an artificial debug location before emitting a shadow copy store.
This prevents (among other things) an unexpected step to the end of the scope while initializing a guard variable. <rdar://problem/25427596>
1 parent ff5b879 commit 674d2e7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ class IRGenSILFunction :
653653
auto &Alloca = ShadowStackSlots[{ArgNo, {Scope, Name}}];
654654
if (!Alloca.isValid())
655655
Alloca = createAlloca(Ty, Align, Name+".addr");
656+
657+
ArtificialLocation AutoRestore(Scope, IGM.DebugInfo, Builder);
656658
Builder.CreateStore(Storage, Alloca.getAddress(), Align);
657659
return Alloca.getAddress();
658660
}

test/DebugInfo/guard-let.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o - | FileCheck %s
2+
func use<T>(_ t: T) {}
3+
4+
public func f(_ i : Int?)
5+
{
6+
// CHECK: define {{.*}}@_TF4main1fFGSqSi_T_
7+
// CHECK: %[[PHI:.*]] = phi
8+
// The shadow copy store should not have a location.
9+
// CHECK: store i64 %[[PHI]], i64* %val.addr, align 8, !dbg ![[DBG0:.*]]
10+
// CHECK: @llvm.dbg.declare(metadata i64* %val.addr, {{.*}}, !dbg ![[DBG1:.*]]
11+
// CHECK: ![[DBG0]] = !DILocation(line: 0,
12+
// CHECK: ![[DBG1]] = !DILocation(line: [[@LINE+1]],
13+
guard let val = i else { return }
14+
use(val)
15+
}

0 commit comments

Comments
 (0)