From 21a66267c661a55c8ad27248c0765276dd6f72ea Mon Sep 17 00:00:00 2001 From: Gangzheng Tong Date: Tue, 15 Jul 2025 16:39:22 -0700 Subject: Emit additional diagnostic for invalid pointer taking operations (#7663) * Emit special diagnostic for invalid pointer taking operations * Update source/slang/slang-diagnostic-defs.h Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> * Add OperatorAddressOf KnownBuiltin modifier * update error message for non-l-value assignment * update the diagnostics in the tests * Use enum based KnownBuiltinDeclName * format code (#7772) Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --------- Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- .../invalid-constant-pointer-taking.slang | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/diagnostics/invalid-constant-pointer-taking.slang (limited to 'tests/diagnostics/invalid-constant-pointer-taking.slang') diff --git a/tests/diagnostics/invalid-constant-pointer-taking.slang b/tests/diagnostics/invalid-constant-pointer-taking.slang new file mode 100644 index 000000000..349f8cc25 --- /dev/null +++ b/tests/diagnostics/invalid-constant-pointer-taking.slang @@ -0,0 +1,23 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target spirv + +RWStructuredBuffer mutable_float_buffer; +RWStructuredBuffer mutable_uint_buffer; + +StructuredBuffer constant_float_buffer; +StructuredBuffer constant_uint_buffer; + +[shader("compute")] +[numthreads(1,1,1)] +void computeMain(uint3 threadId : SV_DispatchThreadID) +{ + float* mutablePtr = &mutable_float_buffer[threadId.x]; + + InterlockedAdd(mutable_uint_buffer[threadId.x], 1); + + // Constant pointers arent a thing in slang + // CHECK: error 30078: + float* ptr = &constant_float_buffer[threadId.x]; + + + InterlockedAdd(constant_uint_buffer[0], 1); +} \ No newline at end of file -- cgit v1.2.3