summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/slang/slang-check-decl.cpp5
-rw-r--r--tests/diagnostics/autodiff-custom-diff-unresolved.slang23
2 files changed, 28 insertions, 0 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 1ebd50cbd..56b0a991b 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -7042,6 +7042,11 @@ namespace Slang
{
if (declRefExpr->declRef)
visitor->ensureDecl(declRefExpr->declRef, DeclCheckState::TypesFullyResolved);
+ else
+ {
+ visitor->getSink()->diagnose(attr, Diagnostics::cannotResolveDerivativeFunction);
+ return;
+ }
}
else if (auto overloadedExpr = as<OverloadedExpr>(checkedFuncExpr))
{
diff --git a/tests/diagnostics/autodiff-custom-diff-unresolved.slang b/tests/diagnostics/autodiff-custom-diff-unresolved.slang
new file mode 100644
index 000000000..0ca055b59
--- /dev/null
+++ b/tests/diagnostics/autodiff-custom-diff-unresolved.slang
@@ -0,0 +1,23 @@
+//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK):
+
+// Simple check to see that the compiler returns an error message if the
+// custom derivative definition points to an undefined function.
+//
+
+void __d_f(float x, float.Differential dout)
+{
+}
+
+[BackwardDerivative(__d_g)]
+float f(float x)
+{
+ // CHECK: tests/diagnostics/autodiff-custom-diff-unresolved.slang([[@LINE-3]]): error 30015: undefined identifier '__d_g'.
+ // CHECK-NEXT: [BackwardDerivative(__d_g)]
+ return x * x;
+}
+
+float main(float x)
+{
+ DifferentialPair<float> dpx = diffPair(x, 1.f);
+ bwd_diff(f)(dpx, 1.f);
+} \ No newline at end of file