Files
swift-mirror/test/SILOptimizer/moveonly_lifetime.swift
Daniel Rodríguez Troitiño ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00

57 lines
1.8 KiB
Swift

// RUN: %target-swift-emit-sil -sil-verify-all -module-name moveonly_lifetime -o /dev/null -Xllvm -sil-print-canonical-module -Onone -verify -enable-experimental-feature MoveOnlyClasses %s | %FileCheck %s
// REQUIRES: swift_feature_MoveOnlyClasses
struct C : ~Copyable {
deinit {}
}
@_silgen_name("getC")
func getC() -> C
@_silgen_name("takeC")
func takeC(_ c: __owned C)
@_silgen_name("borrowC")
func borrowC(_ c: borrowing C)
@_silgen_name("something")
func something()
// Verify that a move-only value's lifetime extends to the end of the
// non-consuming scope where it appears but not further (which would require a
// copy).
//
// NOTE: We do not properly maximize lifetimes yet in the address checker. So
// the lifetimes are shortened in the sides of the diamonds inappropriately.
//
// CHECK-LABEL: sil hidden [ossa] @test_diamond__consume_r__use_l : $@convention(thin) (Bool) -> () {
// CHECK: [[STACK:%.*]] = alloc_stack
// CHECK: cond_br {{%[^,]+}}, [[LEFT:bb[0-9]+]], [[RIGHT:bb[0-9]+]]
//
// CHECK: [[RIGHT]]:
// CHECK: [[INSTANCE:%.*]] = load [take] [[STACK]]
// CHECK: [[TAKE_C:%[^,]+]] = function_ref @takeC
// CHECK: apply [[TAKE_C]]([[INSTANCE]])
// CHECK: br [[BOTTOM:bb[0-9]+]]
//
// CHECK: [[LEFT]]:
// CHECK: [[INSTANCE:%.*]] = load_borrow [[STACK]]
// CHECK: [[BORROW_C:%[^,]+]] = function_ref @borrowC
// CHECK: apply [[BORROW_C]]([[INSTANCE]])
// CHECK: [[SOMETHING:%[^,]+]] = function_ref @something
// CHECK: apply [[SOMETHING]]
// CHECK: destroy_addr [[STACK]]
// CHECK: br [[BOTTOM]]
// CHECK-LABEL: } // end sil function 'test_diamond__consume_r__use_l'
@_silgen_name("test_diamond__consume_r__use_l")
func test_diamond(_ condition: Bool) {
let c = getC()
if condition {
borrowC(c)
something()
} else {
takeC(c)
}
}