summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-02-27 21:21:39 -0800
committerGitHub <noreply@github.com>2023-02-27 21:21:39 -0800
commitf23e36243e9c59c02f66ec2e18b80ba4ea540f45 (patch)
tree6bf0e2a3676fe84067f70fcbda4549fa4eb6504d /tests/diagnostics
parent10e2d9c7c532c204f26bb2c9f383f21b121b2ff2 (diff)
Diagnose on storing differentiable value into non-differentiable location. (#2681)
Diffstat (limited to 'tests/diagnostics')
-rw-r--r--tests/diagnostics/autodiff-data-flow-3.slang26
-rw-r--r--tests/diagnostics/autodiff-data-flow-3.slang.expected8
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/diagnostics/autodiff-data-flow-3.slang b/tests/diagnostics/autodiff-data-flow-3.slang
new file mode 100644
index 000000000..0a8e3e58a
--- /dev/null
+++ b/tests/diagnostics/autodiff-data-flow-3.slang
@@ -0,0 +1,26 @@
+//DIAGNOSTIC_TEST:SIMPLE:
+
+struct DiffT : IDifferentiable
+{
+ float f;
+}
+struct NoDiffField
+{
+ DiffT fp;
+}
+
+[BackwardDifferentiable]
+float g(float x)
+{
+ NoDiffField obj;
+ obj.fp.f = x * x; // Error, this location cannot hold derivative.
+ return obj.fp.f;
+}
+
+[BackwardDifferentiable]
+float h(float x)
+{
+ NoDiffField obj;
+ obj.fp.f = detach(x * x); // OK.
+ return obj.fp.f;
+}
diff --git a/tests/diagnostics/autodiff-data-flow-3.slang.expected b/tests/diagnostics/autodiff-data-flow-3.slang.expected
new file mode 100644
index 000000000..73381cf58
--- /dev/null
+++ b/tests/diagnostics/autodiff-data-flow-3.slang.expected
@@ -0,0 +1,8 @@
+result code = -1
+standard error = {
+tests/diagnostics/autodiff-data-flow-3.slang(16): error 41024: derivative is lost during assignment to non-differentiable location. Use 'detach()' to clarify intention.
+ obj.fp.f = x * x; // Error, this location cannot hold derivative.
+ ^
+}
+standard output = {
+}