Skip to content

Commit 0ef287a

Browse files
Merge pull request #74735 from nate-chandler/bug/20240626/1
6.0: [IRGen] Fix RecordTypeInfoImpl::initWithTake.
2 parents 9624428 + 09449de commit 0ef287a

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

lib/IRGen/GenRecord.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,10 @@ class RecordTypeInfoImpl : public Base,
268268
dest.getAddress(), llvm::MaybeAlign(dest.getAlignment().getValue()),
269269
src.getAddress(), llvm::MaybeAlign(src.getAlignment().getValue()),
270270
asImpl().Impl::getSize(IGF, T));
271-
return;
272-
}
273-
274-
// If the fields are not ABI-accessible, use the value witness table.
275-
if (!AreFieldsABIAccessible) {
271+
} else if (!AreFieldsABIAccessible) {
272+
// If the fields are not ABI-accessible, use the value witness table.
276273
return emitInitializeWithTakeCall(IGF, T, dest, src);
277-
}
278-
279-
if (auto rawLayout = T.getRawLayout()) {
274+
} else if (auto rawLayout = T.getRawLayout()) {
280275
// Because we have a rawlayout attribute, we know this has to be a struct.
281276
auto structDecl = T.getStructOrBoundGenericStruct();
282277

@@ -292,9 +287,7 @@ class RecordTypeInfoImpl : public Base,
292287
isOutlined);
293288
}
294289
}
295-
}
296-
297-
if (isOutlined || T.hasParameterizedExistential()) {
290+
} else if (isOutlined || T.hasParameterizedExistential()) {
298291
auto offsets = asImpl().getNonFixedOffsets(IGF, T);
299292
for (auto &field : getFields()) {
300293
if (field.isEmpty())
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// RUN: %target-swift-emit-irgen -O \
2+
// RUN: -parse-sil \
3+
// RUN: -disable-type-layout \
4+
// RUN: %s \
5+
// RUN: -enable-experimental-feature RawLayout \
6+
// RUN: | \
7+
// RUN: %IRGenFileCheck %s
8+
9+
import Builtin
10+
import Swift
11+
12+
@usableFromInline
13+
@frozen @_rawLayout(like: Value, movesAsLike) internal struct _Cell<Value> : ~Copyable where Value : ~Copyable {
14+
@_alwaysEmitIntoClient @inlinable deinit
15+
}
16+
17+
sil @$sSp12deinitialize5countSvSi_tF : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (Int, UnsafeMutablePointer<τ_0_0>) -> UnsafeMutableRawPointer
18+
19+
// CHECK-LABEL: define{{.*}} @"$s15Synchronization5_CellVAARi_zrlEfD"(
20+
// CHECK-SAME: ptr %"_Cell<Value>",
21+
// CHECK-SAME: ptr noalias swiftself [[SOURCE:%[0-9]+]]
22+
// CHECK-SAME: )
23+
// CHECK-SAME: {
24+
// CHECK: entry:
25+
// CHECK: [[CELL_VWT_ADDR:%[^,]+]] = getelementptr inbounds ptr, ptr %"_Cell<Value>", i64 -1
26+
// CHECK: %"_Cell<Value>.valueWitnesses" = load ptr, ptr [[CELL_VWT_ADDR]]
27+
// CHECK: [[CELL_SIZE_ADDR:%[^,]+]] = getelementptr inbounds %swift.vwtable, ptr %"_Cell<Value>.valueWitnesses", i32 0, i32 8
28+
// CHECK: %size = load i64, ptr [[CELL_SIZE_ADDR]]
29+
// CHECK: [[DEST:%[^,]+]] = alloca i8, i64 %size
30+
// CHECK: call void @llvm.lifetime.start.p0(i64 -1, ptr [[DEST]])
31+
// CHECK: [[VALUE_METADATA_ADDR:%[^,]+]] = getelementptr inbounds ptr, ptr %"_Cell<Value>", i64 2
32+
// CHECK: %Value = load ptr, ptr [[VALUE_METADATA_ADDR]]
33+
// CHECK: [[VALUE_VWT_ADDR:%[^,]+]] = getelementptr inbounds ptr, ptr %Value, i64 -1
34+
// CHECK: %Value.valueWitnesses = load ptr, ptr [[VALUE_VWT_ADDR]]
35+
// CHECK: [[VALUE_INIT_WITH_TAKE_ADDR:%[^,]+]] = getelementptr inbounds ptr, ptr %Value.valueWitnesses, i32 4
36+
// CHECK: %InitializeWithTake = load ptr, ptr [[VALUE_INIT_WITH_TAKE_ADDR]]
37+
// CHECK: call ptr %InitializeWithTake(ptr noalias [[DEST]], ptr noalias [[SOURCE]], ptr %Value)
38+
// CHECK: call swiftcc ptr @"$sSp12deinitialize5countSvSi_tF"(i64 1, ptr [[DEST]], ptr %Value)
39+
// CHECK: call void @llvm.lifetime.end.p0(i64 -1, ptr [[DEST]])
40+
// CHECK: }
41+
sil @$s15Synchronization5_CellVAARi_zrlEfD : $@convention(method) <Value where Value : ~Copyable> (@in _Cell<Value>) -> () {
42+
bb0(%0 : $*_Cell<Value>):
43+
%1 = alloc_stack $_Cell<Value>
44+
copy_addr [take] %0 to [init] %1 : $*_Cell<Value>
45+
%7 = builtin "addressOfRawLayout"<_Cell<Value>>(%1 : $*_Cell<Value>) : $Builtin.RawPointer
46+
%8 = struct $UnsafeMutablePointer<Value> (%7 : $Builtin.RawPointer)
47+
%9 = integer_literal $Builtin.Int64, 1
48+
%10 = struct $Int (%9 : $Builtin.Int64)
49+
%11 = function_ref @$sSp12deinitialize5countSvSi_tF : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (Int, UnsafeMutablePointer<τ_0_0>) -> UnsafeMutableRawPointer
50+
%12 = apply %11<Value>(%10, %8) : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (Int, UnsafeMutablePointer<τ_0_0>) -> UnsafeMutableRawPointer
51+
%13 = tuple ()
52+
dealloc_stack %1 : $*_Cell<Value>
53+
return %13 : $()
54+
}

0 commit comments

Comments
 (0)