diff options
| author | Julius Ikkala <julius.ikkala@gmail.com> | 2025-01-17 18:58:18 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-17 08:58:18 -0800 |
| commit | ddc4a1799a9d21084604cc2bf334d5d91cb329e3 (patch) | |
| tree | 779e4d8c8ccbc48f2797a8672e9f5e78c5b081a7 /source/slang/slang-ir-clone.cpp | |
| parent | 91430870a8a6ec2825969823b892a9c8a0d588ab (diff) | |
Fix nullptr in generic specialization (#6066)
* Fix nullptr in generic specialization
* Fix formatting
* Revert "Fix nullptr in generic specialization" and add emitPtrLit instead
* Add type parameter to getPtrValue()
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-ir-clone.cpp')
| -rw-r--r-- | source/slang/slang-ir-clone.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/source/slang/slang-ir-clone.cpp b/source/slang/slang-ir-clone.cpp index 6bbaefa26..66af405d6 100644 --- a/source/slang/slang-ir-clone.cpp +++ b/source/slang/slang-ir-clone.cpp @@ -51,6 +51,20 @@ IRInst* cloneInstAndOperands(IRCloneEnv* env, IRBuilder* builder, IRInst* oldIns SLANG_ASSERT(builder); SLANG_ASSERT(oldInst); + // We start by mapping the type of the orignal instruction + // to its replacement value, if any. + // + auto oldType = oldInst->getFullType(); + auto newType = (IRType*)findCloneForOperand(env, oldType); + + // Pointer literals need to be handled separately, as they carry other data + // than just the operands. + if (oldInst->getOp() == kIROp_PtrLit) + { + auto oldPtr = as<IRPtrLit>(oldInst); + return builder->getPtrValue(newType, oldPtr->value.ptrVal); + } + // This logic will not handle any instructions // with special-case data attached, but that only // applies to `IRConstant`s at this point, and those @@ -62,12 +76,6 @@ IRInst* cloneInstAndOperands(IRCloneEnv* env, IRBuilder* builder, IRInst* oldIns // SLANG_ASSERT(!as<IRConstant>(oldInst)); - // We start by mapping the type of the orignal instruction - // to its replacement value, if any. - // - auto oldType = oldInst->getFullType(); - auto newType = (IRType*)findCloneForOperand(env, oldType); - // Next we will iterate over the operands of `oldInst` // to find their replacements and install them as // the operands of `newInst`. |
