Skip to content

Commit 3e69186

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 578254c commit 3e69186

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", .{
@@ -4044,7 +4044,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
40444044
const new_local = try f.allocLocal(inst, src_ty);
40454045
try f.writeCValue(writer, new_local, .Other);
40464046
try writer.writeAll(" = ");
4047-
try f.writeCValue(writer, src_val, .Initializer);
4047+
try f.writeCValue(writer, src_val, .Other);
40484048
try writer.writeAll(";\n");
40494049
40504050
break :blk new_local;
@@ -4515,7 +4515,7 @@ fn airSlice(f: *Function, inst: Air.Inst.Index) !CValue {
45154515
const a = try Assignment.start(f, writer, .usize);
45164516
try f.writeCValueMember(writer, local, .{ .identifier = "len" });
45174517
try a.assign(f, writer);
4518-
try f.writeCValue(writer, len, .Initializer);
4518+
try f.writeCValue(writer, len, .Other);
45194519
try a.end(f, writer);
45204520
}
45214521
return local;
@@ -4933,7 +4933,7 @@ fn airSwitchDispatch(f: *Function, inst: Air.Inst.Index) !void {
49334933
const cond_local = f.loop_switch_conds.get(br.block_inst).?;
49344934
try f.writeCValue(writer, .{ .local = cond_local }, .Other);
49354935
try writer.writeAll(" = ");
4936-
try f.writeCValue(writer, cond, .Initializer);
4936+
try f.writeCValue(writer, cond, .Other);
49374937
try writer.writeAll(";\n");
49384938
try writer.print("goto zig_switch_{d}_loop;", .{@intFromEnum(br.block_inst)});
49394939
}
@@ -4978,14 +4978,13 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !CVal
49784978
const operand_lval = if (operand == .constant) blk: {
49794979
const operand_local = try f.allocLocal(null, operand_ty);
49804980
try f.writeCValue(writer, operand_local, .Other);
4981-
if (operand_ty.isAbiInt(zcu)) {
4982-
try writer.writeAll(" = ");
4983-
} else {
4984-
try writer.writeAll(" = (");
4981+
try writer.writeAll(" = ");
4982+
if (!operand_ty.isAbiInt(zcu)) {
4983+
try writer.writeByte('(');
49854984
try f.renderType(writer, operand_ty);
49864985
try writer.writeByte(')');
49874986
}
4988-
try f.writeCValue(writer, operand, .Initializer);
4987+
try f.writeCValue(writer, operand, .Other);
49894988
try writer.writeAll(";\n");
49904989
break :blk operand_local;
49914990
} else operand;
@@ -5697,7 +5696,7 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
56975696
const a = try Assignment.start(f, writer, opt_ctype);
56985697
try f.writeCValueDeref(writer, operand);
56995698
try a.assign(f, writer);
5700-
try f.object.dg.renderValue(writer, Value.false, .Initializer);
5699+
try f.object.dg.renderValue(writer, Value.false, .Other);
57015700
try a.end(f, writer);
57025701
return .none;
57035702
},
@@ -5717,7 +5716,7 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
57175716
const a = try Assignment.start(f, writer, opt_ctype);
57185717
try f.writeCValueDerefMember(writer, operand, .{ .identifier = "is_null" });
57195718
try a.assign(f, writer);
5720-
try f.object.dg.renderValue(writer, Value.false, .Initializer);
5719+
try f.object.dg.renderValue(writer, Value.false, .Other);
57215720
try a.end(f, writer);
57225721
}
57235722
if (f.liveness.isUnused(inst)) return .none;
@@ -5843,7 +5842,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
58435842
try writer.writeByte(')');
58445843

58455844
switch (fieldLocation(container_ptr_ty, field_ptr_ty, extra.field_index, pt)) {
5846-
.begin => try f.writeCValue(writer, field_ptr_val, .Initializer),
5845+
.begin => try f.writeCValue(writer, field_ptr_val, .Other),
58475846
.field => |field| {
58485847
const u8_ptr_ty = try pt.adjustPtrTypeChild(field_ptr_ty, .u8);
58495848

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

58995898
switch (fieldLocation(container_ptr_ty, field_ptr_ty, field_index, pt)) {
5900-
.begin => try f.writeCValue(writer, container_ptr_val, .Initializer),
5899+
.begin => try f.writeCValue(writer, container_ptr_val, .Other),
59015900
.field => |field| {
59025901
try writer.writeByte('&');
59035902
try f.writeCValueDerefMember(writer, container_ptr_val, field);
@@ -6020,7 +6019,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
60206019
const operand_local = try f.allocLocal(inst, struct_ty);
60216020
try f.writeCValue(writer, operand_local, .Other);
60226021
try writer.writeAll(" = ");
6023-
try f.writeCValue(writer, struct_byval, .Initializer);
6022+
try f.writeCValue(writer, struct_byval, .Other);
60246023
try writer.writeAll(";\n");
60256024
break :blk operand_local;
60266025
} else struct_byval;
@@ -6118,7 +6117,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu
61186117
try writer.writeAll(" = (");
61196118
try f.renderType(writer, inst_ty);
61206119
try writer.writeByte(')');
6121-
try f.writeCValue(writer, operand, .Initializer);
6120+
try f.writeCValue(writer, operand, .Other);
61226121
try writer.writeAll(";\n");
61236122
return local;
61246123
}
@@ -6163,7 +6162,7 @@ fn airWrapOptional(f: *Function, inst: Air.Inst.Index) !CValue {
61636162
const a = try Assignment.start(f, writer, operand_ctype);
61646163
try f.writeCValueMember(writer, local, .{ .identifier = "payload" });
61656164
try a.assign(f, writer);
6166-
try f.writeCValue(writer, operand, .Initializer);
6165+
try f.writeCValue(writer, operand, .Other);
61676166
try a.end(f, writer);
61686167
}
61696168
return local;
@@ -6364,7 +6363,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
63646363
try f.writeCValueMember(writer, local, .{ .identifier = "ptr" });
63656364
try a.assign(f, writer);
63666365
if (operand == .undef) {
6367-
try f.writeCValue(writer, .{ .undef = inst_ty.slicePtrFieldType(zcu) }, .Initializer);
6366+
try f.writeCValue(writer, .{ .undef = inst_ty.slicePtrFieldType(zcu) }, .Other);
63686367
} else {
63696368
const ptr_ctype = try f.ctypeFromType(ptr_ty, .complete);
63706369
const ptr_child_ctype = ptr_ctype.info(ctype_pool).pointer.elem_ctype;
@@ -6381,7 +6380,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
63816380
try writer.writeByte('&');
63826381
try f.writeCValueDeref(writer, operand);
63836382
try writer.print("[{}]", .{try f.fmtIntLiteral(try pt.intValue(.usize, 0))});
6384-
} else try f.writeCValue(writer, operand, .Initializer);
6383+
} else try f.writeCValue(writer, operand, .Other);
63856384
}
63866385
try a.end(f, writer);
63876386
}
@@ -6911,7 +6910,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
69116910
try writer.writeAll("for (");
69126911
try f.writeCValue(writer, index, .Other);
69136912
try writer.writeAll(" = ");
6914-
try f.object.dg.renderValue(writer, try pt.intValue(.usize, 0), .Initializer);
6913+
try f.object.dg.renderValue(writer, try pt.intValue(.usize, 0), .Other);
69156914
try writer.writeAll("; ");
69166915
try f.writeCValue(writer, index, .Other);
69176916
try writer.writeAll(" != ");
@@ -7281,7 +7280,7 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
72817280
.float => try pt.floatValue(scalar_ty, std.math.nan(f128)),
72827281
else => unreachable,
72837282
},
7284-
}, .Initializer);
7283+
}, .Other);
72857284
try writer.writeAll(";\n");
72867285

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

0 commit comments

Comments
 (0)