33// RUN: -emit-module-path=%t/resilient_struct.swiftmodule \
44// RUN: -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
55
6- // RUN: %target-sil-opt -enable-sil-verify-all %s -sil-combine -jumpthread-simplify-cfg -I %t | %FileCheck %s
6+ // RUN: %target-sil-opt -sdk %clang-importer-sdk-path - enable-sil-verify-all %s -sil-combine -jumpthread-simplify-cfg -I %t | %FileCheck %s
77
88sil_stage canonical
99
1010import Builtin
1111import Swift
1212
1313import resilient_struct
14+ import ctypes
1415
1516// CHECK-LABEL: sil @convert_inject_enum_addr_select_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> ()
1617// CHECK-NOT: init_existential_addr
4748 br bb1
4849}
4950
50-
5151// CHECK-LABEL: sil @convert_inject_enum_addr_switch_enum_addr_into_cond_br : $@convention(thin) (@in Int, @inout _Stdout) -> ()
5252// CHECK-NOT: init_existential_addr
5353// CHECK-NOT: inject_enum_addr
@@ -122,7 +122,6 @@ bb22:
122122 br bb2
123123}
124124
125-
126125class A {
127126
128127}
@@ -314,10 +313,10 @@ bb3:
314313
315314sil @no_init_struct : $@convention(thin) () -> (@out ResilientEmptyStruct)
316315
317- // CHECK-LABEL: sil @test_empty_struct_uninintialized : $@convention(thin) () -> () {
316+ // CHECK-LABEL: sil @test_empty_struct_uninitialized : $@convention(thin) () -> () {
318317// CHECK-NOT: switch_enum_addr
319- // CHECK-LABEL: } // end sil function 'test_empty_struct_uninintialized '
320- sil @test_empty_struct_uninintialized : $@convention(thin) () -> () {
318+ // CHECK-LABEL: } // end sil function 'test_empty_struct_uninitialized '
319+ sil @test_empty_struct_uninitialized : $@convention(thin) () -> () {
321320bb0:
322321 %0 = alloc_stack $Optional<ResilientEmptyStruct>
323322 %1 = init_enum_data_addr %0 : $*Optional<ResilientEmptyStruct>, #Optional.some!enumelt
@@ -337,3 +336,29 @@ bb3:
337336 %8 = tuple ()
338337 return %8 : $()
339338}
339+
340+ sil @no_init_c_union : $@convention(thin) () -> (@out EmptyCUnion)
341+
342+ // CHECK-LABEL: sil @test_empty_c_union : $@convention(thin) () -> () {
343+ // CHECK: inject_enum_addr
344+ // CHECK-LABEL: } // end sil function 'test_empty_c_union'
345+ sil @test_empty_c_union : $@convention(thin) () -> () {
346+ bb0:
347+ %0 = alloc_stack $Optional<EmptyCUnion>
348+ %1 = init_enum_data_addr %0 : $*Optional<EmptyCUnion>, #Optional.some!enumelt
349+ %f = function_ref @no_init_c_union : $@convention(thin) () -> (@out EmptyCUnion)
350+ apply %f(%1) : $@convention(thin) () -> (@out EmptyCUnion)
351+ inject_enum_addr %0 : $*Optional<EmptyCUnion>, #Optional.some!enumelt
352+ switch_enum_addr %0 : $*Optional<EmptyCUnion>, case #Optional.some!enumelt: bb1, case #Optional.none!enumelt: bb2
353+
354+ bb1:
355+ br bb3
356+
357+ bb2:
358+ br bb3
359+
360+ bb3:
361+ dealloc_stack %0 : $*Optional<EmptyCUnion>
362+ %8 = tuple ()
363+ return %8 : $()
364+ }
0 commit comments