From da878dc0776b56c1e2c251857a40415a35e9535a Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Fri, 5 May 2023 14:56:10 -0400 Subject: [PATCH] AstGen: fix branch on undefined `isAlwaysVoid` was being called with the undefined tag added by `addOne`, causing non-deterministic behavior failures with release builds of the compiler. Prevents the following random failure: test/behavior/defer.zig:120:40: error: expected type 'error{One}', found 'void' --- src/AstGen.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/AstGen.zig b/src/AstGen.zig index 2568b89980..000151a2cc 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -2905,7 +2905,10 @@ fn deferStmt( const sub_scope = if (!have_err_code) &defer_gen.base else blk: { try gz.addDbgBlockBegin(); const ident_name = try gz.astgen.identAsString(payload_token); - remapped_err_code = @intCast(u32, try gz.astgen.instructions.addOne(gz.astgen.gpa)); + remapped_err_code = @intCast(Zir.Inst.Index, gz.astgen.instructions.len); + // Use a placeholder tag of .as to allow querying things that depend on the tag, + // but undefined data to prevent querying of data.bin. + try gz.astgen.instructions.append(gz.astgen.gpa, .{ .tag = .as, .data = undefined }); const remapped_err_code_ref = Zir.indexToRef(remapped_err_code); local_val_scope = .{ .parent = &defer_gen.base,