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 3 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
10 changes: 10 additions & 0 deletions source/slang/slang-ir-clone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ IRInst* cloneInstAndOperands(IRCloneEnv* env, IRBuilder* builder, IRInst* oldIns
SLANG_ASSERT(builder);
SLANG_ASSERT(oldInst);

// 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);
auto newInst = builder->emitPtrLit(oldPtr->getFullType(), oldPtr->value.ptrVal);
newInst->sourceLoc = oldPtr->sourceLoc;
return newInst;
}

// 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 Down
2 changes: 2 additions & 0 deletions source/slang/slang-ir-insts.h
Original file line number Diff line number Diff line change
Expand Up @@ -4433,6 +4433,8 @@ struct IRBuilder

IRGlobalConstant* emitGlobalConstant(IRType* type, IRInst* val);

IRConstant* emitPtrLit(IRType* type, void* ptr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding this, we should change IRBuilder::_getPtrValue to take a type. We should bottleneck all constant inst creation through findOrEmitConstant as in _getPtrValue.


IRInst* emitWaveMaskBallot(IRType* type, IRInst* mask, IRInst* condition);
IRInst* emitWaveMaskMatch(IRType* type, IRInst* mask, IRInst* value);

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
10 changes: 10 additions & 0 deletions source/slang/slang-ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5844,6 +5844,16 @@ IRGlobalConstant* IRBuilder::emitGlobalConstant(IRType* type, IRInst* val)
return inst;
}

IRConstant* IRBuilder::emitPtrLit(IRType* type, void* ptrVal)
{
const size_t prefixSize = SLANG_OFFSET_OF(IRConstant, value);
const size_t instSize = prefixSize + sizeof(void*);
auto inst = static_cast<IRConstant*>(_createInst(instSize, type, kIROp_PtrLit));
inst->value.ptrVal = ptrVal;
addInst(inst);
return inst;
}

IRInst* IRBuilder::emitWaveMaskBallot(IRType* type, IRInst* mask, IRInst* condition)
{
auto inst = createInst<IRInst>(this, kIROp_WaveMaskBallot, type, mask, condition);
Expand Down