Skip to content

Commit 2bcece3

Browse files
committed
[Runtime] Use aligned offset to compute new field offset for unmanaged properties in CVW
The original fix only added the field size to the unaligned offset, which is not correct.
1 parent 5d4e1d0 commit 2bcece3

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

stdlib/public/runtime/Metadata.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,18 +2846,16 @@ void swift::swift_initStructMetadataWithLayoutString(
28462846
const TypeLayout *fieldType = (const TypeLayout*)fieldTypes[i];
28472847
auto alignmentMask = fieldType->flags.getAlignmentMask();
28482848
fullOffset = roundUpToAlignMask(fullOffset, alignmentMask);
2849-
2849+
size_t offset = fullOffset - unalignedOffset + previousFieldOffset;
28502850
if (fieldTag <= 0x4) {
2851-
size_t offset = fullOffset - unalignedOffset + previousFieldOffset;
2852-
28532851
auto tag = fieldTag <= 0x2 ? RefCountingKind::UnknownUnowned :
28542852
RefCountingKind::UnknownWeak;
28552853

28562854
auto tagAndOffset = ((uint64_t)tag << 56) | offset;
28572855
writer.writeBytes(tagAndOffset);
28582856
previousFieldOffset = fieldType->size - sizeof(uintptr_t);
28592857
} else {
2860-
previousFieldOffset += fieldType->size;
2858+
previousFieldOffset = offset + fieldType->size;
28612859
}
28622860

28632861
fullOffset += fieldType->size;

test/Interpreter/Inputs/layout_string_witnesses_types_resilient.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public struct GenericResilient<C, T> {
2020
}
2121

2222
public struct GenericResilientWithUnmanagedAndWeak<T> {
23-
public let x: T
23+
public let b: Bool = false
2424
public unowned(unsafe) var y: AnyObject?
25-
public let z: Int = 500
25+
public let z: Bool = false
26+
public let x: T
2627
public weak var w: AnyObject?
2728

2829
public init(x: T) {

0 commit comments

Comments
 (0)