authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-03-22 08:44:46-04:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-04-28 01:14:24+01:00
log029cc0640f2feb1f90959f234101f4aafd275561
treee7cb2f29edb6f8027ed20109c3262f5d2af71485
parent95932e98e50f3762c3faf5ac3ee7c8f11f09096e
signaturelock-open Commit is signed but in an unrecognized format.

cbe: assignment is not initialization

Turns out the backend currently never emits a non-static initializer, but the handling is kept in case it is needed again in the future.

1 files changed, 20 insertions(+), 21 deletions(-)

src/codegen/c.zig+20-21
...@@ -611,7 +611,7 @@ pub const Function = struct {...@@ -611,7 +611,7 @@ pub const Function = struct {
611 const a = try Assignment.start(f, writer, ctype);611 const a = try Assignment.start(f, writer, ctype);
612 try f.writeCValue(writer, dst, .Other);612 try f.writeCValue(writer, dst, .Other);
613 try a.assign(f, writer);613 try a.assign(f, writer);
614 try f.writeCValue(writer, src, .Initializer);614 try f.writeCValue(writer, src, .Other);
615 try a.end(f, writer);615 try a.end(f, writer);
616 }616 }
617617
...@@ -2826,7 +2826,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn...@@ -2826,7 +2826,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
2826 });2826 });
2827 try o.dg.renderTypeAndName(w, name_ty, .{ .identifier = "name" }, Const, .none, .complete);2827 try o.dg.renderTypeAndName(w, name_ty, .{ .identifier = "name" }, Const, .none, .complete);
2828 try w.writeAll(" = ");2828 try w.writeAll(" = ");
2829 try o.dg.renderValue(w, Value.fromInterned(name_val), .Initializer);2829 try o.dg.renderValue(w, Value.fromInterned(name_val), .StaticInitializer);
2830 try w.writeAll(";\n return (");2830 try w.writeAll(";\n return (");
2831 try o.dg.renderType(w, name_slice_ty);2831 try o.dg.renderType(w, name_slice_ty);
2832 try w.print("){{{}, {}}};\n", .{2832 try w.print("){{{}, {}}};\n", .{
...@@ -4045,7 +4045,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -4045,7 +4045,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
4045 const new_local = try f.allocLocal(inst, src_ty);4045 const new_local = try f.allocLocal(inst, src_ty);
4046 try f.writeCValue(writer, new_local, .Other);4046 try f.writeCValue(writer, new_local, .Other);
4047 try writer.writeAll(" = ");4047 try writer.writeAll(" = ");
4048 try f.writeCValue(writer, src_val, .Initializer);4048 try f.writeCValue(writer, src_val, .Other);
4049 try writer.writeAll(";\n");4049 try writer.writeAll(";\n");
40504050
4051 break :blk new_local;4051 break :blk new_local;
...@@ -4516,7 +4516,7 @@ fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -4516,7 +4516,7 @@ fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue {
4516 const a = try Assignment.start(f, writer, .usize);4516 const a = try Assignment.start(f, writer, .usize);
4517 try f.writeCValueMember(writer, local, .{ .identifier = "len" });4517 try f.writeCValueMember(writer, local, .{ .identifier = "len" });
4518 try a.assign(f, writer);4518 try a.assign(f, writer);
4519 try f.writeCValue(writer, len, .Initializer);4519 try f.writeCValue(writer, len, .Other);
4520 try a.end(f, writer);4520 try a.end(f, writer);
4521 }4521 }
4522 return local;4522 return local;
...@@ -4934,7 +4934,7 @@ fn airSwitchDispatch(f: *Function, inst: Air.Inst.Index) !void {...@@ -4934,7 +4934,7 @@ fn airSwitchDispatch(f: *Function, inst: Air.Inst.Index) !void {
4934 const cond_local = f.loop_switch_conds.get(br.block_inst).?;4934 const cond_local = f.loop_switch_conds.get(br.block_inst).?;
4935 try f.writeCValue(writer, .{ .local = cond_local }, .Other);4935 try f.writeCValue(writer, .{ .local = cond_local }, .Other);
4936 try writer.writeAll(" = ");4936 try writer.writeAll(" = ");
4937 try f.writeCValue(writer, cond, .Initializer);4937 try f.writeCValue(writer, cond, .Other);
4938 try writer.writeAll(";\n");4938 try writer.writeAll(";\n");
4939 try writer.print("goto zig_switch_{d}_loop;", .{@intFromEnum(br.block_inst)});4939 try writer.print("goto zig_switch_{d}_loop;", .{@intFromEnum(br.block_inst)});
4940}4940}
...@@ -4979,14 +4979,13 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !CVal...@@ -4979,14 +4979,13 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !CVal
4979 const operand_lval = if (operand == .constant) blk: {4979 const operand_lval = if (operand == .constant) blk: {
4980 const operand_local = try f.allocLocal(null, operand_ty);4980 const operand_local = try f.allocLocal(null, operand_ty);
4981 try f.writeCValue(writer, operand_local, .Other);4981 try f.writeCValue(writer, operand_local, .Other);
4982 if (operand_ty.isAbiInt(zcu)) {4982 try writer.writeAll(" = ");
4983 try writer.writeAll(" = ");4983 if (!operand_ty.isAbiInt(zcu)) {
4984 } else {4984 try writer.writeByte('(');
4985 try writer.writeAll(" = (");
4986 try f.renderType(writer, operand_ty);4985 try f.renderType(writer, operand_ty);
4987 try writer.writeByte(')');4986 try writer.writeByte(')');
4988 }4987 }
4989 try f.writeCValue(writer, operand, .Initializer);4988 try f.writeCValue(writer, operand, .Other);
4990 try writer.writeAll(";\n");4989 try writer.writeAll(";\n");
4991 break :blk operand_local;4990 break :blk operand_local;
4992 } else operand;4991 } else operand;
...@@ -5698,7 +5697,7 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5698,7 +5697,7 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
5698 const a = try Assignment.start(f, writer, opt_ctype);5697 const a = try Assignment.start(f, writer, opt_ctype);
5699 try f.writeCValueDeref(writer, operand);5698 try f.writeCValueDeref(writer, operand);
5700 try a.assign(f, writer);5699 try a.assign(f, writer);
5701 try f.object.dg.renderValue(writer, Value.false, .Initializer);5700 try f.object.dg.renderValue(writer, Value.false, .Other);
5702 try a.end(f, writer);5701 try a.end(f, writer);
5703 return .none;5702 return .none;
5704 },5703 },
...@@ -5718,7 +5717,7 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5718,7 +5717,7 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
5718 const a = try Assignment.start(f, writer, opt_ctype);5717 const a = try Assignment.start(f, writer, opt_ctype);
5719 try f.writeCValueDerefMember(writer, operand, .{ .identifier = "is_null" });5718 try f.writeCValueDerefMember(writer, operand, .{ .identifier = "is_null" });
5720 try a.assign(f, writer);5719 try a.assign(f, writer);
5721 try f.object.dg.renderValue(writer, Value.false, .Initializer);5720 try f.object.dg.renderValue(writer, Value.false, .Other);
5722 try a.end(f, writer);5721 try a.end(f, writer);
5723 }5722 }
5724 if (f.liveness.isUnused(inst)) return .none;5723 if (f.liveness.isUnused(inst)) return .none;
...@@ -5844,7 +5843,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5844,7 +5843,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
5844 try writer.writeByte(')');5843 try writer.writeByte(')');
58455844
5846 switch (fieldLocation(container_ptr_ty, field_ptr_ty, extra.field_index, pt)) {5845 switch (fieldLocation(container_ptr_ty, field_ptr_ty, extra.field_index, pt)) {
5847 .begin => try f.writeCValue(writer, field_ptr_val, .Initializer),5846 .begin => try f.writeCValue(writer, field_ptr_val, .Other),
5848 .field => |field| {5847 .field => |field| {
5849 const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8);5848 const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8);
58505849
...@@ -5898,7 +5897,7 @@ fn fieldPtr(...@@ -5898,7 +5897,7 @@ fn fieldPtr(
5898 try writer.writeByte(')');5897 try writer.writeByte(')');
58995898
5900 switch (fieldLocation(container_ptr_ty, field_ptr_ty, field_index, pt)) {5899 switch (fieldLocation(container_ptr_ty, field_ptr_ty, field_index, pt)) {
5901 .begin => try f.writeCValue(writer, container_ptr_val, .Initializer),5900 .begin => try f.writeCValue(writer, container_ptr_val, .Other),
5902 .field => |field| {5901 .field => |field| {
5903 try writer.writeByte('&');5902 try writer.writeByte('&');
5904 try f.writeCValueDerefMember(writer, container_ptr_val, field);5903 try f.writeCValueDerefMember(writer, container_ptr_val, field);
...@@ -6021,7 +6020,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6021,7 +6020,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
6021 const operand_local = try f.allocLocal(inst, struct_ty);6020 const operand_local = try f.allocLocal(inst, struct_ty);
6022 try f.writeCValue(writer, operand_local, .Other);6021 try f.writeCValue(writer, operand_local, .Other);
6023 try writer.writeAll(" = ");6022 try writer.writeAll(" = ");
6024 try f.writeCValue(writer, struct_byval, .Initializer);6023 try f.writeCValue(writer, struct_byval, .Other);
6025 try writer.writeAll(";\n");6024 try writer.writeAll(";\n");
6026 break :blk operand_local;6025 break :blk operand_local;
6027 } else struct_byval;6026 } else struct_byval;
...@@ -6119,7 +6118,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu...@@ -6119,7 +6118,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu
6119 try writer.writeAll(" = (");6118 try writer.writeAll(" = (");
6120 try f.renderType(writer, inst_ty);6119 try f.renderType(writer, inst_ty);
6121 try writer.writeByte(')');6120 try writer.writeByte(')');
6122 try f.writeCValue(writer, operand, .Initializer);6121 try f.writeCValue(writer, operand, .Other);
6123 try writer.writeAll(";\n");6122 try writer.writeAll(";\n");
6124 return local;6123 return local;
6125 }6124 }
...@@ -6164,7 +6163,7 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6164,7 +6163,7 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {
6164 const a = try Assignment.start(f, writer, operand_ctype);6163 const a = try Assignment.start(f, writer, operand_ctype);
6165 try f.writeCValueMember(writer, local, .{ .identifier = "payload" });6164 try f.writeCValueMember(writer, local, .{ .identifier = "payload" });
6166 try a.assign(f, writer);6165 try a.assign(f, writer);
6167 try f.writeCValue(writer, operand, .Initializer);6166 try f.writeCValue(writer, operand, .Other);
6168 try a.end(f, writer);6167 try a.end(f, writer);
6169 }6168 }
6170 return local;6169 return local;
...@@ -6365,7 +6364,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6365,7 +6364,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
6365 try f.writeCValueMember(writer, local, .{ .identifier = "ptr" });6364 try f.writeCValueMember(writer, local, .{ .identifier = "ptr" });
6366 try a.assign(f, writer);6365 try a.assign(f, writer);
6367 if (operand == .undef) {6366 if (operand == .undef) {
6368 try f.writeCValue(writer, .{ .undef = inst_ty.slicePtrFieldType(zcu) }, .Initializer);6367 try f.writeCValue(writer, .{ .undef = inst_ty.slicePtrFieldType(zcu) }, .Other);
6369 } else {6368 } else {
6370 const ptr_ctype = try f.ctypeFromType(ptr_ty, .complete);6369 const ptr_ctype = try f.ctypeFromType(ptr_ty, .complete);
6371 const ptr_child_ctype = ptr_ctype.info(ctype_pool).pointer.elem_ctype;6370 const ptr_child_ctype = ptr_ctype.info(ctype_pool).pointer.elem_ctype;
...@@ -6382,7 +6381,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6382,7 +6381,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
6382 try writer.writeByte('&');6381 try writer.writeByte('&');
6383 try f.writeCValueDeref(writer, operand);6382 try f.writeCValueDeref(writer, operand);
6384 try writer.print("[{}]", .{try f.fmtIntLiteral(try pt.intValue(.usize, 0))});6383 try writer.print("[{}]", .{try f.fmtIntLiteral(try pt.intValue(.usize, 0))});
6385 } else try f.writeCValue(writer, operand, .Initializer);6384 } else try f.writeCValue(writer, operand, .Other);
6386 }6385 }
6387 try a.end(f, writer);6386 try a.end(f, writer);
6388 }6387 }
...@@ -6912,7 +6911,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -6912,7 +6911,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
6912 try writer.writeAll("for (");6911 try writer.writeAll("for (");
6913 try f.writeCValue(writer, index, .Other);6912 try f.writeCValue(writer, index, .Other);
6914 try writer.writeAll(" = ");6913 try writer.writeAll(" = ");
6915 try f.object.dg.renderValue(writer, try pt.intValue(.usize, 0), .Initializer);6914 try f.object.dg.renderValue(writer, try pt.intValue(.usize, 0), .Other);
6916 try writer.writeAll("; ");6915 try writer.writeAll("; ");
6917 try f.writeCValue(writer, index, .Other);6916 try f.writeCValue(writer, index, .Other);
6918 try writer.writeAll(" != ");6917 try writer.writeAll(" != ");
...@@ -7294,7 +7293,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7294,7 +7293,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
7294 .float => try pt.floatValue(scalar_ty, std.math.nan(f128)),7293 .float => try pt.floatValue(scalar_ty, std.math.nan(f128)),
7295 else => unreachable,7294 else => unreachable,
7296 },7295 },
7297 }, .Initializer);7296 }, .Other);
7298 try writer.writeAll(";\n");7297 try writer.writeAll(";\n");
72997298
7300 const v = try Vectorize.start(f, inst, writer, operand_ty);7299 const v = try Vectorize.start(f, inst, writer, operand_ty);