From a9ce7520e5f1b97b09e5de69455258bef55e10d2 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Thu, 23 Jan 2025 00:06:21 -0800 Subject: Fix incorrect resolve of specialization instance (#6162) * Fix incorrect resolve of specialization instance While checking the uninitialized variables, we were not resolving the specialized instance correctly. This commit repeats the resolve while the result is a specialization instance. A new test is added for this: tests/diagnostics/uninitialized-generic.slang After the problem is fixed, it revealed another problem in existing tests: tests/compute/nested-generics2.slang tests/diagnostics/uninitialized-local-variables.slang When a struct has a member variable whose type is a generic type, we cannot iterate over its member variables yet, because the type is unknown until the generic function/struct is specialized. We will have to give up checking for these cases. --- source/slang/slang-ir-use-uninitialized-values.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'source') diff --git a/source/slang/slang-ir-use-uninitialized-values.cpp b/source/slang/slang-ir-use-uninitialized-values.cpp index b1db2913e..51de2117c 100644 --- a/source/slang/slang-ir-use-uninitialized-values.cpp +++ b/source/slang/slang-ir-use-uninitialized-values.cpp @@ -139,13 +139,6 @@ static bool isDifferentiableFunc(IRInst* func) return false; } -static IRInst* resolveSpecialization(IRSpecialize* spec) -{ - IRInst* base = spec->getBase(); - IRGeneric* generic = as(base); - return findInnerMostGenericReturnVal(generic); -} - // The `upper` field contains the struct that the type is // is contained in. It is used to check for empty structs. static bool canIgnoreType(IRType* type, IRType* upper) @@ -174,6 +167,10 @@ static bool canIgnoreType(IRType* type, IRType* upper) if (as(type)) return true; + // We don't know what type it will be yet. + if (as(type)) + return true; + // For pointers, check the value type (primarily for globals) if (auto ptr = as(type)) { @@ -188,7 +185,7 @@ static bool canIgnoreType(IRType* type, IRType* upper) // In the case of specializations, check returned type if (auto spec = as(type)) { - IRInst* inner = resolveSpecialization(spec); + IRInst* inner = getResolvedInstForDecorations(spec); IRType* innerType = as(inner); return canIgnoreType(innerType, upper); } @@ -231,7 +228,7 @@ static InstructionUsageType getCallUsageType(IRCall* call, IRInst* inst) IRFunc* ftn = nullptr; IRFuncType* ftype = nullptr; if (auto spec = as(callee)) - ftn = as(resolveSpecialization(spec)); + ftn = as(getResolvedInstForDecorations(spec)); // Differentiable functions are mostly ignored, treated as having inout parameters else if (as(callee)) -- cgit v1.2.3