Skip to content

Commit 15a687b

Browse files
committed
[IRGen] Fix RecordTypeInfoImpl::initWithTake.
Apply the same control-flow changes to the method that were applied on main to avoid duplicated implementations one of which crashes with ``` Metadata for archetype not bound in function. The metadata could be missing entirely because it needs to be passed to the function. Or the metadata is present and not bound in which case setScopedLocalTypeMetadata or similar must be called. Archetype without metadata: Value (primary_archetype_type address=0x14207ebe0 conforms_to="Swift.(file).Escapable" name="Value" (interface_type=generic_type_param_type depth=0 index=0 decl="Synchronization.(file)._Cell.Value@/Volumes/ams1_ext4/Submit/SWE/DevTools/swift/6_0_0_6/swift/stdlib/public/Synchronization/Cell.swift:19:23")) Function: ; Function Attrs: noinline nounwind define linkonce_odr hidden ptr @"$s15Synchronization5_CellVyxGRi_zlWOb"(ptr %0, ptr %1, ptr %2) swiftlang#14 !dbg !8 { %4 = alloca i1, align 1 } LocalTypeData: (0x14207f5f8 (_Cell<Value>), FormalTypeMetadata) => [ (universal) concrete: 0x600003d1add0 ptr %2 ] ``` when building Synchronization.
1 parent 54898ce commit 15a687b

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)