diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-05-18 17:01:45 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-05-20 02:47:20 -0700 |
| commit | cd04b49041200b36c5af23ac3700cbfa82f037ca (patch) | |
| tree | 415600adaea3553fd3bf3020958812672f6aa97c /src/AstGen.zig | |
| parent | 5626bb45d24cd4a57a4f6a1c0f41ec0feb276f7b (diff) | |
| download | zig-cd04b49041200b36c5af23ac3700cbfa82f037ca.tar.gz zig-cd04b49041200b36c5af23ac3700cbfa82f037ca.zip | |
stage2: fix `@call` when used in a comptime or nosuspend block
`@call` allows specifying the modifier explicitly, however it can still
appear in a context that overrides the modifier. This commit adds flags
to the BuiltinCall ZIR encoding. Since we have unused bits I also threw
in the ensure_result_used mechanism.
I also deleted a behavior test that was checking for bound function
behavior where I think stage2 behavior is correct and stage1 behavior
is incorrect.
Diffstat (limited to 'src/AstGen.zig')
| -rw-r--r-- | src/AstGen.zig | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index 3e502625db..30ed680226 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -71,6 +71,7 @@ fn setExtra(astgen: *AstGen, index: usize, extra: anytype) void { Zir.Inst.Ref => @enumToInt(@field(extra, field.name)), i32 => @bitCast(u32, @field(extra, field.name)), Zir.Inst.Call.Flags => @bitCast(u32, @field(extra, field.name)), + Zir.Inst.BuiltinCall.Flags => @bitCast(u32, @field(extra, field.name)), Zir.Inst.SwitchBlock.Bits => @bitCast(u32, @field(extra, field.name)), Zir.Inst.ExtendedFunc.Bits => @bitCast(u32, @field(extra, field.name)), else => @compileError("bad field type"), @@ -2213,6 +2214,14 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner slot.* = @bitCast(u32, flags); break :b true; }, + .builtin_call => { + const extra_index = gz.astgen.instructions.items(.data)[inst].pl_node.payload_index; + const slot = &gz.astgen.extra.items[extra_index]; + var flags = @bitCast(Zir.Inst.BuiltinCall.Flags, slot.*); + flags.ensure_result_used = true; + slot.* = @bitCast(u32, flags); + break :b true; + }, // ZIR instructions that might be a type other than `noreturn` or `void`. .add, @@ -2412,7 +2421,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner .atomic_load, .atomic_rmw, .mul_add, - .builtin_call, .field_parent_ptr, .maximum, .minimum, @@ -7502,6 +7510,11 @@ fn builtinCall( .options = options, .callee = callee, .args = args, + .flags = .{ + .is_nosuspend = gz.nosuspend_node != 0, + .is_comptime = gz.force_comptime, + .ensure_result_used = false, + }, }); return rvalue(gz, rl, result, node); }, |
