mirror of
https://github.com/apple/swift.git
synced 2026-02-27 18:26:24 +01:00
These two new invariants eliminate corner cases which caused bugs if optimization didn't handle them. Also, it will significantly simplify lifetime completion. The implementation basically consists of these changes: * add a flag in SILFunction which tells optimization if they need to take care of infinite loops * add a utility to break infinite loops * let all optimizations remove unreachable blocks and break infinite loops if necessary * add verification to check the new SIL invariants The new `breakIfniniteLoops` utility breaks infinite loops in the control flow by inserting an "artificial" loop exit to a new dead-end block with an `unreachable`. It inserts a `cond_br` with a `builtin "infinite_loop_true_condition"`: ``` bb0: br bb1 bb1: br bb1 // back-end branch ``` -> ``` bb0: br bb1 bb1: %1 = builtin "infinite_loop_true_condition"() // always true, but the compiler doesn't know cond_br %1, bb2, bb3 bb2: // new back-end block br bb1 bb3: // new dead-end block unreachable ```
20 lines
444 B
Swift
20 lines
444 B
Swift
// RUN: %target-swift-frontend -primary-file %s -emit-ir -o - | %FileCheck %s
|
|
|
|
func f() -> Bool? { return nil }
|
|
|
|
var gb = false
|
|
var gc: () -> () = {}
|
|
|
|
({
|
|
guard var b = f() else { return }
|
|
let c = { b = true }
|
|
gb = b
|
|
gc = c
|
|
})()
|
|
|
|
// CHECK-LABEL: @"$s9alloc_boxyyXEfU0_"
|
|
// CHECK-NOT: call void @swift_setDeallocating
|
|
// CHECK: call void @swift_deallocUninitializedObject
|
|
// CHECK-NOT: call void @swift_setDeallocating
|
|
// CHECK: ret void
|