Skip to content

Commit 1c4c8e8

Browse files
authored
Merge pull request #68816 from kubamracek/embedded-once
[embedded] Use -1 as the swift_once predicate indicator, to match Darwin expectations in the compiler
2 parents b9c719b + 88a5fb9 commit 1c4c8e8

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public func swift_once(predicate: UnsafeMutablePointer<Int>, fn: (@convention(c)
137137
if predicate.pointee == 0 {
138138
predicate.pointee = 1
139139
fn(context)
140+
predicate.pointee = -1
140141
}
141142
}
142143

test/embedded/once.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-run-simple-swift(%S/Inputs/print.swift -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
2+
// RUN: %target-run-simple-swift(-O %S/Inputs/print.swift -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
3+
// RUN: %target-run-simple-swift(-O -lto=llvm-full %lto_flags %S/Inputs/print.swift -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
4+
5+
// REQUIRES: executable_test
6+
// REQUIRES: optimized_stdlib
7+
// REQUIRES: VENDOR=apple
8+
// REQUIRES: OS=macosx
9+
10+
// For LTO, the linker dlopen()'s the libLTO library, which is a scenario that
11+
// ASan cannot work in ("Interceptors are not working, AddressSanitizer is
12+
// loaded too late").
13+
// REQUIRES: no_asan
14+
15+
public struct MyStruct {
16+
static var singleton = MyStruct()
17+
18+
init() {
19+
print("MyStruct.init")
20+
}
21+
22+
func foo() {
23+
print("MyStruct.foo")
24+
}
25+
}
26+
27+
@main
28+
struct Main {
29+
static func main() {
30+
MyStruct.singleton.foo()
31+
// CHECK: MyStruct.init
32+
// CHECK: MyStruct.foo
33+
}
34+
}

0 commit comments

Comments
 (0)