Files
wgpu/naga/tests/out/msl/empty-global-name.msl
T
Jamie Nicol 1f939e1c44 [naga msl-out] Avoid undefined behaviour due to signed integer overflow (#6959)
Signed integer overflow is undefined behaviour in MSL. However, signed
integers are defined to be two's complement. This allows us to cast
signed values to their corresponding unsigned type, perform the
arithmetic on these unsigned values (which has defined overflow
behaviour) then cast the result back to signed.

Care must be taken when emitting the isign polyfill, which uses
metal::select(). We must ensure the -1, 0, and 1 literals used as
inputs to select() have the correct width, else bitcasting the output
of select() will fail due to mismatched widths.
2025-01-20 18:11:27 +01:00

24 lines
380 B
Plaintext

// language: metal1.0
#include <metal_stdlib>
#include <simd/simd.h>
using metal::uint;
struct type_1 {
int member;
};
void function(
device type_1& unnamed
) {
int _e3 = unnamed.member;
unnamed.member = as_type<int>(as_type<uint>(_e3) + as_type<uint>(1));
return;
}
kernel void main_(
device type_1& unnamed [[user(fake0)]]
) {
function(unnamed);
}