From b01d6b156cf4d273be40a6e6288f4766f71f4a29 Mon Sep 17 00:00:00 2001 From: mlugg Date: Wed, 29 Jan 2025 18:45:08 +0000 Subject: 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 --- src/codegen/c.zig | 1 + 1 file changed, 1 insertion(+) (limited to 'src/codegen/c.zig') 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", .{}), -- cgit v1.2.3