authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-13 13:50:35+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-13 13:52:01+02:00
logbaeff1762b90fc9a4cd4b1d6a7db6ba43fd35356
treeb1f266f37800eb8bcfe71143a819250a0b736b8a
parentaaac8eae683172546ce9e018d8c419f62793f8d4

stage2,x64: recursively mark decls as alive when lowering


1 files changed, 25 insertions(+), 14 deletions(-)

src/arch/x86_64/CodeGen.zig+25-14
......@@ -3903,17 +3903,17 @@ fn airDbgVar(self: *Self, inst: Air.Inst.Index) !void {
39033903 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
39043904 const operand = pl_op.operand;
39053905 const ty = self.air.typeOf(operand);
3906 const mcv = try self.resolveInst(operand);
39063907
3907 if (!self.liveness.operandDies(inst, 0)) {
3908 const mcv = try self.resolveInst(operand);
3909 const name = self.air.nullTerminatedString(pl_op.payload);
3908 log.debug("airDbgVar: %{d}: {}, {}", .{ inst, ty.fmtDebug(), mcv });
39103909
3911 const tag = self.air.instructions.items(.tag)[inst];
3912 switch (tag) {
3913 .dbg_var_ptr => try self.genVarDbgInfo(ty.childType(), mcv, name),
3914 .dbg_var_val => try self.genVarDbgInfo(ty, mcv, name),
3915 else => unreachable,
3916 }
3910 const name = self.air.nullTerminatedString(pl_op.payload);
3911
3912 const tag = self.air.instructions.items(.tag)[inst];
3913 switch (tag) {
3914 .dbg_var_ptr => try self.genVarDbgInfo(ty.childType(), mcv, name),
3915 .dbg_var_val => try self.genVarDbgInfo(ty, mcv, name),
3916 else => unreachable,
39173917 }
39183918
39193919 return self.finishAir(inst, .dead, .{ operand, .none, .none });
......@@ -6089,6 +6089,7 @@ fn limitImmediateType(self: *Self, operand: Air.Inst.Ref, comptime T: type) !MCV
60896089}
60906090
60916091fn lowerDeclRef(self: *Self, tv: TypedValue, decl: *Module.Decl) InnerError!MCValue {
6092 log.debug("lowerDeclRef: ty = {}, val = {}", .{ tv.ty.fmtDebug(), tv.val.fmtDebug() });
60926093 const ptr_bits = self.target.cpu.arch.ptrBitWidth();
60936094 const ptr_bytes: u64 = @divExact(ptr_bits, 8);
60946095
......@@ -6100,7 +6101,8 @@ fn lowerDeclRef(self: *Self, tv: TypedValue, decl: *Module.Decl) InnerError!MCVa
61006101 }
61016102 }
61026103
6103 decl.alive = true;
6104 decl.markAlive();
6105
61046106 if (self.bin_file.cast(link.File.Elf)) |elf_file| {
61056107 const got = &elf_file.program_headers.items[elf_file.phdr_got_index.?];
61066108 const got_addr = got.p_vaddr + decl.link.elf.offset_table_index * ptr_bytes;
......@@ -6120,8 +6122,6 @@ fn lowerDeclRef(self: *Self, tv: TypedValue, decl: *Module.Decl) InnerError!MCVa
61206122 } else {
61216123 return self.fail("TODO codegen non-ELF const Decl pointer", .{});
61226124 }
6123
6124 _ = tv;
61256125}
61266126
61276127fn lowerUnnamedConst(self: *Self, tv: TypedValue) InnerError!MCValue {
......@@ -6144,6 +6144,7 @@ fn lowerUnnamedConst(self: *Self, tv: TypedValue) InnerError!MCValue {
61446144}
61456145
61466146fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
6147 log.debug("genTypedValue: ty = {}, val = {}", .{ typed_value.ty.fmtDebug(), typed_value.val.fmtDebug() });
61476148 if (typed_value.val.isUndef())
61486149 return MCValue{ .undef = {} };
61496150 const ptr_bits = self.target.cpu.arch.ptrBitWidth();
......@@ -6181,8 +6182,6 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
61816182 .Bool => {
61826183 return MCValue{ .immediate = @boolToInt(typed_value.val.toBool()) };
61836184 },
6184 .ComptimeInt => unreachable, // semantic analysis prevents this
6185 .ComptimeFloat => unreachable, // semantic analysis prevents this
61866185 .Optional => {
61876186 if (typed_value.ty.isPtrLikeOptional()) {
61886187 if (typed_value.val.isNull())
......@@ -6243,6 +6242,18 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
62436242 }
62446243 }
62456244 },
6245
6246 .ComptimeInt => unreachable,
6247 .ComptimeFloat => unreachable,
6248 .Type => unreachable,
6249 .EnumLiteral => unreachable,
6250 .Void => unreachable,
6251 .NoReturn => unreachable,
6252 .Undefined => unreachable,
6253 .Null => unreachable,
6254 .BoundFn => unreachable,
6255 .Opaque => unreachable,
6256
62466257 else => {},
62476258 }
62486259