From 1677a25f44d6f608c8aecd4e5c0ceeb94573c10e Mon Sep 17 00:00:00 2001 From: venkataram-nv Date: Thu, 18 Jul 2024 11:13:26 -0700 Subject: Fix bug with uninititialized warnings in nested scopes (#4677) Previously the warning system ignores undefined variables in nested scopes (blocks in IR). --- .../uninitialized-local-variables.slang | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/diagnostics') diff --git a/tests/diagnostics/uninitialized-local-variables.slang b/tests/diagnostics/uninitialized-local-variables.slang index 5a2119f53..3c3dba881 100644 --- a/tests/diagnostics/uninitialized-local-variables.slang +++ b/tests/diagnostics/uninitialized-local-variables.slang @@ -148,4 +148,30 @@ float structs() return result; } +// Warnings even in nested scopes +float nested_scopes(int x, inout float p) +{ + if (x == 0) + { + float y; + //CHK-DAG: warning 41016: use of uninitialized variable 'y' + return y; + } + else if (x == 1) + { + float y; + //CHK-DAG: warning 41016: use of uninitialized variable 'y' + p = y + 1; + + if (x == 2) + { + float z; + //CHK-DAG: warning 41016: use of uninitialized variable 'z' + p += z; + } + } + + return 1.0; +} + //CHK-NOT: warning 41016 -- cgit v1.2.3