From ddc4a1799a9d21084604cc2bf334d5d91cb329e3 Mon Sep 17 00:00:00 2001 From: Julius Ikkala Date: Fri, 17 Jan 2025 18:58:18 +0200 Subject: 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 --- source/slang/slang-ir-clone.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'source/slang/slang-ir-clone.cpp') 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(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(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`. -- cgit v1.2.3