Skip to content

Commit d07513b

Browse files
authored
Merge pull request #22096 from aschwaighofer/no_capture_descriptor_stack_allocated
2 parents 92416e7 + 3982bde commit d07513b

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,10 +1456,6 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
14561456
/*typeToFill*/ nullptr,
14571457
std::move(bindings));
14581458

1459-
auto descriptor = IGF.IGM.getAddrOfCaptureDescriptor(SILFn, origType,
1460-
substType, subs,
1461-
layout);
1462-
14631459
llvm::Value *data;
14641460

14651461
Optional<StackAddress> stackAddr;
@@ -1479,8 +1475,13 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
14791475
stackAddr = stackAddr->withAddress(IGF.Builder.CreateBitCast(
14801476
stackAddr->getAddress(), IGF.IGM.OpaquePtrTy));
14811477
data = stackAddr->getAddress().getAddress();
1482-
} else
1483-
data = IGF.emitUnmanagedAlloc(layout, "closure", descriptor, &offsets);
1478+
} else {
1479+
auto descriptor = IGF.IGM.getAddrOfCaptureDescriptor(SILFn, origType,
1480+
substType, subs,
1481+
layout);
1482+
1483+
data = IGF.emitUnmanagedAlloc(layout, "closure", descriptor, &offsets);
1484+
}
14841485
Address dataAddr = layout.emitCastTo(IGF, data);
14851486

14861487
unsigned i = 0;

test/IRGen/closure.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s
2+
// RUN: %target-swift-frontend -primary-file %s -emit-ir | %FileCheck %s --check-prefix=CAPTURE
23

34
// REQUIRES: CPU=x86_64
45

@@ -55,3 +56,12 @@ func captures_tuple<T, U>(x x: (T, U)) -> () -> (T, U) {
5556
// CHECK: bitcast %swift.opaque* [[ADDR]] to <{}>*
5657
return {x}
5758
}
59+
60+
class C {}
61+
62+
func useClosure(_ cl : () -> ()) {}
63+
64+
// CAPTURE-NOT: reflection_descriptor{{.*}} = private constant { i32, i32, i32, i32, i32, i32, i32, i32 } { i32 5, i32 0, i32 0
65+
func no_capture_descriptor(_ c: C, _ d: C, _ e: C, _ f: C, _ g: C) {
66+
useClosure( { _ = c ; _ = d ; _ = e ; _ = f ; _ = g })
67+
}

test/IRGen/partial_apply_forwarder.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ bb0(%0 : $*τ_0_1, %2: $EmptyType):
149149
// CHECK: call noalias %swift.refcounted* @swift_allocObject(%swift.type* [[WBTY]]
150150
// CHECK: ret void
151151

152-
// CHECK-LABEL: define internal swiftcc void @"$s7takingQTA.2"(%T23partial_apply_forwarder7WeakBoxC*, %swift.refcounted* swiftself)
152+
// CHECK-LABEL: define internal swiftcc void @"$s7takingQTA.1"(%T23partial_apply_forwarder7WeakBoxC*, %swift.refcounted* swiftself)
153153
// CHECK: entry:
154154
// CHECK: [[TYADDR:%.*]] = getelementptr inbounds %T23partial_apply_forwarder7WeakBoxC, %T23partial_apply_forwarder7WeakBoxC* %0
155155
// CHECK: [[TY:%.*]] = load %swift.type*, %swift.type** [[TYADDR]]

test/IRGen/swift3-metadata-coff.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ public protocol P {
1515
associatedtype T
1616
}
1717

18+
enum E {
19+
case a
20+
case b
21+
}
22+
1823
public struct S : P {
1924
public typealias T = Optional<S>
25+
var e = E.a
2026
}
2127

2228
var gg = S()

0 commit comments

Comments
 (0)