Skip to content

Commit c9e0df7

Browse files
committed
Add an opaque field for necessary bindings struct
Without this, offsets of captures in closure contexts may be incorrect if there is a non-empty necessary bindings structure at the front. rdar://problem/26312900
1 parent 2118585 commit c9e0df7

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

include/swift/Reflection/ReflectionContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ class ReflectionContext
331331
// Initialize the builder.
332332
Builder.addField(OffsetToFirstCapture.second, sizeof(StoredPointer));
333333

334+
// Skip the closure's necessary bindings struct, if it's present.
335+
auto SizeOfNecessaryBindings = Info.NumBindings * sizeof(StoredPointer);
336+
Builder.addField(SizeOfNecessaryBindings, sizeof(StoredPointer));
337+
334338
// FIXME: should be unordered_set but I'm too lazy to write a hash
335339
// functor
336340
std::set<std::pair<const TypeRef *, const MetadataSource *>> Done;

validation-test/Reflection/functions.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,21 @@ func generic<T : P, U, V : C>(x: T, y: U, z: V, i: Int) {
7676
// CHECK-NEXT: (builtin Builtin.NativeObject)
7777

7878
// CHECK-32: Type info:
79-
// CHECK-32-NEXT: (closure_context size=24 alignment=4 stride=24 num_extra_inhabitants=0
80-
// CHECK-32-NEXT: (field offset=12
79+
// CHECK-32-NEXT: (closure_context size=40 alignment=4 stride=40 num_extra_inhabitants=0
80+
// CHECK-32-NEXT: (field offset=28
8181
// CHECK-32-NEXT: (reference kind=strong refcounting=native))
82-
// CHECK-32-NEXT: (field offset=16
82+
// CHECK-32-NEXT: (field offset=32
8383
// CHECK-32-NEXT: (reference kind=strong refcounting=native))
84-
// CHECK-32-NEXT: (field offset=20
84+
// CHECK-32-NEXT: (field offset=36
8585
// CHECK-32-NEXT: (reference kind=strong refcounting=native)))
8686

8787
// CHECK-64: Type info:
88-
// CHECK-64-NEXT: (closure_context size=40 alignment=8 stride=40 num_extra_inhabitants=0
89-
// CHECK-64-NEXT: (field offset=16
88+
// CHECK-64-NEXT: (closure_context size=72 alignment=8 stride=72 num_extra_inhabitants=0
89+
// CHECK-64-NEXT: (field offset=48
9090
// CHECK-64-NEXT: (reference kind=strong refcounting=native))
91-
// CHECK-64-NEXT: (field offset=24
91+
// CHECK-64-NEXT: (field offset=56
9292
// CHECK-64-NEXT: (reference kind=strong refcounting=native))
93-
// CHECK-64-NEXT: (field offset=32
93+
// CHECK-64-NEXT: (field offset=64
9494
// CHECK-64-NEXT: (reference kind=strong refcounting=native)))
9595
}
9696

0 commit comments

Comments
 (0)