Skip to content

Commit a3156cc

Browse files
committed
Use swift::findUnreferenceableStorage to ensure we can construct an struct value
1 parent 2a13234 commit a3156cc

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ SILCombiner::visitInjectEnumAddrInst(InjectEnumAddrInst *IEAI) {
12461246

12471247
// We cannot create a struct when it has unreferenceable storage.
12481248
if (elemType.isEmpty(*IEAI->getFunction()) && structDecl &&
1249-
structDecl->hasUnreferenceableStorage()) {
1249+
findUnreferenceableStorage(structDecl, elemType, IEAI->getFunction())) {
12501250
return nullptr;
12511251
}
12521252

test/SILOptimizer/sil_combine_enum_addr.sil

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,33 @@ bb3:
362362
%8 = tuple ()
363363
return %8 : $()
364364
}
365+
366+
struct NestedUnreferenceableStorage {
367+
let e: EmptyCUnion
368+
}
369+
370+
sil @no_init_nested_c_union : $@convention(thin) () -> (@out NestedUnreferenceableStorage)
371+
372+
// CHECK-LABEL: sil @test_empty_nested_c_union : $@convention(thin) () -> () {
373+
// CHECK: inject_enum_addr
374+
// CHECK-LABEL: } // end sil function 'test_empty_nested_c_union'
375+
sil @test_empty_nested_c_union : $@convention(thin) () -> () {
376+
bb0:
377+
%0 = alloc_stack $Optional<NestedUnreferenceableStorage>
378+
%1 = init_enum_data_addr %0 : $*Optional<NestedUnreferenceableStorage>, #Optional.some!enumelt
379+
%f = function_ref @no_init_nested_c_union : $@convention(thin) () -> (@out NestedUnreferenceableStorage)
380+
apply %f(%1) : $@convention(thin) () -> (@out NestedUnreferenceableStorage)
381+
inject_enum_addr %0 : $*Optional<NestedUnreferenceableStorage>, #Optional.some!enumelt
382+
switch_enum_addr %0 : $*Optional<NestedUnreferenceableStorage>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
383+
384+
bb1:
385+
br bb3
386+
387+
bb2:
388+
br bb3
389+
390+
bb3:
391+
dealloc_stack %0 : $*Optional<NestedUnreferenceableStorage>
392+
%8 = tuple ()
393+
return %8 : $()
394+
}

0 commit comments

Comments
 (0)