summaryrefslogtreecommitdiffstats
path: root/tests/current-bugs
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-04-21 10:06:55 -0400
committerGitHub <noreply@github.com>2022-04-21 10:06:55 -0400
commit34f8b5e722aede018e275324c43055cad9a9ca5a (patch)
tree08432f3235b334403408d53de31178ebb5a24e11 /tests/current-bugs
parent3d1d692f939d2e23704a90a9cd009194905de5dc (diff)
Example for compiler crash with recursive function calling (#2196)
* #include an absolute path didn't work - because paths were taken to always be relative. * Add crash when lowering a recursive function. * Add simplified recursive crash example. * Fix typos/tabs.
Diffstat (limited to 'tests/current-bugs')
-rw-r--r--tests/current-bugs/mul-crash.slang27
-rw-r--r--tests/current-bugs/recursive-call-crash.slang28
2 files changed, 55 insertions, 0 deletions
diff --git a/tests/current-bugs/mul-crash.slang b/tests/current-bugs/mul-crash.slang
new file mode 100644
index 000000000..a5ee7e62c
--- /dev/null
+++ b/tests/current-bugs/mul-crash.slang
@@ -0,0 +1,27 @@
+//DISABLE_TEST:SIMPLE: -target hlsl -entry computeMain -stage compute
+
+// This test crashes when enabled, with a stack overrun. The crash happens when lowering into IR.
+// NOTE! That the code has a bug in that the mul function calls itself - so would exhaust the stack *when run*.
+// This exhausts the stack when compiling which shouldn't happen.
+
+RWStructuredBuffer<float> outputBuffer;
+
+struct SomeType
+{
+ float2x2 v;
+};
+
+float mul(SomeType a, float2 v) { return mul(a, v).x; }
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+
+ float inVal = float(tid);
+
+ float2 v = float2(inVal, inVal + 2);
+ SomeType t = { inVal + 1, 0, 1, 0 };
+
+ outputBuffer[tid] = mul(t, v).x;
+} \ No newline at end of file
diff --git a/tests/current-bugs/recursive-call-crash.slang b/tests/current-bugs/recursive-call-crash.slang
new file mode 100644
index 000000000..4641827a5
--- /dev/null
+++ b/tests/current-bugs/recursive-call-crash.slang
@@ -0,0 +1,28 @@
+//DISABLE_TEST:SIMPLE: -target hlsl -entry computeMain -stage compute
+
+// This is a simplified version of the mul-crash.slang test, that shows the underlying issue is recursion.
+// This test crashes when enabled, with a stack overrun. The crash happens when lowering into IR.
+//
+// It appears recursion in GLSL/HLSL is not allowed (at least with earlier shader models), but the compiler
+// shouldn't crash. Moreover the Slang language can support recursion today on non GPU targets.
+
+RWStructuredBuffer<int> outputBuffer;
+
+int doRecursive(int a)
+{
+ if (a > 0)
+ {
+ return doRecursive(a - 1) + 2;
+ }
+ return 10;
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint tid = dispatchThreadID.x;
+
+ let val = doRecursive(tid);
+
+ outputBuffer[tid] = val;
+} \ No newline at end of file