Skip to content

Commit 36b1fee

Browse files
authored
Merge pull request #66221 from eeckstein/fix-arc-sequence-opts
ARCSequenceOpts: fix a wrong handling of applies with indirect out arguments
2 parents 1d90de1 + 895b4df commit 36b1fee

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

lib/SILOptimizer/Analysis/ARCAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ mayGuaranteedUseValue(SILInstruction *User, SILValue Ptr, AliasAnalysis *AA) {
501501
for (unsigned i : indices(Params)) {
502502
if (!Params[i].isGuaranteed())
503503
continue;
504-
SILValue Op = FAS.getArgument(i);
504+
SILValue Op = FAS.getArgumentsWithoutIndirectResults()[i];
505505
if (!AA->isNoAlias(Op, Ptr))
506506
return true;
507507
}

test/SILOptimizer/arcsequenceopts.sil

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ class C {
4949
var w : FakeOptional<Builtin.NativeObject>
5050
}
5151

52+
enum E {
53+
case A(C)
54+
case B
55+
}
56+
57+
struct StructWithEnum {
58+
@_hasStorage var e: E { get }
59+
init(e: E)
60+
}
61+
62+
5263
sil @cls_use : $@convention(thin) (@owned Cls) -> ()
5364

5465
class Container {
@@ -2391,3 +2402,43 @@ bb0:
23912402
%15 = tuple ()
23922403
return %15 : $()
23932404
}
2405+
2406+
sil @closure : $@convention(thin) (@inout E, @guaranteed C) -> ()
2407+
sil @call_closure : $@convention(method) (@guaranteed @noescape @callee_guaranteed (@inout E) -> (), @inout StructWithEnum) -> @out S2
2408+
2409+
// CHECK-LABEL: sil @test_apply_with_out_arg :
2410+
// CHECK: retain_value
2411+
// CHECK: strong_release
2412+
// CHECK: release_value
2413+
// CHECK: } // end sil function 'test_apply_with_out_arg'
2414+
sil @test_apply_with_out_arg : $@convention(method) (@guaranteed StructWithEnum) -> () {
2415+
bb0(%0 : $StructWithEnum):
2416+
%1 = alloc_stack $StructWithEnum
2417+
store %0 to %1 : $*StructWithEnum
2418+
%3 = struct_element_addr %1 : $*StructWithEnum, #StructWithEnum.e
2419+
%4 = load %3 : $*E
2420+
retain_value %4 : $E
2421+
switch_enum %4 : $E, case #E.A!enumelt: bb1, default bb2
2422+
2423+
2424+
bb1(%7 : $C):
2425+
%8 = alloc_stack $S2
2426+
%9 = function_ref @closure : $@convention(thin) (@inout E, @guaranteed C) -> ()
2427+
%10 = partial_apply [callee_guaranteed] [on_stack] %9(%7) : $@convention(thin) (@inout E, @guaranteed C) -> ()
2428+
%11 = function_ref @call_closure : $@convention(method) (@guaranteed @noescape @callee_guaranteed (@inout E) -> (), @inout StructWithEnum) -> @out S2
2429+
%12 = apply %11(%8, %10, %1) : $@convention(method) (@guaranteed @noescape @callee_guaranteed (@inout E) -> (), @inout StructWithEnum) -> @out S2
2430+
dealloc_stack %10 : $@noescape @callee_guaranteed (@inout E) -> ()
2431+
strong_release %7 : $C
2432+
dealloc_stack %8 : $*S2
2433+
br bb3
2434+
2435+
bb2:
2436+
release_value %4 : $E
2437+
br bb3
2438+
2439+
bb3:
2440+
dealloc_stack %1 : $*StructWithEnum
2441+
%21 = tuple ()
2442+
return %21 : $()
2443+
}
2444+

0 commit comments

Comments
 (0)