Skip to content

Commit df6fb25

Browse files
author
Davide Italiano
committed
[Reflection] Fix the computation of boundaries in getFieldName().
1 parent 0460669 commit df6fb25

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

include/swift/Reflection/Records.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ class FieldRecord {
8787

8888
StringRef getFieldName(uintptr_t Offset, uintptr_t Low,
8989
uintptr_t High) const {
90-
if (Offset < Low || Offset > High)
90+
uintptr_t nameAddr = (uintptr_t)FieldName.get() + Offset;
91+
if (nameAddr < Low || nameAddr > High)
9192
return "";
92-
return (const char *)((uintptr_t)FieldName.get() + Offset);
93+
return (const char *)nameAddr;
9394
}
9495

9596
bool isIndirectCase() const {

stdlib/public/Reflection/TypeRefBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ bool TypeRefBuilder::getFieldTypeRefs(
194194
- FD.second->TypeReference.SectionOffset;
195195
auto FieldOffset = FD.second->Field.SectionOffset
196196
- FD.second->ReflectionString.SectionOffset;
197-
auto Low = FD.second->ReflectionString.SectionOffset;
198-
auto High = FD.second->ReflectionString.Metadata.size();
197+
auto Low = (uintptr_t)(FD.second->ReflectionString.Metadata.startAddress());
198+
auto High = (uintptr_t)(FD.second->ReflectionString.Metadata.endAddress());
199199
auto FieldName = Field.getFieldName(FieldOffset, Low, High);
200200

201201
// Empty cases of enums do not have a type
@@ -341,8 +341,8 @@ void TypeRefBuilder::dumpFieldSection(std::ostream &OS) {
341341
OS << '-';
342342
OS << '\n';
343343
for (auto &field : descriptor) {
344-
auto Low = sections.ReflectionString.SectionOffset;
345-
auto High = sections.ReflectionString.Metadata.size();
344+
auto Low = (uintptr_t)sections.ReflectionString.Metadata.startAddress();
345+
auto High = (uintptr_t)sections.ReflectionString.Metadata.endAddress();
346346
OS << std::string(field.getFieldName(NameOffset, Low, High).begin(),
347347
field.getFieldName(NameOffset, Low, High).end());
348348
if (field.hasMangledTypeName()) {

stdlib/public/runtime/ReflectionMirror.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static bool _shouldReportMissingReflectionMetadataWarnings() {
328328
const FieldDescriptor &descriptor = *fields;
329329
auto &field = descriptor.getFields()[index];
330330
// Bounds are always valid as the offset is constant.
331-
auto name = field.getFieldName(0, 0, 1);
331+
auto name = field.getFieldName(0, 0, std::numeric_limits<uint64_t>::max());
332332

333333
// Enum cases don't always have types.
334334
if (!field.hasMangledTypeName())

0 commit comments

Comments
 (0)