Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nullptr in generic specialization #6066

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions source/slang/slang-ir-clone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion source/slang/slang-ir-insts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3599,7 +3599,7 @@ struct IRBuilder
IRInst* getFloatValue(IRType* type, IRFloatingPointValue value);
IRStringLit* getStringValue(const UnownedStringSlice& slice);
IRBlobLit* getBlobValue(ISlangBlob* blob);
IRPtrLit* _getPtrValue(void* ptr);
IRPtrLit* getPtrValue(IRType* type, void* ptr);
IRPtrLit* getNullPtrValue(IRType* type);
IRPtrLit* getNullVoidPtrValue() { return getNullPtrValue(getPtrType(getVoidType())); }
IRVoidLit* getVoidValue();
Expand Down
9 changes: 9 additions & 0 deletions source/slang/slang-ir-link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,15 @@ IRInst* cloneInst(
{
// We need to special-case any instruction that is not
// allocated like an ordinary `IRInst` with trailing args.
case kIROp_IntLit:
case kIROp_FloatLit:
case kIROp_BoolLit:
case kIROp_StringLit:
case kIROp_BlobLit:
case kIROp_PtrLit:
case kIROp_VoidLit:
return cloneValue(context, originalInst);

case kIROp_Func:
return cloneFuncImpl(context, builder, cast<IRFunc>(originalInst), originalValues);

Expand Down
5 changes: 2 additions & 3 deletions source/slang/slang-ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2395,9 +2395,8 @@ IRBlobLit* IRBuilder::getBlobValue(ISlangBlob* blob)
return static_cast<IRBlobLit*>(_findOrEmitConstant(keyInst));
}

IRPtrLit* IRBuilder::_getPtrValue(void* data)
IRPtrLit* IRBuilder::getPtrValue(IRType* type, void* data)
{
auto type = getPtrType(getVoidType());
IRConstant keyInst;
memset(&keyInst, 0, sizeof(keyInst));
keyInst.m_op = kIROp_PtrLit;
Expand Down Expand Up @@ -6324,7 +6323,7 @@ IRDecoration* IRBuilder::addDecoration(

void IRBuilder::addHighLevelDeclDecoration(IRInst* inst, Decl* decl)
{
auto ptrConst = _getPtrValue(decl);
auto ptrConst = getPtrValue(getPtrType(getVoidType()), decl);
addDecoration(inst, kIROp_HighLevelDeclDecoration, ptrConst);
}

Expand Down