diff options
| author | Yong He <yonghe@outlook.com> | 2025-10-10 14:34:56 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-10 21:34:56 +0000 |
| commit | 462ea4e66569efa978e4057ea2d041c69d4a729b (patch) | |
| tree | 5bda696d5e5af79e726b771c712c28165988b4ce /source/slang/slang-ir-lower-existential.cpp | |
| parent | 1e0908bd7107dfbdac912b693c3ab9bd6e1dc8b3 (diff) | |
Fix `specializeRTTIObject` to use non-zero RTTI value to work with `Optional<T>`. (#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<IFoo>.hasValue` to always return false in such
cases.
Diffstat (limited to 'source/slang/slang-ir-lower-existential.cpp')
| -rw-r--r-- | source/slang/slang-ir-lower-existential.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/source/slang/slang-ir-lower-existential.cpp b/source/slang/slang-ir-lower-existential.cpp index 076ed57bd..ea7f906a9 100644 --- a/source/slang/slang-ir-lower-existential.cpp +++ b/source/slang/slang-ir-lower-existential.cpp @@ -68,13 +68,15 @@ struct ExistentialLoweringContext auto witnessTableIdType = cast<IRWitnessTableIDType>(tupleType->getOperand(1)); auto anyValueType = cast<IRAnyValueType>(tupleType->getOperand(2)); - // Create a null value for `rttiObject` for now since it will not be used. + // Create a standin value for `rttiObject` for now since it will not be used + // other than test for null in the case of `Optional<IFoo>`. auto uint2Type = builder->getVectorType( builder->getUIntType(), builder->getIntValue(builder->getIntType(), 2)); + IRInst* standinVal = builder->getIntValue(builder->getUIntType(), 0xFFFFFFFF); IRInst* zero = builder->getIntValue(builder->getUIntType(), 0); - IRInst* zeroVectorArgs[] = {zero, zero}; - IRInst* rttiObject = builder->emitMakeVector(uint2Type, 2, zeroVectorArgs); + IRInst* standinRTTIVectorArgs[] = {standinVal, zero}; + IRInst* rttiObject = builder->emitMakeVector(uint2Type, 2, standinRTTIVectorArgs); // Pack the user provided value into `AnyValue`. IRInst* packedValue = inst->getValue(); |
