diff options
| author | Jacob G-W <jacoblevgw@gmail.com> | 2021-06-23 14:32:21 -0400 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2021-06-25 08:57:03 +0300 |
| commit | 2d2a6ed1a46349355650bfdd68688738c67bbf9c (patch) | |
| tree | 9f3b593da5ea52f083143cc3c536695d6e04f3d2 /src | |
| parent | 4adcd560ce4c742791cf1c1d34cdb16f805ffcfd (diff) | |
| download | zig-2d2a6ed1a46349355650bfdd68688738c67bbf9c.tar.gz zig-2d2a6ed1a46349355650bfdd68688738c67bbf9c.zip | |
stage2: implement @setRuntimeSafety
Diffstat (limited to 'src')
| -rw-r--r-- | src/Module.zig | 7 | ||||
| -rw-r--r-- | src/Sema.zig | 8 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/Module.zig b/src/Module.zig index e168f6aac7..439256f320 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1151,6 +1151,9 @@ pub const Scope = struct { is_comptime: bool, + /// when null, it is determined by build mode, changed by @setRuntimeSafety + want_safety: ?bool = null, + /// This `Block` maps a block ZIR instruction to the corresponding /// AIR instruction for break instruction analysis. pub const Label = struct { @@ -1195,12 +1198,12 @@ pub const Scope = struct { .runtime_cond = parent.runtime_cond, .runtime_loop = parent.runtime_loop, .runtime_index = parent.runtime_index, + .want_safety = parent.want_safety, }; } pub fn wantSafety(block: *const Block) bool { - // TODO take into account scope's safety overrides - return switch (block.sema.mod.optimizeMode()) { + return block.want_safety orelse switch (block.sema.mod.optimizeMode()) { .Debug => true, .ReleaseSafe => true, .ReleaseFast => false, diff --git a/src/Sema.zig b/src/Sema.zig index 1e1aadcc76..ea6f4898c5 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2040,8 +2040,12 @@ fn zirSetFloatMode(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Inner fn zirSetRuntimeSafety(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void { const inst_data = sema.code.instructions.items(.data)[inst].un_node; - const src: LazySrcLoc = inst_data.src(); - return sema.mod.fail(&block.base, src, "TODO: implement Sema.zirSetRuntimeSafety", .{}); + const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; + + const op = try sema.resolveInst(inst_data.operand); + const op_coerced = try sema.coerce(block, Type.initTag(.bool), op, operand_src); + const b = (try sema.resolveConstValue(block, operand_src, op_coerced)).toBool(); + block.want_safety = b; } fn zirBreakpoint(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError!void { |
