Files
swift-mirror/test/SILGen/foreach.swift
Joe Groff d07f093521 SILGen: Manage a foreach loop's generator payload before taking loop variables from it.
Fixes a leak when parts of the payload are ignored, as in rdar://problem/19631811.

Swift SVN r24809
2015-01-29 00:17:55 +00:00

43 lines
1.9 KiB
Swift

// RUN: %target-swift-frontend -emit-silgen %s | FileCheck %s
class C {}
// CHECK-LABEL: sil hidden @_TF7foreach3fooFGSaTCS_1CS0___T_
func foo(xx: [(C, C)]) {
// CHECK: [[PAYLOAD_ADDR:%.*]] = unchecked_take_enum_data_addr {{%.*}} : $*Optional<(C, C)>
// CHECK: [[PAYLOAD:%.*]] = load [[PAYLOAD_ADDR]]
// CHECK: [[A:%.*]] = tuple_extract [[PAYLOAD]] : $(C, C), 0
// CHECK: [[B:%.*]] = tuple_extract [[PAYLOAD]] : $(C, C), 1
// CHECK: strong_release [[B]]
// CHECK: strong_release [[A]]
for (a, b) in xx {}
// CHECK: [[PAYLOAD_ADDR:%.*]] = unchecked_take_enum_data_addr {{%.*}} : $*Optional<(C, C)>
// CHECK: [[PAYLOAD:%.*]] = load [[PAYLOAD_ADDR]]
// CHECK: [[A:%.*]] = tuple_extract [[PAYLOAD]] : $(C, C), 0
// CHECK: [[B:%.*]] = tuple_extract [[PAYLOAD]] : $(C, C), 1
// CHECK: strong_release [[B]]
// CHECK: strong_release [[A]]
for (a, _) in xx {}
// CHECK: [[PAYLOAD_ADDR:%.*]] = unchecked_take_enum_data_addr {{%.*}} : $*Optional<(C, C)>
// CHECK: [[PAYLOAD:%.*]] = load [[PAYLOAD_ADDR]]
// CHECK: [[A:%.*]] = tuple_extract [[PAYLOAD]] : $(C, C), 0
// CHECK: [[B:%.*]] = tuple_extract [[PAYLOAD]] : $(C, C), 1
// CHECK: strong_release [[A]]
// CHECK: strong_release [[B]]
for (_, b) in xx {}
// CHECK: [[PAYLOAD_ADDR:%.*]] = unchecked_take_enum_data_addr {{%.*}} : $*Optional<(C, C)>
// CHECK: [[PAYLOAD:%.*]] = load [[PAYLOAD_ADDR]]
// CHECK: [[A:%.*]] = tuple_extract [[PAYLOAD]] : $(C, C), 0
// CHECK: [[B:%.*]] = tuple_extract [[PAYLOAD]] : $(C, C), 1
// CHECK: strong_release [[B]]
// CHECK: strong_release [[A]]
for (_, _) in xx {}
// CHECK: [[PAYLOAD_ADDR:%.*]] = unchecked_take_enum_data_addr {{%.*}} : $*Optional<(C, C)>
// CHECK: [[PAYLOAD:%.*]] = load [[PAYLOAD_ADDR]]
// CHECK: [[A:%.*]] = tuple_extract [[PAYLOAD]] : $(C, C), 0
// CHECK: [[B:%.*]] = tuple_extract [[PAYLOAD]] : $(C, C), 1
// CHECK: strong_release [[B]]
// CHECK: strong_release [[A]]
for _ in xx {}
}