Skip to content

Commit e9cce3c

Browse files
authored
Merge pull request #13806 from DougGregor/runtime-round-up-labels-align
2 parents 4a28ed3 + c9b7ec9 commit e9cce3c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

stdlib/public/runtime/Metadata.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,9 @@ swift::swift_getTupleTypeMetadata(size_t numElements,
913913

914914
// Allocate a copy of the labels string within the tuple type allocator.
915915
size_t labelsLen = strlen(labels);
916+
size_t labelsAllocSize = roundUpToAlignment(labelsLen + 1, sizeof(void*));
916917
char *newLabels =
917-
(char *)TupleTypes.getAllocator().Allocate(labelsLen + 1, alignof(char));
918+
(char *)TupleTypes.getAllocator().Allocate(labelsAllocSize, alignof(char));
918919
strcpy(newLabels, labels);
919920
key.Labels = newLabels;
920921

@@ -924,7 +925,7 @@ swift::swift_getTupleTypeMetadata(size_t numElements,
924925
// If we didn't manage to perform the insertion, free the memory associated
925926
// with the copy of the labels: nobody else can reference it.
926927
if (!result.second) {
927-
TupleTypes.getAllocator().Deallocate(newLabels, labelsLen + 1);
928+
TupleTypes.getAllocator().Deallocate(newLabels, labelsAllocSize);
928929
}
929930

930931
// Done.

test/Runtime/demangleToMetadata.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ DemangleToMetadataTests.test("tuple types") {
1616
expectEqual(type(of: ((), b: ())), _typeByMangledName("yt_yt1bt")!)
1717
expectEqual(type(of: (a: (), ())), _typeByMangledName("yt1a_ytt")!)
1818
expectEqual(type(of: (a: (), b: ())), _typeByMangledName("yt1a_yt1bt")!)
19+
20+
// Initial creation of metadata via demangling a type name.
21+
expectNotNil(_typeByMangledName("yt1a_yt3bcdt"))
1922
}
2023

2124
func f0() { }

0 commit comments

Comments
 (0)