From 04353fb7602b7eb6a8b86193510ebe0c670b7724 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Wed, 22 Jan 2025 19:10:35 +0200 Subject: Add validation for destination of atomic operations (#6093) * Reimplement the GLSL atomic* functions in terms of __intrinsic_op Many of these functions map directly to atomic IR instructions. The functions taking atomic_uint are left as they are. This helps to address #5989, since the destination pointer type validation can then be written only for the atomic IR instructions. * Add validation for atomic operations Diagnose an error if the destination of the atomic operation is not appropriate, where appropriate means it's either: - 'groupshared' - from a device buffer This closes #5989. * Add tests for GLSL atomics destination validation Attempting to use the GLSL atomic functions on destinations that are neither groupshared nor from a device buffer should fail with the following error: error 41403: cannot perform atomic operation because destination is neither groupshared nor from a device buffer. * Validate atomic operations after address space specialization Address space specialization for SPIR-V is not done as part of `linkAndOptimizeIR`, as it is for e.g. Metal, so opt out and add a separate call for SPIR-V. * Allow unchecked in/inout parameters for non-SPIRV targets * Clean up callees left without uses during address space specialziation * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He --- tests/glsl-intrinsic/atomic/invalidDest.slang | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/glsl-intrinsic/atomic/invalidDest.slang (limited to 'tests') diff --git a/tests/glsl-intrinsic/atomic/invalidDest.slang b/tests/glsl-intrinsic/atomic/invalidDest.slang new file mode 100644 index 000000000..315321f88 --- /dev/null +++ b/tests/glsl-intrinsic/atomic/invalidDest.slang @@ -0,0 +1,25 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -allow-glsl -stage compute -entry computeMain -target glsl -DTARGET_GLSL +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -allow-glsl -stage compute -entry computeMain -target spirv -skip-spirv-validation -emit-spirv-directly -DTARGET_SPIRV +#version 430 + +uint notShared; + +void computeMain() +{ + // CHECK: ([[# @LINE+1]]): error 41403 + atomicAdd(notShared, 1u); + // CHECK: ([[# @LINE+1]]): error 41403 + atomicAnd(notShared, 1u); + // CHECK: ([[# @LINE+1]]): error 41403 + atomicCompSwap(notShared, 1u, 2u); + // CHECK: ([[# @LINE+1]]): error 41403 + atomicExchange(notShared, 1u); + // CHECK: ([[# @LINE+1]]): error 41403 + atomicMax(notShared, 1u); + // CHECK: ([[# @LINE+1]]): error 41403 + atomicMin(notShared, 1u); + // CHECK: ([[# @LINE+1]]): error 41403 + atomicOr(notShared, 1u); + // CHECK: ([[# @LINE+1]]): error 41403 + atomicXor(notShared, 1u); +} -- cgit v1.2.3