Files
swift-mirror/test/SILGen/assignment.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

62 lines
2.1 KiB
Swift

// RUN: %target-swift-emit-silgen -Xllvm -sil-print-types -enforce-exclusivity=checked %s | %FileCheck %s
class C {}
struct A {}
struct B { var owner: C }
var a = A()
// CHECK-LABEL: sil [ossa] @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 {
// CHECK: assign {{%.*}} to {{%.*}} : $*A
// CHECK: destroy_value {{%.*}} : $B
// CHECK: } // end sil function 'main'
(a, _) = (A(), B(owner: C()))
class D { var child: C = C() }
// Verify that the LHS is formally evaluated before the RHS.
// CHECK-LABEL: sil hidden [ossa] @$s10assignment5test1yyF : $@convention(thin) () -> () {
func test1() {
// CHECK: [[T0:%.*]] = metatype $@thick D.Type
// CHECK: [[CTOR:%.*]] = function_ref @$s10assignment1DC{{[_0-9a-zA-Z]*}}fC
// CHECK: [[D:%.*]] = apply [[CTOR]]([[T0]])
// CHECK: [[T0:%.*]] = metatype $@thick C.Type
// CHECK: [[CTOR:%.*]] = function_ref @$s10assignment1CC{{[_0-9a-zA-Z]*}}fC
// CHECK: [[C:%.*]] = apply [[CTOR]]([[T0]]) : $@convention(method) (@thick C.Type) -> @owned C
// CHECK: [[SETTER:%.*]] = class_method [[D]] : $D, #D.child!setter
// CHECK: apply [[SETTER]]([[C]], [[D]])
// CHECK: destroy_value [[D]]
D().child = C()
}
// rdar://32039566
protocol P {
var left: Int {get set}
var right: Int {get set}
}
// Verify that the access to the LHS does not begin until after the
// RHS is formally evaluated.
// CHECK-LABEL: sil hidden [ossa] @$s10assignment15copyRightToLeft1pyAA1P_pz_tF : $@convention(thin) (@inout any P) -> () {
func copyRightToLeft(p: inout P) {
// CHECK: bb0(%0 : $*any P):
// CHECK: [[READ:%.*]] = begin_access [read] [unknown] %0 : $*any P
// CHECK: [[READ_OPEN:%.*]] = open_existential_addr immutable_access [[READ]]
// CHECK: end_access [[READ]] : $*any P
// CHECK: [[WRITE:%.*]] = begin_access [modify] [unknown] %0 : $*any P
// CHECK: [[WRITE_OPEN:%.*]] = open_existential_addr mutable_access [[WRITE]]
// CHECK: end_access [[WRITE]] : $*any P
p.left = p.right
}
// https://github.com/apple/swift/issues/48478
func stupidGames() -> ((), ()) {
return ((), ())
}
func assignToNestedVoid() {
let _: ((), ()) = stupidGames()
}