Skip to content

Commit 6fde84e

Browse files
committed
Fix size and alignment for fixed
1 parent ab143ee commit 6fde84e

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

lib/IRGen/GenStruct.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,12 @@ namespace {
996996
// If we have a raw layout struct who is fixed size, it means the
997997
// layout of the struct is fully concrete.
998998
if (rawLayout) {
999+
// Defer to this fixed type info for type layout if the raw layout
1000+
// specifies size and alignment.
1001+
if (rawLayout->getSizeAndAlignment()) {
1002+
return IGM.typeLayoutCache.getOrCreateTypeInfoBasedEntry(*this, T);
1003+
}
1004+
9991005
auto likeType = rawLayout->getResolvedLikeType(decl)->getCanonicalType();
10001006
SILType loweredLikeType = IGM.getLoweredType(likeType);
10011007

@@ -1112,6 +1118,10 @@ namespace {
11121118
// layout of the struct is dependent on the archetype of the thing it's
11131119
// like.
11141120
if (rawLayout) {
1121+
// Note: We don't have to handle the size and alignment case here for
1122+
// raw layout because those are always fixed, so only dependent layouts
1123+
// will be non-fixed.
1124+
11151125
auto likeType = rawLayout->getResolvedLikeType(decl)->getCanonicalType();
11161126
SILType loweredLikeType = IGM.getLoweredType(likeType);
11171127

test/IRGen/Inputs/raw_layout_multifile_b.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ extension Foo where T == Int32 {
66

77
public func foo(_: borrowing Foo<Int32>) {}
88

9+
@_rawLayout(size: 4, alignment: 4)
10+
public struct Int32Fake: ~Copyable {
11+
var address: UnsafeMutablePointer<Int32> {
12+
.init(Builtin.unprotectedAddressOfBorrow(self))
13+
}
14+
}
15+
916
@_rawLayout(like: T)
1017
public struct UnsafeCell<T>: ~Copyable {
1118
var address: UnsafeMutablePointer<T> {

test/IRGen/raw_layout_multifile.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
@_rawLayout(like: Int32)
66
public struct Foo<T>: ~Copyable {}
77

8+
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}5MyIntVWV" = {{.*}} %swift.vwtable
9+
// size
10+
// CHECK-SAME: , {{i64|i32}} 4
11+
// stride
12+
// CHECK-SAME: , {{i64|i32}} 4
13+
// flags: alignment 3, noncopyable
14+
// CHECK-SAME: , <i32 0x800003>
15+
struct MyInt: ~Copyable {
16+
let x: Int32Fake
17+
}
18+
819
// CHECK-LABEL: @"$s{{[A-Za-z0-9_]*}}9BadBufferVWV" = {{.*}} %swift.vwtable
920
// size
1021
// CHECK-SAME: , {{i64|i32}} 48
@@ -38,3 +49,9 @@ public func something2() -> Int64? {
3849
let buf = BadBuffer()
3950
return buf.buf.address[1]
4051
}
52+
53+
// Force emission of MyInt's descriptor to be lazy...
54+
public func something3() -> Int32 {
55+
let x = MyInt(x: Int32Fake())
56+
return x.x.address.pointee
57+
}

0 commit comments

Comments
 (0)