Skip to content

Commit 3b32ee8

Browse files
authored
Merge pull request #8702 from gottesmm/move_ome_past_no_return_folding
[semantic-sil] Move the ownership model eliminator past no return folding.
2 parents dbb7169 + e7b8865 commit 3b32ee8

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

lib/SIL/SILOwnershipVerifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ static bool compatibleOwnershipKinds(ValueOwnershipKind K1,
176176

177177
static bool isValueAddressOrTrivial(SILValue V, SILModule &M) {
178178
return V->getType().isAddress() ||
179-
V.getOwnershipKind() == ValueOwnershipKind::Trivial;
179+
V.getOwnershipKind() == ValueOwnershipKind::Trivial ||
180+
V.getOwnershipKind() == ValueOwnershipKind::Any;
180181
}
181182

182183
static bool isOwnershipForwardingValueKind(ValueKind K) {

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ static void addMandatoryOptPipeline(SILPassPipelinePlan &P,
8080
P.addDiagnoseStaticExclusivity();
8181
P.addCapturePromotion();
8282
P.addAllocBoxToStack();
83-
84-
P.addOwnershipModelEliminator();
8583
P.addNoReturnFolding();
84+
P.addOwnershipModelEliminator();
8685
P.addDefiniteInitialization();
8786

8887
P.addAccessEnforcementSelection();
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %target-sil-opt -module-name Swift -enable-sil-ownership -enable-sil-verify-all -noreturn-folding < %s | %FileCheck %s
2+
3+
import Builtin
4+
5+
enum Never {}
6+
7+
struct Int64 {
8+
var value: Builtin.Int64
9+
}
10+
11+
// We used to crash on this IR. We would delete "%4" while there is still a
12+
// (dead) user "%7" around.
13+
14+
// CHECK-LABEL: unreachable_outside_block_user
15+
// CHECK: %[[E:.+]] = function_ref @exit
16+
// CHECK: apply %[[E]]
17+
// CHECK: unreachable
18+
19+
sil private @unreachable_outside_block_user : $@convention(thin) () -> Int64 {
20+
bb0:
21+
%0 = integer_literal $Builtin.Int1, -1
22+
%1 = integer_literal $Builtin.Int32, 3
23+
// function_ref exit
24+
%2 = function_ref @exit : $@convention(thin) (Builtin.Int32) -> Never
25+
%3 = apply %2(%1) : $@convention(thin) (Builtin.Int32) -> Never
26+
%4 = integer_literal $Builtin.Int64, 7
27+
cond_br %0, bb1, bb2
28+
29+
bb1:
30+
%5 = metatype $@thin Int64.Type
31+
%6 = integer_literal $Builtin.Int64, 42
32+
%7 = struct $Int64 (%4 : $Builtin.Int64)
33+
br bb3(%7 : $Int64)
34+
35+
bb2:
36+
%8 = metatype $@thin Int64.Type
37+
%9 = integer_literal $Builtin.Int64, 17
38+
%10 = struct $Int64 (%9 : $Builtin.Int64)
39+
br bb3(%10 : $Int64)
40+
41+
bb3 (%11: @trivial $Int64):
42+
return %11 : $Int64
43+
}
44+
45+
sil @exit : $@convention(thin) (Builtin.Int32) -> Never

0 commit comments

Comments
 (0)