From 567c7e09b6df36b535c4ffbccd6a3658d18e04c2 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Tue, 12 Nov 2024 19:46:45 +0200 Subject: Fix two specialization bugs (#5540) * Fix two specialization bugs The first bug was introduced in b2ca2d5a4efeae807d3c3f48f60235e47413b559 and ran some code at scope exit that dereferenced a nullptr context. The second bug was introduced in bea1394ad35680940a0b69b9c67efc43764cc194 and would cause the wrong mangled name to be used during specialization. This closes #5516. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-ir-link.cpp | 9 ++++++--- source/slang/slang-ir-specialize.cpp | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index a764db117..28bb63a87 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -873,6 +873,7 @@ static void maybeCopyLayoutInformationToParameters(IRFunc* func, IRBuilder* buil IRFunc* specializeIRForEntryPoint( IRSpecContext* context, + String const& mangledName, EntryPoint* entryPoint, UnownedStringSlice nameOverride) { @@ -886,7 +887,6 @@ IRFunc* specializeIRForEntryPoint( // not the same as the mangled name of the decl. // RefPtr sym; - auto mangledName = entryPoint->getEntryPointMangledName(0); if (!context->getSymbols().tryGetValue(mangledName, sym)) { String hashedName = getHashedName(mangledName.getUnownedSlice()); @@ -1829,8 +1829,11 @@ LinkedIR linkIR(CodeGenContext* codeGenContext) auto entryPointMangledName = program->getEntryPointMangledName(entryPointIndex); auto nameOverride = program->getEntryPointNameOverride(entryPointIndex); auto entryPoint = program->getEntryPoint(entryPointIndex).get(); - irEntryPoints.add( - specializeIRForEntryPoint(context, entryPoint, nameOverride.getUnownedSlice())); + irEntryPoints.add(specializeIRForEntryPoint( + context, + entryPointMangledName, + entryPoint, + nameOverride.getUnownedSlice())); } // Layout information for global shader parameters is also required, diff --git a/source/slang/slang-ir-specialize.cpp b/source/slang/slang-ir-specialize.cpp index 81ad5ca2a..2757538a6 100644 --- a/source/slang/slang-ir-specialize.cpp +++ b/source/slang/slang-ir-specialize.cpp @@ -2979,7 +2979,7 @@ IRInst* specializeGenericImpl( builder->setInsertBefore(genericVal); List pendingWorkList; - SLANG_DEFER(for (Index ii = pendingWorkList.getCount() - 1; ii >= 0; ii--) + SLANG_DEFER(for (Index ii = pendingWorkList.getCount() - 1; ii >= 0; ii--) if (context) context->addToWorkList(pendingWorkList[ii]);); // Now we will run through the body of the generic and -- cgit v1.2.3