summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-04-21 14:05:49 +0800
committerGitHub <noreply@github.com>2023-04-21 14:05:49 +0800
commitdeb130645e8538eed8fb9f682de64e2dd329473d (patch)
tree100542512c9eece9d147dee0728ad3d6aa07df61 /tests/diagnostics
parent8177fff665d10f2a116d8fd6b7a48b68d518647f (diff)
Add warning for returning without initializing out parameter (#2807)
* Add warning for returning without initializing out parameter * Add unused prelude function to squash uninitialized out variable warnings
Diffstat (limited to 'tests/diagnostics')
-rw-r--r--tests/diagnostics/uninitialized-out.slang50
-rw-r--r--tests/diagnostics/uninitialized-out.slang.expected14
2 files changed, 63 insertions, 1 deletions
diff --git a/tests/diagnostics/uninitialized-out.slang b/tests/diagnostics/uninitialized-out.slang
index c285970da..d0d87449f 100644
--- a/tests/diagnostics/uninitialized-out.slang
+++ b/tests/diagnostics/uninitialized-out.slang
@@ -2,6 +2,56 @@
float foo(out float3 v)
{
+ // This should error as we haven't set v before we read from it
float r = v.x + 1.0;
+ // This should warn as we haven't set v before we return
return r;
}
+
+// This should warn as we return without x being initialized
+float bar(out float x)
+{
+ return 0;
+}
+
+// This should also warn pointing at the implicit return
+void baz(out float x) {}
+
+void twoReturns(bool b, out float y)
+{
+ if(b)
+ {
+ // Should warn
+ return;
+ }
+ y = 0;
+ // Shouldn't warn
+ return;
+}
+
+void twoOkReturns(bool b, out float y)
+{
+ if(b)
+ {
+ // Shouldn't warn
+ unused(y);
+ return;
+ }
+ y = 0;
+ // Shouldn't warn
+ return;
+}
+
+// TODO: This should warn that n is potentially uninitialized
+int ok(bool b, out int n)
+{
+ if(b)
+ n = 0;
+ return n;
+}
+
+// TODO: This should warn that arr isn't fully initialized
+void partial(out float arr[2])
+{
+ arr[0] = 1;
+}
diff --git a/tests/diagnostics/uninitialized-out.slang.expected b/tests/diagnostics/uninitialized-out.slang.expected
index feb8c494a..5846c12df 100644
--- a/tests/diagnostics/uninitialized-out.slang.expected
+++ b/tests/diagnostics/uninitialized-out.slang.expected
@@ -1,8 +1,20 @@
result code = -1
standard error = {
-tests/diagnostics/uninitialized-out.slang(5): error 41015: use of uninitialized value.
+tests/diagnostics/uninitialized-out.slang(6): error 41015: use of uninitialized value 'v'
float r = v.x + 1.0;
^
+tests/diagnostics/uninitialized-out.slang(8): warning 41016: returning without initializing out parameter 'v'
+ return r;
+ ^~~~~~
+tests/diagnostics/uninitialized-out.slang(14): warning 41016: returning without initializing out parameter 'x'
+ return 0;
+ ^~~~~~
+tests/diagnostics/uninitialized-out.slang(18): warning 41016: returning without initializing out parameter 'x'
+void baz(out float x) {}
+ ^
+tests/diagnostics/uninitialized-out.slang(25): warning 41016: returning without initializing out parameter 'y'
+ return;
+ ^~~~~~
}
standard output = {
}