Skip to content

Commit 19dccf7

Browse files
committed
MandatoryPerformanceOptimizations: don't crash with empty global-init-once functions
Instead ignore empty global-init-once functions #73487 rdar://130041582
1 parent 3ccbcfe commit 19dccf7

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ private extension Value {
355355
private extension Function {
356356
/// Analyzes the global initializer function and returns global it initializes (from `alloc_global` instruction).
357357
func getInitializedGlobal() -> GlobalVariable? {
358+
if !isDefinition {
359+
return nil
360+
}
358361
for inst in self.entryBlock.instructions {
359362
switch inst {
360363
case let agi as AllocGlobalInst:

test/SILOptimizer/mandatory_performance_optimizations.sil

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ bb0:
167167
return %6 : $()
168168
}
169169

170+
// Check that we don't crash on global init-once declarations.
171+
172+
// CHECK-LABEL: sil [global_init_once_fn] [no_locks] @external_global_init_once : $@convention(c) () -> ()
173+
sil [global_init_once_fn] [no_locks] @external_global_init_once : $@convention(c) () -> ()
174+
170175
sil @yield_int_value : $@convention(thin) @yield_once () -> (@yields Int32) {
171176
bb0:
172177
%0 = integer_literal $Builtin.Int32, 10

0 commit comments

Comments
 (0)