Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizhangNV committed Feb 12, 2025
1 parent 10933bd commit 50d8580
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion source/slang/slang-diagnostic-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2551,7 +2551,7 @@ DIAGNOSTIC(
attemptToQuerySizeOfUnsizedArray,
"cannot obtain the size of an unsized array.")

DIAGNOSTIC(56003, Error, useOfUninitializedResourceType, "use of uninitialized resource type '$0'.")
DIAGNOSTIC(56003, Error, useOfUninitializedResourceType, "use of uninitialized opaque type '$0'.")

// Metal
DIAGNOSTIC(
Expand Down
22 changes: 10 additions & 12 deletions source/slang/slang-ir-legalize-types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2053,19 +2053,17 @@ static LegalVal coerceToLegalType(IRTypeLegalizationContext* context, LegalType

static LegalVal legalizeUndefined(IRTypeLegalizationContext* context, IRInst* inst)
{
if (auto structType = as<IRStructType>(inst->getFullType()))
List<IRType*> opaqueTypes;
if (isOpaqueType(inst->getFullType(), opaqueTypes))
{
for (auto field : structType->getFields())
{
if (isResourceType(field->getFieldType()))
{
context->m_sink->diagnose(
field,
Diagnostics::useOfUninitializedResourceType,
field->getFieldType());
SLANG_ABORT_COMPILATION("use of uninitialized resource type");
}
}
auto opaqueType = opaqueTypes[0];
auto containerType = opaqueTypes.getCount() > 1 ? opaqueTypes[1] : opaqueType;

context->m_sink->diagnose(
containerType,
Diagnostics::useOfUninitializedResourceType,
opaqueType);
SLANG_ABORT_COMPILATION("use of uninitialized resource type");
}
return LegalVal();
}
Expand Down
21 changes: 21 additions & 0 deletions source/slang/slang-legalize-types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,27 @@ bool isResourceType(IRType* type)
return false;
}

bool isOpaqueType(IRType* type, List<IRType*>& opaqueTypes)
{
if (isResourceType(type))
{
opaqueTypes.add(type);
return true;
}

if (auto structType = as<IRStructType>(type))
{
for (auto field : structType->getFields())
{
if (isOpaqueType(field->getFieldType(), opaqueTypes))
{
opaqueTypes.add(type);
return true;
}
}
}
return false;
}
// Helper wrapper function around isResourceType that checks if the given
// type is a pointer to a resource type or a physical storage buffer.
bool isPointerToResourceType(IRType* type)
Expand Down
1 change: 1 addition & 0 deletions source/slang/slang-legalize-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ void legalizeEmptyTypes(TargetProgram* target, IRModule* module, DiagnosticSink*

bool isResourceType(IRType* type);

bool isOpaqueType(IRType* type, List<IRType*>& opaqueTypes);

} // namespace Slang

Expand Down
4 changes: 2 additions & 2 deletions tests/diagnostics/uninitialized-resource-type.slang.expected
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
result code = -1
standard error = {
tests/diagnostics/test1.slang(31): warning 41016: use of uninitialized variable 'foo'
tests/diagnostics/uninitialized-resource-type.slang(31): warning 41016: use of uninitialized variable 'foo'
const let result = process(foo);
^
tests/diagnostics/test1.slang(5): error 56003: use of uninitialized resource type 'Texture2D'.
tests/diagnostics/uninitialized-resource-type.slang(5): error 56003: use of uninitialized opaque type 'Texture2D'.
struct Foo
^~~
}

0 comments on commit 50d8580

Please sign in to comment.