authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-05 21:31:16-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-05-05 21:31:16-07:00
log1e9811070be35463e5cf4dfd284d9313e0621ded
treea8c7969270a16c1dfa945cc168cc4fc533e7fa56
parent4bfd37ddb48af4dbfd2e892aec7a90a822c8cbe7
parentdf4849c4f5aafc7eb80fd7b2299b49162fa2aa79
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #15591 from jacobly0/undef-errdefer-capture

AstGen: fix branch on undefined

4 files changed, 16 insertions(+), 3 deletions(-)

src/AstGen.zig+9-1
...@@ -2905,7 +2905,15 @@ fn deferStmt(...@@ -2905,7 +2905,15 @@ fn deferStmt(
2905 const sub_scope = if (!have_err_code) &defer_gen.base else blk: {2905 const sub_scope = if (!have_err_code) &defer_gen.base else blk: {
2906 try gz.addDbgBlockBegin();2906 try gz.addDbgBlockBegin();
2907 const ident_name = try gz.astgen.identAsString(payload_token);2907 const ident_name = try gz.astgen.identAsString(payload_token);
2908 remapped_err_code = @intCast(u32, try gz.astgen.instructions.addOne(gz.astgen.gpa));2908 remapped_err_code = @intCast(Zir.Inst.Index, gz.astgen.instructions.len);
2909 try gz.astgen.instructions.append(gz.astgen.gpa, .{
2910 .tag = .extended,
2911 .data = .{ .extended = .{
2912 .opcode = .errdefer_err_code,
2913 .small = undefined,
2914 .operand = undefined,
2915 } },
2916 });
2909 const remapped_err_code_ref = Zir.indexToRef(remapped_err_code);2917 const remapped_err_code_ref = Zir.indexToRef(remapped_err_code);
2910 local_val_scope = .{2918 local_val_scope = .{
2911 .parent = &defer_gen.base,2919 .parent = &defer_gen.base,
src/Sema.zig+1
...@@ -1198,6 +1198,7 @@ fn analyzeBodyInner(...@@ -1198,6 +1198,7 @@ fn analyzeBodyInner(
1198 i += 1;1198 i += 1;
1199 continue;1199 continue;
1200 },1200 },
1201 .errdefer_err_code => unreachable, // never appears in a body
1201 };1202 };
1202 },1203 },
12031204
src/Zir.zig+5-2
...@@ -1979,7 +1979,7 @@ pub const Inst = struct {...@@ -1979,7 +1979,7 @@ pub const Inst = struct {
1979 /// `operand` is `src_node: i32`.1979 /// `operand` is `src_node: i32`.
1980 breakpoint,1980 breakpoint,
1981 /// Implements the `@select` builtin.1981 /// Implements the `@select` builtin.
1982 /// operand` is payload index to `Select`.1982 /// `operand` is payload index to `Select`.
1983 select,1983 select,
1984 /// Implement builtin `@errToInt`.1984 /// Implement builtin `@errToInt`.
1985 /// `operand` is payload index to `UnNode`.1985 /// `operand` is payload index to `UnNode`.
...@@ -1999,7 +1999,7 @@ pub const Inst = struct {...@@ -1999,7 +1999,7 @@ pub const Inst = struct {
1999 /// `operand` is payload index to `Cmpxchg`.1999 /// `operand` is payload index to `Cmpxchg`.
2000 cmpxchg,2000 cmpxchg,
2001 /// Implement the builtin `@addrSpaceCast`2001 /// Implement the builtin `@addrSpaceCast`
2002 /// `Operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand.2002 /// `operand` is payload index to `BinNode`. `lhs` is dest type, `rhs` is operand.
2003 addrspace_cast,2003 addrspace_cast,
2004 /// Implement builtin `@cVaArg`.2004 /// Implement builtin `@cVaArg`.
2005 /// `operand` is payload index to `BinNode`.2005 /// `operand` is payload index to `BinNode`.
...@@ -2031,6 +2031,9 @@ pub const Inst = struct {...@@ -2031,6 +2031,9 @@ pub const Inst = struct {
2031 /// Implements the `@inComptime` builtin.2031 /// Implements the `@inComptime` builtin.
2032 /// `operand` is `src_node: i32`.2032 /// `operand` is `src_node: i32`.
2033 in_comptime,2033 in_comptime,
2034 /// Used as a placeholder for the capture of an `errdefer`.
2035 /// This is replaced by Sema with the captured value.
2036 errdefer_err_code,
20342037
2035 pub const InstData = struct {2038 pub const InstData = struct {
2036 opcode: Extended,2039 opcode: Extended,
src/print_zir.zig+1
...@@ -467,6 +467,7 @@ const Writer = struct {...@@ -467,6 +467,7 @@ const Writer = struct {
467 .breakpoint,467 .breakpoint,
468 .c_va_start,468 .c_va_start,
469 .in_comptime,469 .in_comptime,
470 .errdefer_err_code,
470 => try self.writeExtNode(stream, extended),471 => try self.writeExtNode(stream, extended),
471472
472 .builtin_src => {473 .builtin_src => {