aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-30 23:16:32 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-30 23:19:10 -0700
commitcf4aad4858ac61b4814d8f021c8eae22ee7f63e6 (patch)
tree24b38ed2af8bc40ffa056b5deb3d932916d8c770 /src/AstGen.zig
parent08565b23f94655e3b2610187f71ba774ce89eeb8 (diff)
downloadzig-cf4aad4858ac61b4814d8f021c8eae22ee7f63e6.tar.gz
zig-cf4aad4858ac61b4814d8f021c8eae22ee7f63e6.zip
AstGen: fix referencing unreferencable instructions
Sema avoids adding map entries for certain instructions such as `set_eval_branch_quota` and `atomic_store`. This means that result location semantics in AstGen must not emit any instructions that attempt to use the result of any of these instructions. This commit makes AstGen replace such instructions with `Zir.Inst.Ref.void_value` if their result value ends up being referenced. This fixes a compiler crash when running std lib atomic tests.
Diffstat (limited to 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 0fe64ec36b..0d52a1a2bc 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -8924,9 +8924,18 @@ fn nodeImpliesComptimeOnly(tree: *const Ast, start_node: Ast.Node.Index) bool {
fn rvalue(
gz: *GenZir,
rl: ResultLoc,
- result: Zir.Inst.Ref,
+ raw_result: Zir.Inst.Ref,
src_node: Ast.Node.Index,
) InnerError!Zir.Inst.Ref {
+ const result = r: {
+ if (refToIndex(raw_result)) |result_index| {
+ const zir_tags = gz.astgen.instructions.items(.tag);
+ if (zir_tags[result_index].isAlwaysVoid()) {
+ break :r Zir.Inst.Ref.void_value;
+ }
+ }
+ break :r raw_result;
+ };
if (gz.endsWithNoReturn()) return result;
switch (rl) {
.none, .coerced_ty => return result,