From 54d9b345bff4b01949e875366cb1e7cf1c021c61 Mon Sep 17 00:00:00 2001 From: "James Helferty (NVIDIA)" Date: Wed, 8 Oct 2025 19:11:10 -0400 Subject: parser: Avoid dropping modifiers when splitting list (#8546) Fix for a linked list usage bug; avoids dropping any modifiers when moving type modifiers from a linked list of modifiers into their own linked list. Since this change results in no_diff modifiers to traditional functions ending up on the return type instead of the function (due to the order they're parsed in), we duplicate the no_diff modifier onto the function declaration after the fact. Includes a test for the original issue. The no_diff redistribution case is covered by a slangpy device test case. Fixes #8332 --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-check-decl.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source/slang/slang-check-decl.cpp') diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 4bfbde584..867c1daad 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -10241,6 +10241,17 @@ void SemanticsDeclHeaderVisitor::checkInterfaceRequirement(Decl* decl) } } +bool doesTypeHaveNoDiffModifier(Type* type) +{ + if (auto modifiedType = as(type)) + { + if (modifiedType->findModifier() != nullptr) + return true; + return doesTypeHaveNoDiffModifier(modifiedType->getBase()); + } + return false; +} + void SemanticsDeclHeaderVisitor::checkCallableDeclCommon(CallableDecl* decl) { for (auto paramDecl : decl->getParameters()) @@ -10259,6 +10270,13 @@ void SemanticsDeclHeaderVisitor::checkCallableDeclCommon(CallableDecl* decl) } decl->errorType = errorType; + if (doesTypeHaveNoDiffModifier(decl->returnType.type)) + { + auto noDiffMod = m_astBuilder->create(); + noDiffMod->loc = decl->loc; + addModifier(decl, noDiffMod); + } + checkDifferentiableCallableCommon(decl); // If this method is intended to be a CUDA kernel, verify that the return type is void. -- cgit v1.2.3