@@ -841,12 +841,44 @@ bb0(%0 : $*C, %1 : $*C):
841841sil_global hidden [let] @globalC : $C
842842sil_global hidden @globalCVar : $C
843843
844+ // CHECK-LABEL: @testGlobalLet
845+ // CHECK: PAIR #1.
846+ // CHECK-NEXT: %3 = apply %2() : $@convention(thin) () -> ()
847+ // CHECK-NEXT: %0 = global_addr @globalC : $*C
848+ // CHECK-NEXT: r=1,w=0
849+ sil hidden @testGlobalLet : $@convention(thin) () -> () {
850+ bb0:
851+ %0 = global_addr @globalC : $*C
852+ %1 = load %0 : $*C
853+ %2 = function_ref @nouser_func : $@convention(thin) () -> ()
854+ %3 = apply %2() : $@convention(thin) () -> ()
855+ %4 = function_ref @read_C : $@convention(thin) (@in_guaranteed C) -> ()
856+ %5 = apply %4(%0) : $@convention(thin) (@in_guaranteed C) -> ()
857+ %8 = tuple ()
858+ return %8 : $()
859+ }
860+
844861// CHECK-LABEL: @testInitGlobalLet
845862// CHECK: PAIR #0.
846863// CHECK-NEXT: %2 = apply %1(%0) : $@convention(thin) () -> @out C
847864// CHECK-NEXT: %0 = global_addr @globalC : $*C
848865// CHECK-NEXT: r=1,w=1
849- sil hidden @testInitGlobalLet : $@convention(thin) () -> () {
866+ sil hidden [global_init_once_fn] @testInitGlobalLet : $@convention(thin) () -> () {
867+ bb0:
868+ %0 = global_addr @globalC : $*C
869+ %1 = function_ref @init_C : $@convention(thin) () -> @out C
870+ %2 = apply %1(%0) : $@convention(thin) () -> @out C
871+ %3 = load %0 : $*C
872+ %8 = tuple ()
873+ return %8 : $()
874+ }
875+
876+ // CHECK-LABEL: @main
877+ // CHECK: PAIR #0.
878+ // CHECK-NEXT: %2 = apply %1(%0) : $@convention(thin) () -> @out C
879+ // CHECK-NEXT: %0 = global_addr @globalC : $*C
880+ // CHECK-NEXT: r=1,w=1
881+ sil [global_init_once_fn] @main : $@convention(thin) () -> () {
850882bb0:
851883 %0 = global_addr @globalC : $*C
852884 %1 = function_ref @init_C : $@convention(thin) () -> @out C
@@ -885,6 +917,25 @@ bb0:
885917 return %1 : $Builtin.RawPointer
886918}
887919
920+ // CHECK-LABEL: @testGlobalViaAddressorLet
921+ // CHECK: PAIR #2.
922+ // CHECK-NEXT: %5 = apply %4() : $@convention(thin) () -> ()
923+ // CHECK-NEXT: %2 = pointer_to_address %1 : $Builtin.RawPointer to [strict] $*C
924+ // CHECK-NEXT: r=1,w=0
925+ sil @testGlobalViaAddressorLet : $@convention(thin) () -> () {
926+ bb0:
927+ %0 = function_ref @addressor_of_globalC : $@convention(thin) () -> Builtin.RawPointer
928+ %1 = apply %0() : $@convention(thin) () -> Builtin.RawPointer
929+ %2 = pointer_to_address %1 : $Builtin.RawPointer to [strict] $*C
930+ %3 = load %2 : $*C
931+ %4 = function_ref @nouser_func : $@convention(thin) () -> ()
932+ %5 = apply %4() : $@convention(thin) () -> ()
933+ %6 = function_ref @read_C : $@convention(thin) (@in_guaranteed C) -> ()
934+ %7 = apply %6(%2) : $@convention(thin) (@in_guaranteed C) -> ()
935+ %8 = tuple ()
936+ return %8 : $()
937+ }
938+
888939// CHECK-LABEL: @testGlobalViaAddressorVar
889940// CHECK: PAIR #2.
890941// CHECK-NEXT: %5 = apply %4() : $@convention(thin) () -> ()
0 commit comments