Skip to content

Commit 1bd3f56

Browse files
Merge pull request #4504 from swiftwasm/main
[pull] swiftwasm from main
2 parents 52fbefd + 2f0ae44 commit 1bd3f56

9 files changed

+200
-21
lines changed

CODE_OWNERS.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ E: [email protected]
3737
G: jckarter
3838
D: SIL, SILGen, everything in Swift not covered by someone else
3939

40-
N: Argyrios Kyrzidis
40+
N: Argyrios Kyrtzidis
4141
4242
G: akyrtzi
4343
D: IDE, Index, SourceKit, swift-ide-test

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,11 @@ void swift::visitProductLeafAccessPathNodes(
14001400
worklist.push_back({silType.getTupleElementType(index), elementNode});
14011401
}
14021402
} else if (auto *decl = silType.getStructOrBoundGenericStruct()) {
1403+
if (decl->isResilient(tec.getContext()->getParentModule(),
1404+
tec.getResilienceExpansion())) {
1405+
visitor(AccessPath::PathNode(node), silType);
1406+
continue;
1407+
}
14031408
unsigned index = 0;
14041409
for (auto *field : decl->getStoredProperties()) {
14051410
auto *fieldNode = node->getChild(index);

lib/SILOptimizer/Mandatory/MoveKillsCopyableAddressesChecker.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,10 @@ bool GatherLexicalLifetimeUseVisitor::visitUse(Operand *op,
13631363
if (isa<DeallocStackInst>(op->getUser()))
13641364
return true;
13651365

1366+
// Ignore end_access.
1367+
if (isa<EndAccessInst>(op->getUser()))
1368+
return true;
1369+
13661370
LLVM_DEBUG(llvm::dbgs() << "Found liveness use: " << *op->getUser());
13671371
useState.livenessUses.insert(op->getUser());
13681372

@@ -1507,6 +1511,24 @@ bool DataflowState::cleanupAllDestroyAddr(
15071511
SILBuilderWithScope builder(iter);
15081512
auto *dvi = builder.createDestroyAddr(
15091513
RegularLocation::getAutoGeneratedLocation(), address);
1514+
// Create a debug_value undef if we have debug info to stop the async dbg
1515+
// info propagation from creating debug info for an already destroyed
1516+
// value. We use a separate builder since we need to control the debug
1517+
// scope/location to get llvm to do the right thing.
1518+
if (addressDebugInst) {
1519+
if (auto varInfo = addressDebugInst.getVarInfo()) {
1520+
// We need to always insert /after/ the reinit since the value will
1521+
// not be defined before the value.
1522+
SILBuilderWithScope dbgValueInsertBuilder(dvi);
1523+
dbgValueInsertBuilder.setCurrentDebugScope(
1524+
addressDebugInst->getDebugScope());
1525+
dbgValueInsertBuilder.createDebugValue(
1526+
addressDebugInst.inst->getLoc(),
1527+
SILUndef::get(address->getType(), dvi->getModule()), *varInfo,
1528+
false,
1529+
/*was moved*/ true);
1530+
}
1531+
}
15101532
useState.destroys.insert(dvi);
15111533
continue;
15121534
}

test/DebugInfo/move_function_dbginfo_async.swift

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// RUN: %target-swift-frontend -parse-as-library -disable-availability-checking -g -c %s -o %t/out.o
44
// RUN: %llvm-dwarfdump --show-children %t/out.o | %FileCheck -check-prefix=DWARF %s
55

6-
// REQUIRES: rdar91467528
7-
86
// This test checks that:
97
//
108
// 1. At the IR level, we insert the appropriate llvm.dbg.addr, llvm.dbg.value.
@@ -43,19 +41,19 @@ public func forceSplit() async {}
4341

4442
// CHECK-LABEL: define swifttailcc void @"$s27move_function_dbginfo_async13letSimpleTestyyxnYalF"(%swift.context* swiftasync %0, %swift.opaque* noalias %1, %swift.type* %T)
4543
// CHECK: entry:
46-
// CHECK: call void @llvm.dbg.addr(metadata %swift.context* %0, metadata ![[SIMPLE_TEST_METADATA:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)), !dbg ![[ADDR_LOC:[0-9]+]]
44+
// CHECK: call void @llvm.dbg.addr(metadata %swift.context* %{{[0-9]+}}, metadata ![[SIMPLE_TEST_METADATA:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)), !dbg ![[ADDR_LOC:[0-9]+]]
4745
// CHECK: musttail call swifttailcc void
4846
// CHECK-NEXT: ret void
4947

5048
// CHECK-LABEL: define internal swifttailcc void @"$s27move_function_dbginfo_async13letSimpleTestyyxnYalFTQ0_"(i8* swiftasync %0)
5149
// CHECK: entryresume.0:
52-
// CHECK: call void @llvm.dbg.addr(metadata i8* %0, metadata ![[SIMPLE_TEST_METADATA_2:[0-9]+]], metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)),
50+
// CHECK: call void @llvm.dbg.addr(metadata i8* %{{[0-9]+}}, metadata ![[SIMPLE_TEST_METADATA_2:[0-9]+]], metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)),
5351
// CHECK: musttail call swifttailcc void
5452
// CHECK-NEXT: ret void
5553
//
5654
// CHECK-LABEL: define internal swifttailcc void @"$s27move_function_dbginfo_async13letSimpleTestyyxnYalFTY1_"(i8* swiftasync %0)
5755
// CHECK: entryresume.1:
58-
// CHECK: call void @llvm.dbg.addr(metadata i8* %0, metadata ![[SIMPLE_TEST_METADATA_3:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)), !dbg ![[ADDR_LOC:[0-9]+]]
56+
// CHECK: call void @llvm.dbg.addr(metadata i8* %{{[0-9]+}}, metadata ![[SIMPLE_TEST_METADATA_3:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)), !dbg ![[ADDR_LOC:[0-9]+]]
5957
// CHECK: call void @llvm.dbg.value(metadata %swift.opaque* undef, metadata ![[SIMPLE_TEST_METADATA_3]], metadata !DIExpression(DW_OP_deref)), !dbg ![[ADDR_LOC]]
6058
// CHECK: musttail call swifttailcc void
6159
// CHECK-NEXT: ret void
@@ -83,21 +81,21 @@ public func letSimpleTest<T>(_ msg: __owned T) async {
8381
}
8482

8583
// CHECK-LABEL: define swifttailcc void @"$s27move_function_dbginfo_async13varSimpleTestyyxz_xtYalF"(%swift.context* swiftasync %0, %swift.opaque* %1, %swift.opaque* noalias %2, %swift.type* %T)
86-
// CHECK: call void @llvm.dbg.addr(metadata %swift.context* %0, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref))
84+
// CHECK: call void @llvm.dbg.addr(metadata %swift.context* %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref))
8785
// CHECK: musttail call swifttailcc void @"$s27move_function_dbginfo_async10forceSplityyYaF"(%swift.context* swiftasync %{{[0-9]+}})
8886
// CHECK-NEXT: ret void
8987
// CHECK-NEXT: }
9088
//
9189
// CHECK-LABEL: define internal swifttailcc void @"$s27move_function_dbginfo_async13varSimpleTestyyxz_xtYalFTQ0_"(i8* swiftasync %0)
9290
// CHECK: entryresume.0:
93-
// CHECK: call void @llvm.dbg.addr(metadata i8* %0, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref))
94-
// CHECK: musttail call swifttailcc void @swift_task_switch(%swift.context* swiftasync %9, i8* bitcast (void (i8*)* @"$s27move_function_dbginfo_async13varSimpleTestyyxz_xtYalFTY1_" to i8*), i64 0, i64 0)
91+
// CHECK: call void @llvm.dbg.addr(metadata i8* %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref))
92+
// CHECK: musttail call swifttailcc void @swift_task_switch(%swift.context* swiftasync %{{[0-9]+}}, i8* bitcast (void (i8*)* @"$s27move_function_dbginfo_async13varSimpleTestyyxz_xtYalFTY1_" to i8*), i64 0, i64 0)
9593
// CHECK-NEXT: ret void
9694
// CHECK-NEXT: }
9795
//
9896
// CHECK-LABEL: define internal swifttailcc void @"$s27move_function_dbginfo_async13varSimpleTestyyxz_xtYalFTY1_"(i8* swiftasync %0)
9997
// CHECK: entryresume.1:
100-
// CHECK: call void @llvm.dbg.addr(metadata i8* %0, metadata ![[METADATA:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)), !dbg ![[ADDR_LOC:[0-9]+]]
98+
// CHECK: call void @llvm.dbg.addr(metadata i8* %{{[0-9]+}}, metadata ![[METADATA:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)), !dbg ![[ADDR_LOC:[0-9]+]]
10199
// CHECK: call void @llvm.dbg.value(metadata %swift.opaque* undef, metadata ![[METADATA]], metadata !DIExpression(DW_OP_deref)), !dbg ![[ADDR_LOC]]
102100
// CHECK: musttail call swifttailcc void @"$s27move_function_dbginfo_async10forceSplityyYaF"(%swift.context* swiftasync
103101
// CHECK-NEXT: ret void
@@ -108,9 +106,9 @@ public func letSimpleTest<T>(_ msg: __owned T) async {
108106

109107
// CHECK-LABEL: define internal swifttailcc void @"$s27move_function_dbginfo_async13varSimpleTestyyxz_xtYalFTY3_"(i8* swiftasync %0)
110108
// CHECK: entryresume.3:
111-
// CHECK: call void @llvm.dbg.addr(metadata i8* %0, metadata ![[METADATA:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)), !dbg ![[ADDR_LOC:[0-9]+]]
109+
// CHECK: call void @llvm.dbg.addr(metadata i8* %{{[0-9]+}}, metadata ![[METADATA:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)), !dbg ![[ADDR_LOC:[0-9]+]]
112110
// CHECK: call void @llvm.dbg.value(metadata %swift.opaque* undef, metadata ![[METADATA]], metadata !DIExpression(DW_OP_deref)), !dbg ![[ADDR_LOC]]
113-
// CHECK: call void @llvm.dbg.addr(metadata i8* %0, metadata ![[METADATA]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)), !dbg ![[ADDR_LOC]]
111+
// CHECK: call void @llvm.dbg.addr(metadata i8* %{{[0-9]+}}, metadata ![[METADATA]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8, DW_OP_deref)), !dbg ![[ADDR_LOC]]
114112
// CHECK: musttail call swifttailcc void @"$s27move_function_dbginfo_async10forceSplityyYaF"(
115113
// CHECK-NEXT: ret void
116114
// CHECK-NEXT: }
@@ -192,13 +190,13 @@ public func varSimpleTest<T>(_ msg: inout T, _ msg2: T) async {
192190
// CHECK-NOT: llvm.dbg.addr
193191
//
194192
// CHECK-LABEL: define internal swifttailcc void @"$s27move_function_dbginfo_async16varSimpleTestVaryyYaFTY0_"(i8* swiftasync %0)
195-
// CHECK: call void @llvm.dbg.addr(metadata i8* %0, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8))
193+
// CHECK: call void @llvm.dbg.addr(metadata i8* %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8))
196194
//
197195
// CHECK-LABEL: define internal swifttailcc void @"$s27move_function_dbginfo_async16varSimpleTestVaryyYaFTQ1_"(i8* swiftasync %0)
198-
// CHECK: call void @llvm.dbg.addr(metadata i8* %0, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8))
196+
// CHECK: call void @llvm.dbg.addr(metadata i8* %{{[0-9]+}}, metadata !{{[0-9]+}}, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8))
199197

200198
// CHECK-LABEL: define internal swifttailcc void @"$s27move_function_dbginfo_async16varSimpleTestVaryyYaFTY2_"(i8* swiftasync %0)
201-
// CHECK: call void @llvm.dbg.addr(metadata i8* %0, metadata ![[METADATA:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8)), !dbg ![[ADDR_LOC:[0-9]+]]
199+
// CHECK: call void @llvm.dbg.addr(metadata i8* %{{[0-9]+}}, metadata ![[METADATA:[0-9]+]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8)), !dbg ![[ADDR_LOC:[0-9]+]]
202200
// CHECK: call void @llvm.dbg.value(metadata %T27move_function_dbginfo_async5KlassC** undef, metadata ![[METADATA]], metadata !DIExpression()), !dbg ![[ADDR_LOC]]
203201

204202
// CHECK-LABEL: define internal swifttailcc void @"$s27move_function_dbginfo_async16varSimpleTestVaryyYaFTQ3_"(i8* swiftasync %0)
@@ -212,7 +210,7 @@ public func varSimpleTest<T>(_ msg: inout T, _ msg2: T) async {
212210
//
213211
// CHECK-LABEL: define internal swifttailcc void @"$s27move_function_dbginfo_async16varSimpleTestVaryyYaFTY4_"(i8* swiftasync %0)
214212
// CHECK: call void @llvm.dbg.value(metadata %T27move_function_dbginfo_async5KlassC** undef, metadata ![[METADATA:[0-9]+]], metadata !DIExpression()), !dbg ![[ADDR_LOC:[0-9]+]]
215-
// CHECK: call void @llvm.dbg.addr(metadata i8* %0, metadata ![[METADATA]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8)), !dbg ![[ADDR_LOC]]
213+
// CHECK: call void @llvm.dbg.addr(metadata i8* %{{[0-9]+}}, metadata ![[METADATA]], metadata !DIExpression(DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8)), !dbg ![[ADDR_LOC]]
216214

217215
// We are not an argument, so no problem here.
218216
//

test/Distributed/Runtime/distributed_actor_init_local.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ distributed actor PickATransport1 {
2121
}
2222

2323
distributed actor PickATransport2 {
24-
init(other: Int, thesystem: FakeActorSystem) async {
25-
self.actorSystem = thesystem
24+
init(other: Int, theSystem: FakeActorSystem) async {
25+
self.actorSystem = theSystem
2626
}
2727
}
2828

@@ -240,7 +240,7 @@ func test() async {
240240
// CHECK-NOT: ready
241241
// CHECK: resign id:ActorAddress(address: "[[ID5]]")
242242

243-
test.append(await PickATransport2(other: 1, thesystem: system))
243+
test.append(await PickATransport2(other: 1, theSystem: system))
244244
// CHECK: assign type:PickATransport2, id:ActorAddress(address: "[[ID6:.*]]")
245245
// CHECK: ready actor:main.PickATransport2, id:ActorAddress(address: "[[ID6]]")
246246

test/Distributed/distributed_actor_accessor_thunks_32bit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public distributed actor MyOtherActor {
234234
// CHECK: [[STR_ARG_FLAGS_PTR:%.*]] = getelementptr inbounds { i32, i32, i32 }, { i32, i32, i32 }* %temp-coercion.coerced, i32 0, i32 2
235235
// CHECK: [[STR_ARG_FLAGS:%.*]] = load i32, i32* [[STR_ARG_FLAGS_PTR]]
236236

237-
/// Call distributed thunk with exploaded string value
237+
/// Call distributed thunk with exploded string value
238238

239239
// CHECK: [[THUNK_CONTEXT_PTR:%.*]] = bitcast i8* [[THUNK_ASYNC_CONTEXT]] to %swift.context*
240240

test/Distributed/distributed_actor_accessor_thunks_64bit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public distributed actor MyOtherActor {
221221
// CHECK-NEXT: [[THUNK_ASYNC_CONTEXT:%.*]] = call swiftcc i8* @swift_task_alloc(i64 [[CONTEXT_SIZE_64]])
222222
// CHECK: [[THUNK_CONTEXT_PTR:%.*]] = bitcast i8* [[THUNK_ASYNC_CONTEXT]] to %swift.context*
223223

224-
/// Call distributed thunk with exploaded string value
224+
/// Call distributed thunk with exploded string value
225225

226226
// CHECK: [[THUNK_RESULT:%.*]] = call { i8*, i64, %swift.error* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async.sl_p0i8i64p0s_swift.errorss(
227227
// CHECK-SAME: i8* bitcast (void (%swift.context*, i64, %swift.bridge*, %T27distributed_actor_accessors7MyActorC*)* @"$s27distributed_actor_accessors7MyActorC7simple3ySiSSYaKFTE" to i8*),
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -enable-library-evolution \
3+
// RUN: -emit-module-path=%t/resilient_struct.swiftmodule \
4+
// RUN: -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
5+
6+
// RUN: %target-sil-opt -I %t -opt-mode=speed -enable-sil-verify-all %s -ssa-destroy-hoisting | %FileCheck %s --check-prefix=CHECK
7+
8+
import resilient_struct
9+
10+
struct Twople<Bound> {
11+
@_hasStorage public let lowerBound: Bound { get }
12+
@_hasStorage public let upperBound: Bound { get }
13+
}
14+
15+
sil [ossa] @get_range_out : $@convention(thin) () -> @out Twople<Size>
16+
17+
// Given a non-resilient struct containing two resilient struct fields ONLY ONE
18+
// of which is copy_addr'd out of just before the destroy_addr of the struct,
19+
// DO NOT fold the destroy_addr of the struct into the one copy_addrs--doing so
20+
// would leave the second field initialized.
21+
//
22+
// CHECK: sil [ossa] @dont_fold_into_one_of_two_copy_addr_resilient_struct : {{.*}} {
23+
// CHECK-NOT: copy_addr [take]
24+
// CHECK: copy_addr
25+
// CHECK-NEXT: destroy_addr
26+
// CHECK-LABEL: } // end sil function 'dont_fold_into_one_of_two_copy_addr_resilient_struct'
27+
sil [ossa] @dont_fold_into_one_of_two_copy_addr_resilient_struct : $@convention(thin) () -> () {
28+
bb0:
29+
%range_addr = alloc_stack $Twople<Size>
30+
%get_range_out = function_ref @get_range_out : $@convention(thin) () -> @out Twople<Size>
31+
apply %get_range_out(%range_addr) : $@convention(thin) () -> @out Twople<Size>
32+
%range_upperBound_addr = struct_element_addr %range_addr : $*Twople<Size>, #Twople.upperBound
33+
%date_addr = alloc_stack $Size
34+
copy_addr %range_upperBound_addr to [initialization] %date_addr : $*Size
35+
destroy_addr %range_addr : $*Twople<Size>
36+
destroy_addr %date_addr : $*Size
37+
dealloc_stack %date_addr : $*Size
38+
dealloc_stack %range_addr : $*Twople<Size>
39+
%retval = tuple ()
40+
return %retval : $()
41+
} // end sil function 'dont_fold_into_one_of_two_copy_addr_resilient_struct'
42+
43+
// Given a non-resilient struct containing two resilient fields both of which
44+
// are copy_addr'd out of just before the destroy_addr of the struct, fold the
45+
// destroy_addr of the struct into the two copy_addrs, forming copy_addr
46+
// [take]s.
47+
//
48+
// CHECK: sil [ossa] @fold_into_two_of_two_copy_addr_resilient_struct : {{.*}} {
49+
// CHECK: copy_addr [take]
50+
// CHECK: copy_addr [take]
51+
// CHECK-LABEL: } // end sil function 'fold_into_two_of_two_copy_addr_resilient_struct'
52+
sil [ossa] @fold_into_two_of_two_copy_addr_resilient_struct : $@convention(thin) () -> () {
53+
bb0:
54+
%range_addr = alloc_stack $Twople<Size>
55+
%get_range_out = function_ref @get_range_out : $@convention(thin) () -> @out Twople<Size>
56+
apply %get_range_out(%range_addr) : $@convention(thin) () -> @out Twople<Size>
57+
%range_upperBound_addr = struct_element_addr %range_addr : $*Twople<Size>, #Twople.upperBound
58+
%range_lowerBound_addr = struct_element_addr %range_addr : $*Twople<Size>, #Twople.lowerBound
59+
%date_addr_1 = alloc_stack $Size
60+
%date_addr_2 = alloc_stack $Size
61+
copy_addr %range_upperBound_addr to [initialization] %date_addr_1 : $*Size
62+
copy_addr %range_lowerBound_addr to [initialization] %date_addr_2 : $*Size
63+
destroy_addr %range_addr : $*Twople<Size>
64+
destroy_addr %date_addr_1 : $*Size
65+
destroy_addr %date_addr_2 : $*Size
66+
dealloc_stack %date_addr_2 : $*Size
67+
dealloc_stack %date_addr_1 : $*Size
68+
dealloc_stack %range_addr : $*Twople<Size>
69+
%retval = tuple ()
70+
return %retval : $()
71+
} // end sil function 'dont_fold_into_one_of_two_copy_addr_resilient_struct'
72+

test/SILOptimizer/move_function_kills_addresses_dbginfo.sil

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@
55
sil_stage raw
66

77
import Builtin
8+
import Swift
9+
10+
//////////////////
11+
// Declarations //
12+
//////////////////
13+
14+
public protocol P {
15+
static var value: P { get }
16+
func doSomething()
17+
}
18+
19+
sil @forceSplit : $@convention(thin) @async () -> ()
20+
sil @genericUse : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
21+
22+
enum Optional<T> {
23+
case some(T)
24+
case none
25+
}
26+
27+
///////////
28+
// Tests //
29+
///////////
830

931
// Make sure that when we process a move_addr on an alloc_stack/debug_value that
1032
// we properly put the [moved] marker on them.
@@ -71,3 +93,63 @@ bb3:
7193
%9999 = tuple()
7294
return %9999 : $()
7395
}
96+
97+
// Make sure that we insert a debug_value undef after the destroy_addr that we
98+
// place in block bb2.
99+
// CHECK-LABEL: sil [ossa] @dbg_undef_in_inserted_destroy_addr : $@convention(thin) @async <T where T : P> (@inout T) -> () {
100+
// CHECK: bb2:
101+
// CHECK-NEXT: // function_ref forceSplit
102+
// CHECK-NEXT: function_ref @forceSplit
103+
// CHECK-NEXT: apply
104+
// CHECK-NEXT: debug_value [moved] undef
105+
// CHECK-NEXT: destroy_addr
106+
// CHECK-NEXT: hop_to_executor
107+
// CHECK-NEXT: br bb3
108+
sil [ossa] @dbg_undef_in_inserted_destroy_addr : $@convention(thin) @async <T where T : P> (@inout T) -> () {
109+
bb0(%0 : $*T):
110+
debug_value %0 : $*T, var, name "msg", argno 1, expr op_deref
111+
%2 = enum $Optional<Builtin.Executor>, #Optional.none!enumelt
112+
hop_to_executor %2 : $Optional<Builtin.Executor>
113+
%4 = function_ref @forceSplit : $@convention(thin) @async () -> ()
114+
%5 = apply %4() : $@convention(thin) @async () -> ()
115+
hop_to_executor %2 : $Optional<Builtin.Executor>
116+
cond_br undef, bb1, bb2
117+
118+
bb1:
119+
%11 = alloc_stack $T
120+
%12 = begin_access [modify] [static] %0 : $*T
121+
mark_unresolved_move_addr %12 to %11 : $*T
122+
end_access %12 : $*T
123+
%21 = function_ref @genericUse : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
124+
%22 = apply %21<T>(%11) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
125+
destroy_addr %11 : $*T
126+
dealloc_stack %11 : $*T
127+
%25 = function_ref @forceSplit : $@convention(thin) @async () -> ()
128+
%26 = apply %25() : $@convention(thin) @async () -> ()
129+
hop_to_executor %2 : $Optional<Builtin.Executor>
130+
br bb3
131+
132+
bb2:
133+
%29 = function_ref @forceSplit : $@convention(thin) @async () -> ()
134+
%30 = apply %29() : $@convention(thin) @async () -> ()
135+
hop_to_executor %2 : $Optional<Builtin.Executor>
136+
br bb3
137+
138+
bb3:
139+
%33 = alloc_stack $P
140+
%34 = metatype $@thick T.Type
141+
%35 = witness_method $T, #P.value!getter : <Self where Self : P> (Self.Type) -> () -> P : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@thick τ_0_0.Type) -> @out P
142+
%36 = apply %35<T>(%33, %34) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@thick τ_0_0.Type) -> @out P
143+
%37 = alloc_stack $T
144+
unconditional_checked_cast_addr P in %33 : $*P to T in %37 : $*T
145+
%39 = begin_access [modify] [static] %0 : $*T
146+
copy_addr [take] %37 to %39 : $*T
147+
end_access %39 : $*T
148+
dealloc_stack %37 : $*T
149+
dealloc_stack %33 : $*P
150+
%44 = function_ref @forceSplit : $@convention(thin) @async () -> ()
151+
%45 = apply %44() : $@convention(thin) @async () -> ()
152+
hop_to_executor %2 : $Optional<Builtin.Executor>
153+
%47 = tuple ()
154+
return %47 : $()
155+
}

0 commit comments

Comments
 (0)