| ... | ... | @@ -8934,9 +8934,7 @@ fn zirEnumFromInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8934 | 8934 | |
| 8935 | 8935 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 8936 | 8936 | if (block.wantSafety()) { |
| 8937 | | if (zcu.backendSupportsFeature(.panic_fn)) { |
| 8938 | | _ = try sema.preparePanicId(src, .invalid_enum_value); |
| 8939 | | } |
| 8937 | try sema.preparePanicId(src, .invalid_enum_value); |
| 8940 | 8938 | return block.addTyOp(.intcast_safe, dest_ty, operand); |
| 8941 | 8939 | } |
| 8942 | 8940 | return block.addTyOp(.intcast, dest_ty, operand); |
| ... | ... | @@ -10340,9 +10338,7 @@ fn intCast( |
| 10340 | 10338 | |
| 10341 | 10339 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 10342 | 10340 | if (block.wantSafety()) { |
| 10343 | | if (zcu.backendSupportsFeature(.panic_fn)) { |
| 10344 | | _ = try sema.preparePanicId(src, .integer_out_of_bounds); |
| 10345 | | } |
| 10341 | try sema.preparePanicId(src, .integer_out_of_bounds); |
| 10346 | 10342 | return block.addTyOp(.intcast_safe, dest_ty, operand); |
| 10347 | 10343 | } |
| 10348 | 10344 | return block.addTyOp(.intcast, dest_ty, operand); |
| ... | ... | @@ -16395,9 +16391,7 @@ fn analyzeArithmetic( |
| 16395 | 16391 | } |
| 16396 | 16392 | |
| 16397 | 16393 | if (block.wantSafety() and want_safety and scalar_tag == .int) { |
| 16398 | | if (air_tag != air_tag_safe and zcu.backendSupportsFeature(.panic_fn)) { |
| 16399 | | _ = try sema.preparePanicId(src, .integer_overflow); |
| 16400 | | } |
| 16394 | if (air_tag != air_tag_safe) try sema.preparePanicId(src, .integer_overflow); |
| 16401 | 16395 | return block.addBinOp(air_tag_safe, casted_lhs, casted_rhs); |
| 16402 | 16396 | } |
| 16403 | 16397 | return block.addBinOp(air_tag, casted_lhs, casted_rhs); |
| ... | ... | @@ -22194,9 +22188,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro |
| 22194 | 22188 | } })); |
| 22195 | 22189 | } |
| 22196 | 22190 | if (block.wantSafety()) { |
| 22197 | | if (zcu.backendSupportsFeature(.panic_fn)) { |
| 22198 | | _ = try sema.preparePanicId(src, .integer_part_out_of_bounds); |
| 22199 | | } |
| 22191 | try sema.preparePanicId(src, .integer_part_out_of_bounds); |
| 22200 | 22192 | return block.addTyOp(switch (block.float_mode) { |
| 22201 | 22193 | .optimized => .int_from_float_optimized_safe, |
| 22202 | 22194 | .strict => .int_from_float_safe, |
| ... | ... | @@ -26861,7 +26853,15 @@ fn explainWhyTypeIsNotPacked( |
| 26861 | 26853 | /// Backends depend on panic decls being available when lowering safety-checked |
| 26862 | 26854 | /// instructions. This function ensures the panic function will be available to |
| 26863 | 26855 | /// be called during that time. |
| 26864 | | fn preparePanicId(sema: *Sema, src: LazySrcLoc, panic_id: Zcu.SimplePanicId) !InternPool.Index { |
| 26856 | fn preparePanicId(sema: *Sema, src: LazySrcLoc, panic_id: Zcu.SimplePanicId) !void { |
| 26857 | // If the backend doesn't support `.panic_fn`, it doesn't want us to lower the panic handlers. |
| 26858 | // The backend will transform panics into traps instead. |
| 26859 | if (sema.pt.zcu.backendSupportsFeature(.panic_fn)) { |
| 26860 | _ = try sema.getPanicIdFunc(src, panic_id); |
| 26861 | } |
| 26862 | } |
| 26863 | |
| 26864 | fn getPanicIdFunc(sema: *Sema, src: LazySrcLoc, panic_id: Zcu.SimplePanicId) !InternPool.Index { |
| 26865 | 26865 | const zcu = sema.pt.zcu; |
| 26866 | 26866 | try sema.ensureMemoizedStateResolved(src, .panic); |
| 26867 | 26867 | const panic_func = zcu.builtin_decl_values.get(panic_id.toBuiltin()); |
| ... | ... | @@ -27110,7 +27110,7 @@ fn safetyPanic(sema: *Sema, block: *Block, src: LazySrcLoc, panic_id: Zcu.Simple |
| 27110 | 27110 | if (!sema.pt.zcu.backendSupportsFeature(.panic_fn)) { |
| 27111 | 27111 | _ = try block.addNoOp(.trap); |
| 27112 | 27112 | } else { |
| 27113 | | const panic_fn = try sema.preparePanicId(src, panic_id); |
| 27113 | const panic_fn = try sema.getPanicIdFunc(src, panic_id); |
| 27114 | 27114 | try sema.callBuiltin(block, src, Air.internedToRef(panic_fn), .auto, &.{}, .@"safety check"); |
| 27115 | 27115 | } |
| 27116 | 27116 | } |