diff options
| author | venkataram-nv <vedavamadath@nvidia.com> | 2024-07-16 14:54:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-16 14:54:53 -0700 |
| commit | 05547e25353dd797791c2937679468d529d832d5 (patch) | |
| tree | bc53e95b7b9e69474b83da3e5947712665c4664a /tests/diagnostics | |
| parent | b5174b473ffb41e92b4efc844f60d7239f3322a3 (diff) | |
Warnings function parameters (#4626)
* Handle out/inout functions with separate consideration
* Fixing bug with passing aliasable instructions
* Handle autodiff functions (fwd and rev) in warning system
* Handling interface methods
* Handling ref parameters like out/inout
* Temporary fix to remaining bugs
* Refactoring methods and tests
* Recursive check for empty structs
* Using default initializable interface in tests
* Resolving CI fail
Diffstat (limited to 'tests/diagnostics')
| -rw-r--r-- | tests/diagnostics/interfaces/anyvalue-size-validation.slang | 4 | ||||
| -rw-r--r-- | tests/diagnostics/uninitialized-globals.slang | 48 | ||||
| -rw-r--r-- | tests/diagnostics/uninitialized-local-variables.slang (renamed from tests/diagnostics/uninitialized.slang) | 112 | ||||
| -rw-r--r-- | tests/diagnostics/uninitialized-out-parameters.slang | 51 | ||||
| -rw-r--r-- | tests/diagnostics/uninitialized-out.slang.expected | 20 | ||||
| -rw-r--r-- | tests/diagnostics/uninitialized-use-functions.slang | 113 |
6 files changed, 214 insertions, 134 deletions
diff --git a/tests/diagnostics/interfaces/anyvalue-size-validation.slang b/tests/diagnostics/interfaces/anyvalue-size-validation.slang index 1ebf7f4c3..f2ed52d0c 100644 --- a/tests/diagnostics/interfaces/anyvalue-size-validation.slang +++ b/tests/diagnostics/interfaces/anyvalue-size-validation.slang @@ -26,6 +26,6 @@ RWStructuredBuffer<uint> output; [numthreads(4, 1, 1)] void main() { - S s; + S s = S(); output[0] = test(s).a; -}
\ No newline at end of file +} diff --git a/tests/diagnostics/uninitialized-globals.slang b/tests/diagnostics/uninitialized-globals.slang new file mode 100644 index 000000000..314881a80 --- /dev/null +++ b/tests/diagnostics/uninitialized-globals.slang @@ -0,0 +1,48 @@ +//TEST:SIMPLE(filecheck=CHK): -target spirv + +// Using groupshared variables +groupshared float4 gsConstexpr = float4(1.0f); +groupshared float4 gsUndefined; + +// OK +float use_constexpr_initialized_gs() +{ + return gsConstexpr.x; +} + +float use_undefined_gs() +{ + //CHK-DAG: warning 41017: use of uninitialized global variable 'gsUndefined' + return gsUndefined.x; +} + +// Using static variables +static const float cexprInitialized = 1.0f; +static float writtenNever; +static float writtenLater; + +// OK +float use_initialized_static() +{ + return cexprInitialized; +} + +// Should detect this and treat it as a store +void write_to_later() +{ + writtenLater = 1.0f; +} + +float use_never_written() +{ + //CHK-DAG: warning 41017: use of uninitialized global variable 'writtenNever' + return writtenNever; +} + +// OK because of prior store +float use_later_writte() +{ + return writtenLater; +} + +//CHK-NOT: warning 41017 diff --git a/tests/diagnostics/uninitialized.slang b/tests/diagnostics/uninitialized-local-variables.slang index 4779f45c9..5a2119f53 100644 --- a/tests/diagnostics/uninitialized.slang +++ b/tests/diagnostics/uninitialized-local-variables.slang @@ -1,14 +1,5 @@ //TEST:SIMPLE(filecheck=CHK): -target spirv -// TODO: -// * warn potentially uninitialized variables (control flow) -// * warn partially uninitialized variables (structs, arrays, etc.) -// * warn uninitialized fields in constructors - -/////////////////////////////////// -// Uninitialized local variables // -/////////////////////////////////// - // Should not warn here (unconditionalBranch) float3 unconditional(int mode) { @@ -157,107 +148,4 @@ float structs() return result; } -//////////////////////////////////// -// Uninitialized global variables // -//////////////////////////////////// - -// Using groupshared variables -groupshared float4 gsConstexpr = float4(1.0f); -groupshared float4 gsUndefined; - -// OK -float use_constexpr_initialized_gs() -{ - return gsConstexpr.x; -} - -float use_undefined_gs() -{ - //CHK-DAG: warning 41017: use of uninitialized global variable 'gsUndefined' - return gsUndefined.x; -} - -// Using static variables -static const float cexprInitialized = 1.0f; -static float writtenNever; -static float writtenLater; - -// OK -float use_initialized_static() -{ - return cexprInitialized; -} - -// Should detect this and treat it as a store -void write_to_later() -{ - writtenLater = 1.0f; -} - -float use_never_written() -{ - //CHK-DAG: warning 41017: use of uninitialized global variable 'writtenNever' - return writtenNever; -} - -// OK because of prior store -float use_later_writte() -{ - return writtenLater; -} - -////////////////////////////////// -// Uninitialized out parameters // -////////////////////////////////// - -// Using before assigning -float regular_undefined_use(out float3 v) -{ - //CHK-DAG: warning 41015: use of uninitialized out parameter 'v' - float r = v.x + 1.0; - - //CHK-DAG: warning 41018: returning without initializing out parameter 'v' - return r; -} - -// Returning before assigning -float returning_undefined_use(out float x) -{ - //CHK-DAG: warning 41018: returning without initializing out parameter 'x' - return 0; -} - -// Implicit, still returning before assigning -void implicit_undefined_use(out float x) -{ - //CHK-DAG: warning 41018: returning without initializing out parameter 'x' -} - -// Warn on potential return paths -void control_flow_undefined(bool b, out float y) -{ - if(b) - { - //CHK-DAG: warning 41018: returning without initializing out parameter 'y' - return; - } - y = 0; - return; -} - -// No warnings if all paths are fine -void control_flow_defined(bool b, out float y) -{ - if(b) - { - unused(y); - return; - } - y = 0; - return; -} - -//CHK-NOT: warning 41015 //CHK-NOT: warning 41016 -//CHK-NOT: warning 41017 -//CHK-NOT: warning 41018 diff --git a/tests/diagnostics/uninitialized-out-parameters.slang b/tests/diagnostics/uninitialized-out-parameters.slang new file mode 100644 index 000000000..9714a4b76 --- /dev/null +++ b/tests/diagnostics/uninitialized-out-parameters.slang @@ -0,0 +1,51 @@ +//TEST:SIMPLE(filecheck=CHK): -target spirv + +// Using before assigning +float regular_undefined_use(out float3 v) +{ + //CHK-DAG: warning 41015: use of uninitialized out parameter 'v' + float r = v.x + 1.0; + + //CHK-DAG: warning 41018: returning without initializing out parameter 'v' + return r; +} + +// Returning before assigning +float returning_undefined_use(out float x) +{ + //CHK-DAG: warning 41018: returning without initializing out parameter 'x' + return 0; +} + +// Implicit, still returning before assigning +void implicit_undefined_use(out float x) +{ + //CHK-DAG: warning 41018: returning without initializing out parameter 'x' +} + +// Warn on potential return paths +void control_flow_undefined(bool b, out float y) +{ + if(b) + { + //CHK-DAG: warning 41018: returning without initializing out parameter 'y' + return; + } + y = 0; + return; +} + +// No warnings if all paths are fine +void control_flow_defined(bool b, out float y) +{ + if(b) + { + unused(y); + return; + } + y = 0; + return; +} + +//CHK-NOT: warning 41015 +//CHK-NOT: warning 41018 diff --git a/tests/diagnostics/uninitialized-out.slang.expected b/tests/diagnostics/uninitialized-out.slang.expected deleted file mode 100644 index 5846c12df..000000000 --- a/tests/diagnostics/uninitialized-out.slang.expected +++ /dev/null @@ -1,20 +0,0 @@ -result code = -1 -standard error = { -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 = { -} diff --git a/tests/diagnostics/uninitialized-use-functions.slang b/tests/diagnostics/uninitialized-use-functions.slang new file mode 100644 index 000000000..82e7a04a8 --- /dev/null +++ b/tests/diagnostics/uninitialized-use-functions.slang @@ -0,0 +1,113 @@ +//TEST:SIMPLE(filecheck=CHK): -target spirv + +// Both out and inout parameters +// should have this treated as writes +void out_test(int tmp, out int x) +{ + x = tmp; +} + +// Permuting arguments to ensure that +// the correct argument is checked +void inout_test(inout int x, int tmp) +{ + x = tmp; +} + +// __ref parameters should also be fine +void ref_test(__ref int x, int tmp) +{ + x = tmp; +} + +void undefined_function_use() +{ + int x; + int tmp = 1; + + //CHK-DAG: warning 41016: use of uninitialized variable 'x' + out_test(x, tmp); + + //CHK-DAG: warning 41016: use of uninitialized variable 'x' + inout_test(tmp, x); +} + +void out_function_use() +{ + int x; + int tmp = 1; + + // Acts as a write + out_test(tmp, x); + + // Rest are fine now + out_test(x, tmp); + inout_test(tmp, x); +} + +void inout_function_use() +{ + int x; + int tmp = 1; + + // Acts as a write + inout_test(x, tmp); + + // Rest are fine now + out_test(x, tmp); + inout_test(tmp, x); +} + +void ref_function_use() +{ + int x; + int tmp = 1; + + // Acts as a write + ref_test(x, tmp); + + // Rest are fine now + out_test(x, tmp); + inout_test(tmp, x); +} + +// Likewise for generic functions +static int ord_gen_result; + +__generic<T> +void ordinary_generic(T x) +{ + ord_gen_result = __slang_noop_cast<int, T>(x); +} + +__generic<T> +void unordinary_generic(out T x) +{ + x = __slang_noop_cast<T, int>(1); +} + +void undefined_generic_use() +{ + int x; + + //CHK-DAG: warning 41016: use of uninitialized variable 'x' + ordinary_generic(x); +} + +void ok_generic_use() +{ + int x; + unordinary_generic(x); + ordinary_generic(x); +} + +// Check proper handling of aliases passed +void f() +{ + int3 dim; + + // Should have no warnings + out_test(1, dim.x); +} + +//CHK-NOT: warning 41016 |
