authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2022-12-04 23:50:28-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-06 12:15:04-07:00
logf421efbcc1eebfca5a723a5d4ee5aa685bcc10d8
tree4ffeebda36c712ac185bde4a70cefe59e9a2464f
parentce4e5fee6346d142a7a98d5c56a056ff8a25e1f1

CBE: fix bad local reuse for volatile memset


1 files changed, 3 insertions(+), 2 deletions(-)

src/codegen/c.zig+3-2
......@@ -5935,16 +5935,15 @@ fn airMemset(f: *Function, inst: Air.Inst.Index) !CValue {
59355935 const dest_ptr = try f.resolveInst(pl_op.operand);
59365936 const value = try f.resolveInst(extra.lhs);
59375937 const len = try f.resolveInst(extra.rhs);
5938 try reap(f, inst, &.{ pl_op.operand, extra.lhs, extra.rhs });
59395938
59405939 const writer = f.object.writer();
59415940 if (dest_ty.isVolatilePtr()) {
59425941 var u8_ptr_pl = dest_ty.ptrInfo();
59435942 u8_ptr_pl.data.pointee_type = Type.u8;
59445943 const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base);
5944 const index = try f.allocLocal(inst, Type.usize);
59455945
59465946 try writer.writeAll("for (");
5947 const index = try f.allocLocal(inst, Type.usize);
59485947 try f.writeCValue(writer, index, .Other);
59495948 try writer.writeAll(" = ");
59505949 try f.object.dg.renderValue(writer, Type.usize, Value.zero, .Initializer);
......@@ -5966,11 +5965,13 @@ fn airMemset(f: *Function, inst: Air.Inst.Index) !CValue {
59665965 try f.writeCValue(writer, value, .FunctionArgument);
59675966 try writer.writeAll(";\n");
59685967
5968 try reap(f, inst, &.{ pl_op.operand, extra.lhs, extra.rhs });
59695969 try freeLocal(f, inst, index.local, 0);
59705970
59715971 return CValue.none;
59725972 }
59735973
5974 try reap(f, inst, &.{ pl_op.operand, extra.lhs, extra.rhs });
59745975 try writer.writeAll("memset(");
59755976 try f.writeCValue(writer, dest_ptr, .FunctionArgument);
59765977 try writer.writeAll(", ");