From 462ea4e66569efa978e4057ea2d041c69d4a729b Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 10 Oct 2025 14:34:56 -0700 Subject: Fix `specializeRTTIObject` to use non-zero RTTI value to work with `Optional`. (#8677) Closes #8673. The issue is that we use the RTTI field of an existential to check if it is null. We have the logic to help the user to fill in a non-zero value for the RTTI field when such an object is filled from the host. However, when there is slang code creating an existential value, we still have old logic in the compiler that just fills in 0 for the RTTI field, causing an `Optional.hasValue` to always return false in such cases. --- source/slang/slang-ir-lower-generics.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/slang/slang-ir-lower-generics.cpp') diff --git a/source/slang/slang-ir-lower-generics.cpp b/source/slang/slang-ir-lower-generics.cpp index be21a66ba..8677973f5 100644 --- a/source/slang/slang-ir-lower-generics.cpp +++ b/source/slang/slang-ir-lower-generics.cpp @@ -23,11 +23,11 @@ namespace Slang { // Replace all uses of RTTI objects with its sequential ID. -// Currently we don't use RTTI objects at all, so all of them -// are 0. +// Currently we don't use RTTI objects other than check for null/invalid value, +// so all of them are 0xFFFFFFFF. void specializeRTTIObjectReferences(SharedGenericsLoweringContext* sharedContext) { - uint32_t id = 0; + uint32_t id = 0xFFFFFFFF; for (auto rtti : sharedContext->mapTypeToRTTIObject) { IRBuilder builder(sharedContext->module); -- cgit v1.2.3