summaryrefslogtreecommitdiff
path: root/tests/diagnostics/lvalue-in-bwd-diff.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-07-29 19:26:52 -0700
committerGitHub <noreply@github.com>2025-07-29 19:26:52 -0700
commitb8663a5d93e6e73d5e2d7e737cffd1efac055719 (patch)
tree21eedc0d19065306eb4de7e1be8d00d1045ee032 /tests/diagnostics/lvalue-in-bwd-diff.slang
parent48efc60380aa79e8c4aba13976cc2015f38a659e (diff)
Fix ICE when immutable value is passed to a bwd_diff function. (#7973)
Diffstat (limited to 'tests/diagnostics/lvalue-in-bwd-diff.slang')
-rw-r--r--tests/diagnostics/lvalue-in-bwd-diff.slang23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/diagnostics/lvalue-in-bwd-diff.slang b/tests/diagnostics/lvalue-in-bwd-diff.slang
new file mode 100644
index 000000000..2e12bf5c0
--- /dev/null
+++ b/tests/diagnostics/lvalue-in-bwd-diff.slang
@@ -0,0 +1,23 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv
+[Differentiable]
+float square(float x, float y)
+{
+ return x * x + y * y;
+}
+
+void main()
+{
+ // Forward mode differentiation
+ let x = diffPair(3.0, 1.0); // x = 3, 𝜕x/𝜕𝛉 = 1
+ let y = diffPair(4.0, 1.0); // y = 4, 𝜕y/𝜕𝛄 = 1
+ let result = fwd_diff(square)(x, y);
+ printf("dResult: %f\n", result.d);
+
+ // Backward mode differentiation
+ let dLdSquare = 1.0f;
+ // CHECK-NOT: error 30049
+ // CHECK: error 30047
+ // CHECK-NOT: error 30049
+ bwd_diff(square)(x, y, dLdSquare);
+ printf("dL/dx: %f, dL/dy: %f\n", x.d, y.d);
+}