authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-05-30 14:38:46-04:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-06-01 08:24:00+01:00
logd9b6d1ed33d18eb13fa2cb39da3e7a381742975b
treeafdfcb8ec66c779f9afc064f27befa3ce8036c63
parent4c4dacf81a5da85a1f7d1550ed45f5cb20fd1524
signaturelock-open Commit is signed but in an unrecognized format.

cbe: legalize safety instructions in non-zig1 builds

This is valid if the bootstrap dev env doesn't need to support runtime safety. Another solution can always be implemented if needs change.

5 files changed, 13 insertions(+), 4 deletions(-)

src/arch/riscv64/CodeGen.zig+1-1
......@@ -51,7 +51,7 @@ const Instruction = encoding.Instruction;
5151
5252const InnerError = CodeGenError || error{OutOfRegisters};
5353
54pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
54pub fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
5555 return comptime &.initMany(&.{
5656 .expand_intcast_safe,
5757 .expand_add_safe,
src/arch/wasm/CodeGen.zig+1-1
......@@ -31,7 +31,7 @@ const libcFloatSuffix = target_util.libcFloatSuffix;
3131const compilerRtFloatAbbrev = target_util.compilerRtFloatAbbrev;
3232const compilerRtIntAbbrev = target_util.compilerRtIntAbbrev;
3333
34pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
34pub fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
3535 return comptime &.initMany(&.{
3636 .expand_intcast_safe,
3737 .expand_add_safe,
src/codegen/c.zig+7-1
......@@ -4,6 +4,7 @@ const assert = std.debug.assert;
44const mem = std.mem;
55const log = std.log.scoped(.c);
66
7const dev = @import("../dev.zig");
78const link = @import("../link.zig");
89const Zcu = @import("../Zcu.zig");
910const Module = @import("../Package/Module.zig");
......@@ -21,7 +22,12 @@ const BigIntLimb = std.math.big.Limb;
2122const BigInt = std.math.big.int;
2223
2324pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
24 return null;
25 return if (dev.env.supports(.legalize)) comptime &.initMany(&.{
26 .expand_intcast_safe,
27 .expand_add_safe,
28 .expand_sub_safe,
29 .expand_mul_safe,
30 }) else null; // we don't currently ask zig1 to use safe optimization modes
2531}
2632
2733pub const CType = @import("c/Type.zig");
src/codegen/spirv.zig+1-1
......@@ -28,7 +28,7 @@ const SpvAssembler = @import("spirv/Assembler.zig");
2828
2929const InstMap = std.AutoHashMapUnmanaged(Air.Inst.Index, IdRef);
3030
31pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
31pub fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
3232 return comptime &.initMany(&.{
3333 .expand_intcast_safe,
3434 .expand_add_safe,
src/dev.zig+3
......@@ -1,5 +1,8 @@
11pub const Env = enum {
22 /// zig1 features
3 /// - `-ofmt=c` only
4 /// - `-OReleaseFast` or `-OReleaseSmall` only
5 /// - no `@setRuntimeSafety(true)`
36 bootstrap,
47
58 /// zig2 features