Files
swift-mirror/test/SILOptimizer/global_hoisting_crash.swift
Erik Eckstein 3ad7d548c2 LICM: hoist calls to global_init functions
Global initializers are executed only once.
Therefore it's possible to hoist such an initializer call to a loop pre-header - in case there are no conflicting side-effects in the loop before the call.
Also, the call must post-dominate the loop pre-header. Otherwise it would be executed speculatively.
2020-03-23 16:08:56 +01:00

25 lines
490 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift -O %s -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test
struct Teststruct {
static let s = Teststruct()
@inline(never)
init() {
let set = Set<String>()
for _ in set {
// Check that the global initializer is not hoisted out of this loop,
// resulting in a dispatch_once re-retrance crash.
_ = Teststruct.s
}
}
}
// CHECK: Teststruct
print(Teststruct.s)