# spirv: fix signed overflow detection for safe subtraction · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/ee6d19480da53b3a351749e2a7b18c45ad072018)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: ee6d19480da53b3a351749e2a7b18c45ad072018

Requested commit: ee6d19480da53b3a351749e2a7b18c45ad072018

Commit: ee6d19480da53b3a351749e2a7b18c45ad072018

Tree: 22309b2a5cb5f383d0892c2da8908876341fdb9d

Author: Ivan Stepanov

Committer: Alex Rønne Petersen

## Message

```
spirv: fix signed overflow detection for safe subtraction

The overflow check for safe signed subtraction was using the formula (rhs < 0) == (lhs > result). This logic is flawed and incorrectly reports an overflow when the right-hand side is zero.
For the expression 42 - 0, this check evaluated to (0 < 0) == (42 > 42), which is false == false, resulting in true. This caused the generated SPIR-V to incorrectly branch to an OpUnreachable instruction, preventing the result from being stored.

Fixes #24281.

```

## Parents

- [b8ac740a1b072168c24785cf8d1c8315ed6db8b0](https://git.cafe/gitcafe/zig/commit/b8ac740a1b072168c24785cf8d1c8315ed6db8b0?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/ee6d19480da53b3a351749e2a7b18c45ad072018?format=markdown)
