From 93a3ba812dd33b10f166f9172bd781e84d938e21 Mon Sep 17 00:00:00 2001 From: venkataram-nv Date: Wed, 31 Jul 2024 11:51:09 -0700 Subject: Warnings target switch intrinsic asm (#4727) * Proper warning generation for target switches and intrinsic asm * Relaxing terminators * Fix compiler warnings * Rectified target switch reachability check * Simplify target switch reachability check * Refactoring variable names * Using getBlocks * Moving ad hoc special case to diagnostics source * Using the LINE directive for testing * Simplifying reliance on target switches * Skipping IR generation for empty target switches --------- Co-authored-by: Yong He --- .../diagnostics/uninitialized-out-parameters.slang | 53 ++++++++++++++++++++-- 1 file changed, 48 insertions(+), 5 deletions(-) (limited to 'tests/diagnostics') diff --git a/tests/diagnostics/uninitialized-out-parameters.slang b/tests/diagnostics/uninitialized-out-parameters.slang index 9714a4b76..37cfbb3d4 100644 --- a/tests/diagnostics/uninitialized-out-parameters.slang +++ b/tests/diagnostics/uninitialized-out-parameters.slang @@ -3,24 +3,24 @@ // Using before assigning float regular_undefined_use(out float3 v) { - //CHK-DAG: warning 41015: use of uninitialized out parameter 'v' + //CHK-DAG: ([[# @LINE + 1]]): warning 41015: use of uninitialized out parameter 'v' float r = v.x + 1.0; - //CHK-DAG: warning 41018: returning without initializing out parameter 'v' + //CHK-DAG: ([[# @LINE + 1]]): 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' + //CHK-DAG: ([[# @LINE + 1]]): 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' + //CHK-DAG: ([[# @LINE + 1]]): warning 41018: returning without initializing out parameter 'x' } // Warn on potential return paths @@ -28,7 +28,7 @@ void control_flow_undefined(bool b, out float y) { if(b) { - //CHK-DAG: warning 41018: returning without initializing out parameter 'y' + //CHK-DAG: ([[# @LINE + 1]]): warning 41018: returning without initializing out parameter 'y' return; } y = 0; @@ -47,5 +47,48 @@ void control_flow_defined(bool b, out float y) return; } +// Specialized handling for intrinsic asm +void instrincs_defined(float x, out float exp) +{ + __intrinsic_asm "frexp"; +} + +// Specialized handling for target switches +void target_switching_undefined(float x, out float exp) +{ + //CHK-DAG: ([[# @LINE + 2]]): warning 41018: returning without initializing out parameter 'exp' + __target_switch {} +} + +void target_switching_defined(float x, out float exp) +{ + __target_switch + { + case glsl: __intrinsic_asm "frexp"; + } +} + +void target_switching_blocks(uint x, out half v) +{ + __target_switch + { + case hlsl: + if ((x & 2) == 0) + v = half(1); + else + v = half(1); + return; + case glsl: + case spirv: + { + if ((x & 2) == 0) + v = half(1); + else + v = half(1); + return; + } + } +} + //CHK-NOT: warning 41015 //CHK-NOT: warning 41018 -- cgit v1.2.3