aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-04-23 13:28:44 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-04-25 11:23:41 -0700
commit0f65cc9275cde61fe20f28e4f059c8af4c63b051 (patch)
tree7c3d3382a95906f7f1529c5536f25f5f6827ab7f /src/codegen
parent057c950093085e392fcdd6d6c8e7fb4356dd9959 (diff)
downloadzig-0f65cc9275cde61fe20f28e4f059c8af4c63b051.tar.gz
zig-0f65cc9275cde61fe20f28e4f059c8af4c63b051.zip
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.
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 2823cbef05..582b4bf086 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -6233,6 +6233,15 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
}
if (elem_abi_size > 1 or dest_ty.isVolatilePtr()) {
+ // For the assignment in this loop, the array pointer needs to get
+ // casted to a regular pointer, otherwise an error like this occurs:
+ // error: array type 'uint32_t[20]' (aka 'unsigned int[20]') is not assignable
+ var elem_ptr_ty_pl: Type.Payload.ElemType = .{
+ .base = .{ .tag = .c_mut_pointer },
+ .data = elem_ty,
+ };
+ const elem_ptr_ty = Type.initPayload(&elem_ptr_ty_pl.base);
+
const index = try f.allocLocal(inst, Type.usize);
try writer.writeAll("for (");
@@ -6256,7 +6265,9 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
try f.writeCValue(writer, index, .Other);
try writer.writeAll(" += ");
try f.object.dg.renderValue(writer, Type.usize, Value.one, .Other);
- try writer.writeAll(") (");
+ try writer.writeAll(") ((");
+ try f.renderType(writer, elem_ptr_ty);
+ try writer.writeByte(')');
try writeSliceOrPtr(f, writer, dest_slice, dest_ty);
try writer.writeAll(")[");
try f.writeCValue(writer, index, .Other);