Skip to content

Commit d58d97d

Browse files
committed
Fix SILCombine of inject_enum_addr of ~Copyable values
Fixes rdar://138798467
1 parent b5a85ed commit d58d97d

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,8 @@ SILCombiner::visitInjectEnumAddrInst(InjectEnumAddrInst *IEAI) {
11321132
IEAI->getOperand()->getType().getObjectType());
11331133
auto storeQual = !func->hasOwnership()
11341134
? StoreOwnershipQualifier::Unqualified
1135+
: IEAI->getOperand()->getType().isMoveOnly()
1136+
? StoreOwnershipQualifier::Init
11351137
: StoreOwnershipQualifier::Trivial;
11361138
Builder.createStore(IEAI->getLoc(), E, IEAI->getOperand(), storeQual);
11371139
return eraseInstFromFunction(*IEAI);

test/SILOptimizer/sil_combine_enums_ossa.sil

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,29 @@ bb0(%0 : $S):
653653
return %11 : $()
654654
}
655655

656+
class Klass {}
657+
658+
// CHECK-LABEL: sil [ossa] @test_nontrivial_enum_inject_enum_addr_opt
659+
// CHECK: [[VAL:%.*]] = enum $Optional<Klass>, #Optional.none!enumelt
660+
// CHECK: store [[VAL]] to [trivial] %0 : $*Optional<Klass>
661+
// CHECK: } // end sil function 'test_nontrivial_enum_inject_enum_addr_opt'
662+
sil [ossa] @test_nontrivial_enum_inject_enum_addr_opt : $@convention(method) (@inout Optional<Klass>) -> @owned Optional<Klass> {
663+
bb0(%0 : $*Optional<Klass>):
664+
%1 = load [take] %0 : $*Optional<Klass>
665+
inject_enum_addr %0 : $*Optional<Klass>, #Optional.none!enumelt
666+
return %1 : $Optional<Klass>
667+
}
668+
669+
struct NC : ~Copyable {}
670+
671+
// CHECK-LABEL: sil [ossa] @test_noncopyable_enum_inject_enum_addr_opt
672+
// CHECK: [[VAL:%.*]] = enum $Optional<NC>, #Optional.none!enumelt
673+
// CHECK: store [[VAL]] to [init] %0 : $*Optional<NC>
674+
// CHECK: } // end sil function 'test_noncopyable_enum_inject_enum_addr_opt'
675+
sil [ossa] @test_noncopyable_enum_inject_enum_addr_opt : $@convention(method) (@inout Optional<NC>) -> @owned Optional<NC> {
676+
bb0(%0 : $*Optional<NC>):
677+
%1 = load [take] %0 : $*Optional<NC>
678+
inject_enum_addr %0 : $*Optional<NC>, #Optional.none!enumelt
679+
return %1 : $Optional<NC>
680+
}
681+

0 commit comments

Comments
 (0)