Files
swift-mirror/test/stdlib/unmanaged_rc.swift
Erik Eckstein 7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00

41 lines
1.9 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -Xllvm -sil-print-types -emit-sil | %FileCheck %s
// RUN: %target-swift-frontend %s -Xllvm -sil-print-types -emit-sil -O | %FileCheck -check-prefix=OPT %s
// REQUIRES: optimized_stdlib
// REQUIRES: swift_in_compiler
// Make sure that when we invoke Unmanaged._withUnsafeGuaranteedRef, we do not
// have any ref count overhead.
public class Klass {}
public class KlassContainer {
let k = Klass()
}
@inline(never)
public func myPrint(_ k: Klass) { print(k) }
// Check the codegen of _withUnsafeGuaranteedRef
//
// CHECK-LABEL: sil public_external [transparent] @$ss9UnmanagedV24_withUnsafeGuaranteedRefyqd__qd__xKXEKlF :
// CHECK: bb0([[RESULT:%.*]] : $*Result, [[FUNC:%.*]] : $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1 where τ_0_0 : AnyObject> (@guaranteed τ_0_0) -> (@out τ_0_1, @error any Error) for <Instance, Result>, [[UNMANAGED:%.*]] : $Unmanaged<Instance>):
// CHECK: [[UNMANAGED_REF:%.*]] = struct_extract [[UNMANAGED]]
// CHECK: [[REF:%.*]] = unmanaged_to_ref [[UNMANAGED_REF]]
// CHECK: try_apply {{%.*}}([[RESULT]], [[REF]]) :
// CHECK-NOT: destroy_value
// CHECK: } // end sil function '$ss9UnmanagedV24_withUnsafeGuaranteedRefyqd__qd__xKXEKlF'
// OPT-LABEL: sil @$s12unmanaged_rc12useUnmanagedyys0D0VyAA14KlassContainerCGF : $@convention(thin) (Unmanaged<KlassContainer>) -> () {
// OPT: bb0([[UNMANAGED:%.*]] :
// OPT: [[UNMANAGED_REF:%.*]] = struct_extract [[UNMANAGED]]
// OPT: [[REF:%.*]] = unmanaged_to_ref [[UNMANAGED_REF]]
// OPT: [[REF_ELT_ADDR:%.*]] = ref_element_addr [immutable] [[REF]] : $KlassContainer, #KlassContainer.k
// OPT: [[VALUE:%.*]] = load [[REF_ELT_ADDR]]
// OPT: apply {{%.*}}([[VALUE]])
// OPT: } // end sil function '$s12unmanaged_rc12useUnmanagedyys0D0VyAA14KlassContainerCGF'
public func useUnmanaged(_ u: Unmanaged<KlassContainer>) {
u._withUnsafeGuaranteedRef {
myPrint($0.k)
}
}