From 6f6103c4dbc77d5bceae7c8e766ec3cabc293364 Mon Sep 17 00:00:00 2001 From: Julius Ikkala Date: Sat, 3 May 2025 23:27:03 +0300 Subject: Add IREnumType to distinguish enums from ints and each other (#6973) * Add IREnumType to distinguish enums from ints and each other * Add issue example as test * format code * Add expected test output * Fix peephole optimization hanging No idea why this PR triggered this, but there seems to have been a clear bug here anyway, so may just as well fix it now. * Move enum lowering later * Add linkage decoration to enum type * Use filecheck-buffer instead of expected.txt * Fix comment * Make enum casts actually use IR enum casts They were all BuiltinCasts by accident * Lower enum type before VM * Deal with rate-qualified types in enum cast * Allow any value marshalling for enum types * Handle new enum instructions in a couple more switches * Fix formatting --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-ir-any-value-marshalling.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'source/slang/slang-ir-any-value-marshalling.cpp') diff --git a/source/slang/slang-ir-any-value-marshalling.cpp b/source/slang/slang-ir-any-value-marshalling.cpp index d124b293d..b3bcf3316 100644 --- a/source/slang/slang-ir-any-value-marshalling.cpp +++ b/source/slang/slang-ir-any-value-marshalling.cpp @@ -155,6 +155,13 @@ struct AnyValueMarshallingContext case kIROp_PtrType: context->marshalBasicType(builder, dataType, concreteTypedVar); break; + case kIROp_EnumType: + { + auto enumType = static_cast(dataType); + auto tagType = enumType->getTagType(); + context->marshalBasicType(builder, tagType, concreteTypedVar); + break; + } case kIROp_VectorType: { auto vectorType = static_cast(dataType); @@ -868,6 +875,12 @@ SlangInt _getAnyValueSizeRaw(IRType* type, SlangInt offset) case kIROp_UInt8Type: case kIROp_Int8Type: return offset + 1; + case kIROp_EnumType: + { + auto enumType = static_cast(type); + auto tagType = enumType->getTagType(); + return _getAnyValueSizeRaw(tagType, offset); + } case kIROp_VectorType: { auto vectorType = static_cast(type); -- cgit v1.2.3