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