Skip to content

Commit d9b6d1e

Browse files
jacobly0mlugg
authored andcommitted
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.
1 parent 4c4dacf commit d9b6d1e

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

src/arch/riscv64/CodeGen.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const Instruction = encoding.Instruction;
5151

5252
const InnerError = CodeGenError || error{OutOfRegisters};
5353

54-
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
54+
pub 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const libcFloatSuffix = target_util.libcFloatSuffix;
3131
const compilerRtFloatAbbrev = target_util.compilerRtFloatAbbrev;
3232
const compilerRtIntAbbrev = target_util.compilerRtIntAbbrev;
3333

34-
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
34+
pub 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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const assert = std.debug.assert;
44
const mem = std.mem;
55
const log = std.log.scoped(.c);
66

7+
const dev = @import("../dev.zig");
78
const link = @import("../link.zig");
89
const Zcu = @import("../Zcu.zig");
910
const Module = @import("../Package/Module.zig");
@@ -21,7 +22,12 @@ const BigIntLimb = std.math.big.Limb;
2122
const BigInt = std.math.big.int;
2223

2324
pub 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

2733
pub const CType = @import("c/Type.zig");

src/codegen/spirv.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const SpvAssembler = @import("spirv/Assembler.zig");
2828

2929
const InstMap = std.AutoHashMapUnmanaged(Air.Inst.Index, IdRef);
3030

31-
pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
31+
pub fn legalizeFeatures(_: *const std.Target) *const Air.Legalize.Features {
3232
return comptime &.initMany(&.{
3333
.expand_intcast_safe,
3434
.expand_add_safe,

src/dev.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
pub 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

0 commit comments

Comments
 (0)