aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
authordweiller <4678790+dweiller@users.noreply.github.com>2025-01-23 00:13:23 +1100
committerdweiller <4678790+dweiller@users.noreply.github.com>2025-04-26 13:34:16 +1000
commit898ca824585e78306bb0137dbae1fbf859b762b6 (patch)
tree49934715689d33a7544b56e229e42b0d2e2063ef /src/codegen/c.zig
parentb9f440620d969204e8196ae6c226f939eb194d5e (diff)
downloadzig-898ca824585e78306bb0137dbae1fbf859b762b6.tar.gz
zig-898ca824585e78306bb0137dbae1fbf859b762b6.zip
compiler: add @memmove builtin
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 2aee078b11..e7883b9def 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -3349,6 +3349,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
.memset => try airMemset(f, inst, false),
.memset_safe => try airMemset(f, inst, true),
.memcpy => try airMemcpy(f, inst),
+ .memmove => try airMemmove(f, inst),
.set_union_tag => try airSetUnionTag(f, inst),
.get_union_tag => try airGetUnionTag(f, inst),
.clz => try airUnBuiltinCall(f, inst, air_datas[@intFromEnum(inst)].ty_op.operand, "clz", .bits),
@@ -6976,6 +6977,14 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
}
fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
+ return copyOp(f, inst, .memcpy);
+}
+
+fn airMemmove(f: *Function, inst: Air.Inst.Index) !CValue {
+ return copyOp(f, inst, .memmove);
+}
+
+fn copyOp(f: *Function, inst: Air.Inst.Index, op: enum { memcpy, memmove }) !CValue {
const pt = f.object.dg.pt;
const zcu = pt.zcu;
const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op;
@@ -6990,7 +6999,11 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
try writeArrayLen(f, writer, dest_ptr, dest_ty);
try writer.writeAll(" != 0) ");
}
- try writer.writeAll("memcpy(");
+ const function_paren = switch (op) {
+ .memcpy => "memcpy(",
+ .memmove => "memmove(",
+ };
+ try writer.writeAll(function_paren);
try writeSliceOrPtr(f, writer, dest_ptr, dest_ty);
try writer.writeAll(", ");
try writeSliceOrPtr(f, writer, src_ptr, src_ty);