authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-23 13:28:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-25 11:23:41-07:00
log0f65cc9275cde61fe20f28e4f059c8af4c63b051
tree7c3d3382a95906f7f1529c5536f25f5f6827ab7f
parent057c950093085e392fcdd6d6c8e7fb4356dd9959

C backend: fix memset for loop lowering

Previously, this code casted the array pointer to u8 pointer, but I removed that in a different commit. This commit restores the cast, but instead of hard-coding u8, it uses the destination element pointer, since memset now supports arbitrary element types.

1 files changed, 12 insertions(+), 1 deletions(-)

src/codegen/c.zig+12-1
......@@ -6233,6 +6233,15 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
62336233 }
62346234
62356235 if (elem_abi_size > 1 or dest_ty.isVolatilePtr()) {
6236 // For the assignment in this loop, the array pointer needs to get
6237 // casted to a regular pointer, otherwise an error like this occurs:
6238 // error: array type 'uint32_t[20]' (aka 'unsigned int[20]') is not assignable
6239 var elem_ptr_ty_pl: Type.Payload.ElemType = .{
6240 .base = .{ .tag = .c_mut_pointer },
6241 .data = elem_ty,
6242 };
6243 const elem_ptr_ty = Type.initPayload(&elem_ptr_ty_pl.base);
6244
62366245 const index = try f.allocLocal(inst, Type.usize);
62376246
62386247 try writer.writeAll("for (");
......@@ -6256,7 +6265,9 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
62566265 try f.writeCValue(writer, index, .Other);
62576266 try writer.writeAll(" += ");
62586267 try f.object.dg.renderValue(writer, Type.usize, Value.one, .Other);
6259 try writer.writeAll(") (");
6268 try writer.writeAll(") ((");
6269 try f.renderType(writer, elem_ptr_ty);
6270 try writer.writeByte(')');
62606271 try writeSliceOrPtr(f, writer, dest_slice, dest_ty);
62616272 try writer.writeAll(")[");
62626273 try f.writeCValue(writer, index, .Other);