Skip to content

Commit 029cc06

Browse files
jacobly0mlugg
authored andcommitted
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 parent 95932e9 commit 029cc06

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/codegen/c.zig

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ pub const Function = struct {
611611
const a = try Assignment.start(f, writer, ctype);
612612
try f.writeCValue(writer, dst, .Other);
613613
try a.assign(f, writer);
614-
try f.writeCValue(writer, src, .Initializer);
614+
try f.writeCValue(writer, src, .Other);
615615
try a.end(f, writer);
616616
}
617617

@@ -2826,7 +2826,7 @@ pub fn genLazyFn(o: *Object, lazy_ctype_pool: *const CType.Pool, lazy_fn: LazyFn
28262826
});
28272827
try o.dg.renderTypeAndName(w, name_ty, .{ .identifier = "name" }, Const, .none, .complete);
28282828
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);
28302830
try w.writeAll(";\n return (");
28312831
try o.dg.renderType(w, name_slice_ty);
28322832
try w.print("){{{}, {}}};\n", .{
@@ -4045,7 +4045,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
40454045
const new_local = try f.allocLocal(inst, src_ty);
40464046
try f.writeCValue(writer, new_local, .Other);
40474047
try writer.writeAll(" = ");
4048-
try f.writeCValue(writer, src_val, .Initializer);
4048+
try f.writeCValue(writer, src_val, .Other);
40494049
try writer.writeAll(";\n");
40504050
40514051
break :blk new_local;
@@ -4516,7 +4516,7 @@ fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue {
45164516
const a = try Assignment.start(f, writer, .usize);
45174517
try f.writeCValueMember(writer, local, .{ .identifier = "len" });
45184518
try a.assign(f, writer);
4519-
try f.writeCValue(writer, len, .Initializer);
4519+
try f.writeCValue(writer, len, .Other);
45204520
try a.end(f, writer);
45214521
}
45224522
return local;
@@ -4934,7 +4934,7 @@ fn airSwitchDispatch(f: *Function, inst: Air.Inst.Index) !void {
49344934
const cond_local = f.loop_switch_conds.get(br.block_inst).?;
49354935
try f.writeCValue(writer, .{ .local = cond_local }, .Other);
49364936
try writer.writeAll(" = ");
4937-
try f.writeCValue(writer, cond, .Initializer);
4937+
try f.writeCValue(writer, cond, .Other);
49384938
try writer.writeAll(";\n");
49394939
try writer.print("goto zig_switch_{d}_loop;", .{@intFromEnum(br.block_inst)});
49404940
}
@@ -4979,14 +4979,13 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !CVal
49794979
const operand_lval = if (operand == .constant) blk: {
49804980
const operand_local = try f.allocLocal(null, operand_ty);
49814981
try f.writeCValue(writer, operand_local, .Other);
4982-
if (operand_ty.isAbiInt(zcu)) {
4983-
try writer.writeAll(" = ");
4984-
} else {
4985-
try writer.writeAll(" = (");
4982+
try writer.writeAll(" = ");
4983+
if (!operand_ty.isAbiInt(zcu)) {
4984+
try writer.writeByte('(');
49864985
try f.renderType(writer, operand_ty);
49874986
try writer.writeByte(')');
49884987
}
4989-
try f.writeCValue(writer, operand, .Initializer);
4988+
try f.writeCValue(writer, operand, .Other);
49904989
try writer.writeAll(";\n");
49914990
break :blk operand_local;
49924991
} else operand;
@@ -5698,7 +5697,7 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
56985697
const a = try Assignment.start(f, writer, opt_ctype);
56995698
try f.writeCValueDeref(writer, operand);
57005699
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);
57025701
try a.end(f, writer);
57035702
return .none;
57045703
},
@@ -5718,7 +5717,7 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
57185717
const a = try Assignment.start(f, writer, opt_ctype);
57195718
try f.writeCValueDerefMember(writer, operand, .{ .identifier = "is_null" });
57205719
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);
57225721
try a.end(f, writer);
57235722
}
57245723
if (f.liveness.isUnused(inst)) return .none;
@@ -5844,7 +5843,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
58445843
try writer.writeByte(')');
58455844

58465845
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),
58485847
.field => |field| {
58495848
const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8);
58505849

@@ -5898,7 +5897,7 @@ fn fieldPtr(
58985897
try writer.writeByte(')');
58995898

59005899
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),
59025901
.field => |field| {
59035902
try writer.writeByte('&');
59045903
try f.writeCValueDerefMember(writer, container_ptr_val, field);
@@ -6021,7 +6020,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
60216020
const operand_local = try f.allocLocal(inst, struct_ty);
60226021
try f.writeCValue(writer, operand_local, .Other);
60236022
try writer.writeAll(" = ");
6024-
try f.writeCValue(writer, struct_byval, .Initializer);
6023+
try f.writeCValue(writer, struct_byval, .Other);
60256024
try writer.writeAll(";\n");
60266025
break :blk operand_local;
60276026
} else struct_byval;
@@ -6119,7 +6118,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu
61196118
try writer.writeAll(" = (");
61206119
try f.renderType(writer, inst_ty);
61216120
try writer.writeByte(')');
6122-
try f.writeCValue(writer, operand, .Initializer);
6121+
try f.writeCValue(writer, operand, .Other);
61236122
try writer.writeAll(";\n");
61246123
return local;
61256124
}
@@ -6164,7 +6163,7 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {
61646163
const a = try Assignment.start(f, writer, operand_ctype);
61656164
try f.writeCValueMember(writer, local, .{ .identifier = "payload" });
61666165
try a.assign(f, writer);
6167-
try f.writeCValue(writer, operand, .Initializer);
6166+
try f.writeCValue(writer, operand, .Other);
61686167
try a.end(f, writer);
61696168
}
61706169
return local;
@@ -6365,7 +6364,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
63656364
try f.writeCValueMember(writer, local, .{ .identifier = "ptr" });
63666365
try a.assign(f, writer);
63676366
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);
63696368
} else {
63706369
const ptr_ctype = try f.ctypeFromType(ptr_ty, .complete);
63716370
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 {
63826381
try writer.writeByte('&');
63836382
try f.writeCValueDeref(writer, operand);
63846383
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);
63866385
}
63876386
try a.end(f, writer);
63886387
}
@@ -6912,7 +6911,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
69126911
try writer.writeAll("for (");
69136912
try f.writeCValue(writer, index, .Other);
69146913
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);
69166915
try writer.writeAll("; ");
69176916
try f.writeCValue(writer, index, .Other);
69186917
try writer.writeAll(" != ");
@@ -7294,7 +7293,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
72947293
.float => try pt.floatValue(scalar_ty, std.math.nan(f128)),
72957294
else => unreachable,
72967295
},
7297-
}, .Initializer);
7296+
}, .Other);
72987297
try writer.writeAll(";\n");
72997298

73007299
const v = try Vectorize.start(f, inst, writer, operand_ty);

0 commit comments

Comments
 (0)