Skip to content

Commit c1ac1cd

Browse files
authored
Merge pull request #12578 from zflamig/fix/func
SILGen: Fixes #function when called by lazy initializer
2 parents bba9d4c + 318f90c commit c1ac1cd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/SILGen/SILGenGlobalVariable.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ void SILGenModule::emitGlobalInitialization(PatternBindingDecl *pd,
242242

243243
void SILGenFunction::emitLazyGlobalInitializer(PatternBindingDecl *binding,
244244
unsigned pbdEntry) {
245+
MagicFunctionName = SILGenModule::getMagicFunctionName(binding->getDeclContext());
246+
245247
{
246248
Scope scope(Cleanups, binding);
247249

test/SILGen/default_arguments.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Foo {
116116

117117
// CHECK-LABEL: sil hidden @_T017default_arguments3FooCACSi3int_SS6stringtcfc : $@convention(method) (Int, @owned String, @owned Foo) -> @owned Foo
118118
// CHECK: string_literal utf16 "init(int:string:)"
119-
init(int: Int, string: String) {
119+
init(int: Int, string: String = #function) {
120120
testMagicLiterals()
121121
closure { testMagicLiterals() }
122122
autoclosure(testMagicLiterals())
@@ -138,13 +138,21 @@ class Foo {
138138
autoclosure(testMagicLiterals())
139139
return x
140140
}
141+
142+
// CHECK-LABEL: sil private @globalinit_33_E52D764B1F2009F2390B2B8DF62DAEB8_func0
143+
// CHECK: string_literal utf16 "Foo"
144+
static let x = Foo(int:0)
145+
141146
}
142147

143148
// Test at top level.
144149
testMagicLiterals()
145150
closure { testMagicLiterals() }
146151
autoclosure(testMagicLiterals())
147152

153+
// CHECK: string_literal utf16 "default_arguments"
154+
let y : String = #function
155+
148156
// CHECK-LABEL: sil hidden @_T017default_arguments16testSelectorCallySi_Si17withMagicLiteralstF
149157
// CHECK: string_literal utf16 "testSelectorCall(_:withMagicLiterals:)"
150158
func testSelectorCall(_ x: Int, withMagicLiterals y: Int) {

0 commit comments

Comments
 (0)