diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-04-27 14:39:21 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-27 14:39:21 -0400 |
| commit | 1b76d4c53adafebcbfcf0476276375353139dacb (patch) | |
| tree | 5854ca686d0d016e2d109766fa17742fff27c6ac /src/codegen/c.zig | |
| parent | 227d2b15e449db1e84788d2c87e4f49100d316ca (diff) | |
| parent | 2e9c1553ef40e9f21c2241294b8942369ef9007a (diff) | |
| download | zig-1b76d4c53adafebcbfcf0476276375353139dacb.tar.gz zig-1b76d4c53adafebcbfcf0476276375353139dacb.zip | |
Merge pull request #22605 from dweiller/memmove
add `@memmove` builtin
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 15 |
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); |
