Skip to content

Commit

Permalink
Merge pull request #3 from slangbot/format-5525-aleino/nullptr-deref
Browse files Browse the repository at this point in the history
Format code for PR shader-slang#5525
  • Loading branch information
aleino-nv authored Nov 8, 2024
2 parents c8b88c3 + cf4e7c1 commit 3e66d2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions source/slang/slang-ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ struct IRInst
template<typename T>
T* getNextChildOfType(IRInst* child = nullptr)
{
for (IRInst* cc = child ? child->getNextInst() : getFirstDecorationOrChild(); cc != nullptr; cc = cc->getNextInst())
for (IRInst* cc = child ? child->getNextInst() : getFirstDecorationOrChild(); cc != nullptr;
cc = cc->getNextInst())
{
if (T* cct = as<T>(cc))
return cct;
Expand Down Expand Up @@ -792,10 +793,11 @@ struct IRInst
void removeOperand(Index index);

/// Transfer any decorations of this instruction to the `target` instruction.
// TODO: rewrite as transferDecorationsTo(target) -> transferChildrenOfTypeTo<IRDecoration>(target)
// TODO: rewrite as transferDecorationsTo(target) ->
// transferChildrenOfTypeTo<IRDecoration>(target)
void transferDecorationsTo(IRInst* target);

template <typename T>
template<typename T>
void transferChildrenOfTypeTo(IRInst* target)
{
for (T* cc = getNextChildOfType<T>(); cc != nullptr; cc = getNextChildOfType<T>(cc))
Expand Down
6 changes: 4 additions & 2 deletions source/slang/slang-legalize-types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,11 @@ struct TupleTypeBuilder

// TODO: shallow clone of modifiers, etc.
IRStructField* originalField = findStructField(originalStructType, ee.fieldKey);
IRStructField* newField = builder->createStructField(ordinaryStructType, ee.fieldKey, fieldType);
IRStructField* newField =
builder->createStructField(ordinaryStructType, ee.fieldKey, fieldType);
// In case the original struct had offsets calculated, transfer those as well.
// The original offsets should still be valid, since we only skip fields of types that aren't representable in memory.
// The original offsets should still be valid, since we only skip fields of types
// that aren't representable in memory.
originalField->transferChildrenOfTypeTo<IROffsetDecoration>(newField);
}

Expand Down

0 comments on commit 3e66d2b

Please sign in to comment.