summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-decl.cpp
diff options
context:
space:
mode:
authorJames Helferty (NVIDIA) <jhelferty@nvidia.com>2025-10-08 19:11:10 -0400
committerGitHub <noreply@github.com>2025-10-08 23:11:10 +0000
commit54d9b345bff4b01949e875366cb1e7cf1c021c61 (patch)
tree374b635c94799c151f1ed98e562a9c1e194d086b /source/slang/slang-check-decl.cpp
parenteda080bbf7a2b48e26342df13005a40434f7d802 (diff)
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>
Diffstat (limited to 'source/slang/slang-check-decl.cpp')
-rw-r--r--source/slang/slang-check-decl.cpp18
1 files changed, 18 insertions, 0 deletions
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<ModifiedType>(type))
+ {
+ if (modifiedType->findModifier<NoDiffModifierVal>() != 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<NoDiffModifier>();
+ 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.