From afb8146e10626887e3eb9f479480d4f8a1ad6128 Mon Sep 17 00:00:00 2001 From: Gangzheng Tong Date: Tue, 16 Sep 2025 12:51:43 -0700 Subject: Diagnose error when the function args can't satisfy constexpr parameter requirements (#7269) ## Summary This PR enhances constexpr validation by adding proper error checking when function arguments cannot satisfy constexpr parameter requirements, addressing issue #6370. ## Problem Previously, when a function declared constexpr parameters, the compiler would attempt to propagate constexpr-ness to the call site arguments, but there was insufficient validation and error reporting when this propagation failed. This could lead silent failures where constexpr requirements weren't properly enforced ## Solution This PR adds checks that: 1. **Validates constexpr arguments**: When a function parameter is marked as `constexpr`, the compiler now explicitly checks that the corresponding argument can be marked as `constexpr` 2. **Issues clear compilation errors**: added `Diagnostics::argIsNotConstexpr`) 3. **Handles both call scenarios**: The validation works for both: - Direct function calls with IR-level function definitions - Calls to function from external modules Fixes #6370 --------- Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- tests/diagnostics/constexpr-error.slang | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests/diagnostics/constexpr-error.slang') diff --git a/tests/diagnostics/constexpr-error.slang b/tests/diagnostics/constexpr-error.slang index 0a4744b71..a79c71847 100644 --- a/tests/diagnostics/constexpr-error.slang +++ b/tests/diagnostics/constexpr-error.slang @@ -24,7 +24,7 @@ float4 main() : SV_Target result += t.Sample(s, uv, int2(0,0)); // Error: data passed through cbuffer isn't compile-time constant - // CHECK: ([[# @LINE+1]]): error 40006: + // CHECK: ([[# @LINE+1]]): error 40012: result += t.Sample(s, uv, offset); // Error: data computed via conditional isn't compile-time cosntant @@ -33,16 +33,19 @@ float4 main() : SV_Target { ii = 1; } - // CHECK: ([[# @LINE+1]]): error 40006: + // CHECK: ([[# @LINE+1]]): error 40012: result += t.Sample(s, uv, int2(ii)); // Error: data computed in loop isn't compile-time constant // (and loop isn't unroll-able) - // CHECK: ([[# @LINE+1]]): error 40006: + // CHECK: ([[# @LINE+1]]): error 40012: for(uint jj = 0; jj < uv.y; jj++) { result += t.Sample(s, uv, int2(jj)); } + + + return result; } \ No newline at end of file -- cgit v1.2.3