Skip to content

[6.0] Disable SILCombine::visitInjectEnumAddrInst for empty tuple types #73022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,16 @@ SILCombiner::visitInjectEnumAddrInst(InjectEnumAddrInst *IEAI) {
if (IEAI->getFunction()->hasOwnership())
return nullptr;

// Disable this for empty typle type because empty tuple stack locations maybe
// uninitialized. And converting to value form loses tag information.
if (IEAI->getElement()->hasAssociatedValues()) {
SILType elemType = IEAI->getOperand()->getType().getEnumElementType(
IEAI->getElement(), IEAI->getFunction());
if (elemType.isEmpty(*IEAI->getFunction())) {
return nullptr;
}
}

// Given an inject_enum_addr of a concrete type without payload, promote it to
// a store of an enum. Mem2reg/load forwarding will clean things up for us. We
// can't handle the payload case here due to the flow problems caused by the
Expand Down
10 changes: 5 additions & 5 deletions test/SILOptimizer/sil_combine_enum_addr.sil
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ bb22:
sil @no_init : $@convention(thin) () -> (@out ())

// CHECK-LABEL: sil @test_empty_tuple_uninintialized : $@convention(thin) () -> () {
// CHECK-NOT: inject_enum_addr
// TODO-NOT: inject_enum_addr
// CHECK-LABEL: } // end sil function 'test_empty_tuple_uninintialized'
sil @test_empty_tuple_uninintialized : $@convention(thin) () -> () {
bb0:
Expand All @@ -287,7 +287,7 @@ bb3:
sil @no_init_nested_tuple : $@convention(thin) () -> (@out ((), ()))

// CHECK-LABEL: sil @test_empty_nested_tuple_uninintialized : $@convention(thin) () -> () {
// CHECK-NOT: inject_enum_addr
// TODO-NOT: inject_enum_addr
// CHECK-LABEL: } // end sil function 'test_empty_nested_tuple_uninintialized'
sil @test_empty_nested_tuple_uninintialized : $@convention(thin) () -> () {
bb0:
Expand All @@ -314,7 +314,7 @@ bb3:
sil @no_init_struct : $@convention(thin) () -> (@out ResilientEmptyStruct)

// CHECK-LABEL: sil @test_empty_struct_uninitialized : $@convention(thin) () -> () {
// CHECK-NOT: switch_enum_addr
// TODO-NOT: switch_enum_addr
// CHECK-LABEL: } // end sil function 'test_empty_struct_uninitialized'
sil @test_empty_struct_uninitialized : $@convention(thin) () -> () {
bb0:
Expand All @@ -340,7 +340,7 @@ bb3:
sil @no_init_c_union : $@convention(thin) () -> (@out EmptyCUnion)

// CHECK-LABEL: sil @test_empty_c_union : $@convention(thin) () -> () {
// CHECK: inject_enum_addr
// TODO: inject_enum_addr
// CHECK-LABEL: } // end sil function 'test_empty_c_union'
sil @test_empty_c_union : $@convention(thin) () -> () {
bb0:
Expand Down Expand Up @@ -370,7 +370,7 @@ struct NestedUnreferenceableStorage {
sil @no_init_nested_c_union : $@convention(thin) () -> (@out NestedUnreferenceableStorage)

// CHECK-LABEL: sil @test_empty_nested_c_union : $@convention(thin) () -> () {
// CHECK: inject_enum_addr
// TODO: inject_enum_addr
// CHECK-LABEL: } // end sil function 'test_empty_nested_c_union'
sil @test_empty_nested_c_union : $@convention(thin) () -> () {
bb0:
Expand Down