diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index fe1cc4ea13e..678cf23997a 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -975,10 +975,12 @@ SILFunction *SILGenModule::emitLazyGlobalInitializer(StringRef funcName, PatternBindingDecl *binding, unsigned pbdEntry) { ASTContext &C = M.getASTContext(); - Type initType = FunctionType::get( - TupleType::getEmpty(C), TupleType::getEmpty(C), - FunctionType::ExtInfo() - .withRepresentation(FunctionType::Representation::Thin)); + auto *onceBuiltin = + cast(getBuiltinValueDecl(C, C.getIdentifier("once"))); + auto blockParam = onceBuiltin->getParameterLists()[0]->get(1); + auto *type = blockParam->getType()->castTo(); + Type initType = FunctionType::get(TupleType::getEmpty(C), + TupleType::getEmpty(C), type->getExtInfo()); auto initSILType = getLoweredType(initType).castTo(); auto *f = diff --git a/lib/SILOptimizer/IPO/GlobalOpt.cpp b/lib/SILOptimizer/IPO/GlobalOpt.cpp index bccb8c05aaa..79124f2f56a 100644 --- a/lib/SILOptimizer/IPO/GlobalOpt.cpp +++ b/lib/SILOptimizer/IPO/GlobalOpt.cpp @@ -321,8 +321,8 @@ static SILFunction *getCalleeOfOnceCall(BuiltinInst *BI) { auto Callee = BI->getOperand(1); assert(Callee->getType().castTo()->getRepresentation() - == SILFunctionTypeRepresentation::Thin && - "Expected thin function representation!"); + == SILFunctionTypeRepresentation::CFunctionPointer && + "Expected C function representation!"); if (auto *FR = dyn_cast(Callee)) return FR->getReferencedFunction(); diff --git a/test/IRGen/globals.swift b/test/IRGen/globals.swift index 9a5e68cedec..866961e58ba 100644 --- a/test/IRGen/globals.swift +++ b/test/IRGen/globals.swift @@ -54,5 +54,5 @@ extension A { // CHECK: store i64 {{.*}}, i64* getelementptr inbounds ([[INT]], [[INT]]* @_T07globals2g0Sivp, i32 0, i32 0), align 8 // FIXME: give these initializers a real mangled name -// CHECK: define internal swiftcc void @globalinit_{{.*}}func0() {{.*}} { +// CHECK: define internal void @globalinit_{{.*}}func0() {{.*}} { // CHECK: store i64 5, i64* getelementptr inbounds (%TSi, %TSi* @_T07globals1AV3fooSivpZ, i32 0, i32 0), align 8 diff --git a/test/IRGen/lazy_globals.swift b/test/IRGen/lazy_globals.swift index 3354abc2437..28f8bef44ef 100644 --- a/test/IRGen/lazy_globals.swift +++ b/test/IRGen/lazy_globals.swift @@ -7,7 +7,7 @@ // CHECK: @_T012lazy_globals1ySivp = hidden global %TSi zeroinitializer, align 8 // CHECK: @_T012lazy_globals1zSivp = hidden global %TSi zeroinitializer, align 8 -// CHECK: define internal swiftcc void @globalinit_[[T]]_func0() {{.*}} { +// CHECK: define internal void @globalinit_[[T]]_func0() {{.*}} { // CHECK: entry: // CHECK: store i64 1, i64* getelementptr inbounds (%TSi, %TSi* @_T012lazy_globals1xSivp, i32 0, i32 0), align 8 // CHECK: store i64 2, i64* getelementptr inbounds (%TSi, %TSi* @_T012lazy_globals1ySivp, i32 0, i32 0), align 8 diff --git a/test/SILGen/lazy_globals.swift b/test/SILGen/lazy_globals.swift index 4b184fbd848..8a7c0d47755 100644 --- a/test/SILGen/lazy_globals.swift +++ b/test/SILGen/lazy_globals.swift @@ -1,6 +1,6 @@ // RUN: %target-swift-frontend -parse-as-library -emit-silgen -enable-sil-ownership %s | %FileCheck %s -// CHECK: sil private @globalinit_[[T:.*]]_func0 : $@convention(thin) () -> () { +// CHECK: sil private @globalinit_[[T:.*]]_func0 : $@convention(c) () -> () { // CHECK: alloc_global @_T012lazy_globals1xSiv // CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals1xSivp : $*Int // CHECK: store {{%.*}} to [trivial] [[XADDR]] : $*Int @@ -8,15 +8,15 @@ // CHECK: sil hidden [global_init] @_T012lazy_globals1xSivau : $@convention(thin) () -> Builtin.RawPointer { // CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token0 : $*Builtin.Word // CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer -// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func0 : $@convention(thin) () -> () -// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(thin) () -> ()) : $() +// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func0 : $@convention(c) () -> () +// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(c) () -> ()) : $() // CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals1xSivp : $*Int // CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer // CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer // CHECK: } var x: Int = 0 -// CHECK: sil private @globalinit_[[T:.*]]_func1 : $@convention(thin) () -> () { +// CHECK: sil private @globalinit_[[T:.*]]_func1 : $@convention(c) () -> () { // CHECK: alloc_global @_T012lazy_globals3FooV3fooSivpZ // CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals3FooV3fooSivpZ : $*Int // CHECK: store {{.*}} to [trivial] [[XADDR]] : $*Int @@ -26,8 +26,8 @@ struct Foo { // CHECK: sil hidden [global_init] @_T012lazy_globals3FooV3fooSivau : $@convention(thin) () -> Builtin.RawPointer { // CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token1 : $*Builtin.Word // CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer -// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func1 : $@convention(thin) () -> () -// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(thin) () -> ()) : $() +// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func1 : $@convention(c) () -> () +// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(c) () -> ()) : $() // CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals3FooV3fooSivpZ : $*Int // CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer // CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer @@ -40,7 +40,7 @@ struct Foo { static var initialized: Int = 57 } -// CHECK: sil private @globalinit_[[T:.*]]_func3 : $@convention(thin) () -> () { +// CHECK: sil private @globalinit_[[T:.*]]_func3 : $@convention(c) () -> () { // CHECK: alloc_global @_T012lazy_globals3BarO3barSivpZ // CHECK: [[XADDR:%.*]] = global_addr @_T012lazy_globals3BarO3barSivpZ : $*Int // CHECK: store {{.*}} to [trivial] [[XADDR]] : $*Int @@ -50,8 +50,8 @@ enum Bar { // CHECK: sil hidden [global_init] @_T012lazy_globals3BarO3barSivau : $@convention(thin) () -> Builtin.RawPointer { // CHECK: [[TOKEN_ADDR:%.*]] = global_addr @globalinit_[[T]]_token3 : $*Builtin.Word // CHECK: [[TOKEN_PTR:%.*]] = address_to_pointer [[TOKEN_ADDR]] : $*Builtin.Word to $Builtin.RawPointer -// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func3 : $@convention(thin) () -> () -// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(thin) () -> ()) : $() +// CHECK: [[INIT_FUNC:%.*]] = function_ref @globalinit_[[T]]_func3 : $@convention(c) () -> () +// CHECK: builtin "once"([[TOKEN_PTR]] : $Builtin.RawPointer, [[INIT_FUNC]] : $@convention(c) () -> ()) : $() // CHECK: [[GLOBAL_ADDR:%.*]] = global_addr @_T012lazy_globals3BarO3barSivpZ : $*Int // CHECK: [[GLOBAL_PTR:%.*]] = address_to_pointer [[GLOBAL_ADDR]] : $*Int to $Builtin.RawPointer // CHECK: return [[GLOBAL_PTR]] : $Builtin.RawPointer @@ -63,13 +63,13 @@ enum Bar { func f() -> (Int, Int) { return (1, 2) } -// CHECK: sil private @globalinit_[[T]]_func4 : $@convention(thin) () -> () { +// CHECK: sil private @globalinit_[[T]]_func4 : $@convention(c) () -> () { // CHECK: function_ref @_T012lazy_globals1fSi_SityF : $@convention(thin) () -> (Int, Int) // CHECK: sil hidden [global_init] @_T012lazy_globals2a1Sivau : $@convention(thin) () -> Builtin.RawPointer -// CHECK: function_ref @globalinit_[[T]]_func4 : $@convention(thin) () -> () +// CHECK: function_ref @globalinit_[[T]]_func4 : $@convention(c) () -> () // CHECK: global_addr @_T012lazy_globals2a1Sivp : $*Int // CHECK: sil hidden [global_init] @_T012lazy_globals2b1Sivau : $@convention(thin) () -> Builtin.RawPointer { -// CHECK: function_ref @globalinit_[[T]]_func4 : $@convention(thin) () -> () +// CHECK: function_ref @globalinit_[[T]]_func4 : $@convention(c) () -> () // CHECK: global_addr @_T012lazy_globals2b1Sivp : $*Int var (a1, b1) = f() diff --git a/test/SILGen/properties.swift b/test/SILGen/properties.swift index a6919a7b698..c9722dee915 100644 --- a/test/SILGen/properties.swift +++ b/test/SILGen/properties.swift @@ -627,7 +627,7 @@ func force_global_observing_property_setter() { } // The property is initialized with "zero". -// CHECK-LABEL: sil private @globalinit_{{.*}}_func1 : $@convention(thin) () -> () { +// CHECK-LABEL: sil private @globalinit_{{.*}}_func1 : $@convention(c) () -> () { // CHECK: bb0: // CHECK-NEXT: alloc_global @_T010properties25global_observing_propertySiv // CHECK-NEXT: %1 = global_addr @_T010properties25global_observing_propertySivp : $*Int diff --git a/test/SILOptimizer/globalopt.sil b/test/SILOptimizer/globalopt.sil index 3a1a6437440..a6c22a386f9 100644 --- a/test/SILOptimizer/globalopt.sil +++ b/test/SILOptimizer/globalopt.sil @@ -213,7 +213,7 @@ sil_global private @globalinit_token0 : $Builtin.Word sil_global @MyConst : $Int32 // globalinit_func0 -sil private @globalinit_func0 : $@convention(thin) () -> () { +sil private @globalinit_func0 : $@convention(c) () -> () { bb0: %0 = global_addr @MyConst : $*Int32 // user: %3 %1 = integer_literal $Builtin.Int32, 0 // user: %2 @@ -229,8 +229,8 @@ bb0: %1 = global_addr @globalinit_token0 : $*Builtin.Word // user: %2 %2 = address_to_pointer %1 : $*Builtin.Word to $Builtin.RawPointer // user: %5 // function_ref globalinit_func0 - %3 = function_ref @globalinit_func0 : $@convention(thin) () -> () // user: %4 - %5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(thin) () -> ()) : $() + %3 = function_ref @globalinit_func0 : $@convention(c) () -> () // user: %4 + %5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(c) () -> ()) : $() %6 = global_addr @MyConst : $*Int32 // user: %7 %7 = address_to_pointer %6 : $*Int32 to $Builtin.RawPointer // user: %8 return %7 : $Builtin.RawPointer // id: %8 diff --git a/test/SILOptimizer/static_initializer.sil b/test/SILOptimizer/static_initializer.sil index d808471d54e..40d26ac1dd7 100644 --- a/test/SILOptimizer/static_initializer.sil +++ b/test/SILOptimizer/static_initializer.sil @@ -25,8 +25,8 @@ sil_global private @globalinit_token0 : $Builtin.Word // CHECK-NEXT: } sil_global @_Tv2ch1xSi : $Outer -// CHECK-LABEL: sil private @globalinit_func0 : $@convention(thin) () -> () { -sil private @globalinit_func0 : $@convention(thin) () -> () { +// CHECK-LABEL: sil private @globalinit_func0 : $@convention(c) () -> () { +sil private @globalinit_func0 : $@convention(c) () -> () { bb0: %0 = global_addr @_Tv2ch1xSi : $*Outer %1 = integer_literal $Builtin.Int32, 2 @@ -42,7 +42,7 @@ bb0: // CHECK-NEXT: bb0: // CHECK-NOT: global_addr @globalinit_token0 // CHECK-NEXT: address_to_pointer -// CHECK: function_ref @globalinit_func0 : $@convention(thin) () -> () +// CHECK: function_ref @globalinit_func0 : $@convention(c) () -> () // CHECK-NEXT: global_addr @_Tv2ch1xSi : $*Outer // CHECK-NEXT: address_to_pointer // CHECK-NEXT: return @@ -50,8 +50,8 @@ sil [global_init] @_TF2cha1xSi : $@convention(thin) () -> Builtin.RawPointer { bb0: %1 = global_addr @globalinit_token0 : $*Builtin.Word %2 = address_to_pointer %1 : $*Builtin.Word to $Builtin.RawPointer - %3 = function_ref @globalinit_func0 : $@convention(thin) () -> () - %5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(thin) () -> ()) : $() + %3 = function_ref @globalinit_func0 : $@convention(c) () -> () + %5 = builtin "once"(%2 : $Builtin.RawPointer, %3 : $@convention(c) () -> ()) : $() %6 = global_addr @_Tv2ch1xSi : $*Outer %7 = address_to_pointer %6 : $*Outer to $Builtin.RawPointer return %7 : $Builtin.RawPointer