diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-01-29 18:45:08 +0000 |
|---|---|---|
| committer | Matthew Lugg <mlugg@mlugg.co.uk> | 2025-01-30 14:47:59 +0000 |
| commit | b01d6b156cf4d273be40a6e6288f4766f71f4a29 (patch) | |
| tree | 084bfcf9ad8dfbce7879f750383a3091f699f52f /src/codegen/c.zig | |
| parent | c5e34df555a98c51919eb45b0ab2a5ee3b37f4bf (diff) | |
| download | zig-b01d6b156cf4d273be40a6e6288f4766f71f4a29.tar.gz zig-b01d6b156cf4d273be40a6e6288f4766f71f4a29.zip | |
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
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 6244bd2324..241f215875 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -3436,6 +3436,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, .add_safe, .sub_safe, .mul_safe, + .intcast_safe, => return f.fail("TODO implement safety_checked_instructions", .{}), .is_named_enum_value => return f.fail("TODO: C backend: implement is_named_enum_value", .{}), |
