[IRGen+Runtime] Layout string getEnumTag for fixed size enums subset (#66899)

* [IRGen+Runtime] Layout string getEnumTag for fixed size enums subset

getEnumTag impl for layout strings of fixed sized enums that use a function to fetch the enum tag

* Fix potential UB in IRGen
This commit is contained in:
Dario Rexin
2023-06-23 18:10:55 -07:00
committed by GitHub
parent a44c77d098
commit 270089f297
6 changed files with 111 additions and 9 deletions

View File

@@ -652,6 +652,17 @@ swift_generic_assignWithTake(swift::OpaqueValue *dest, swift::OpaqueValue *src,
return swift_generic_initWithTake(dest, src, metadata);
}
extern "C"
unsigned swift_enumFn_getEnumTag(swift::OpaqueValue *address,
const Metadata *metadata) {
auto addr = reinterpret_cast<const uint8_t *>(address);
LayoutStringReader reader{metadata->getLayoutString(),
layoutStringHeaderSize + sizeof(uint64_t)};
auto getEnumTag = readRelativeFunctionPointer<GetEnumTagFn>(reader);
return getEnumTag(addr);
}
extern "C" unsigned
swift_multiPayloadEnumGeneric_getEnumTag(swift::OpaqueValue *address,
const Metadata *metadata) {