# compiler: add \`intcast_safe\` AIR instruction · gitcafe/zig

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

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

Visibility: public

Requested revision: b01d6b156cf4d273be40a6e6288f4766f71f4a29

Requested commit: b01d6b156cf4d273be40a6e6288f4766f71f4a29

Commit: b01d6b156cf4d273be40a6e6288f4766f71f4a29

Tree: 084bfcf9ad8dfbce7879f750383a3091f699f52f

Author: mlugg

Committer: Matthew Lugg

## Message

```
compiler: add `intcast_safe` AIR instruction

This instruction is like `intcast`, but includes two safety checks:

* Checks that the int is in range of the destination type
* If the destination type is an exhaustive enum, checks that the int
  is a named enum value

This instruction is locked behind the `safety_checked_instructions`
backend feature; if unsupported, Sema will emit a fallback, as with
other safety-checked instructions.

This instruction is used to add a missing safety check for `@enumFromInt`
truncating bits. This check also has a fallback for backends which do
not yet support `safety_checked_instructions`.

Resolves: #21946

```

## Parents

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

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