authorgravatar for reserveblue@protonmail.comdrew <reserveblue@protonmail.com> 2021-11-15 00:08:57-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-16 16:51:31-07:00
logf33af8f071a1782d222067e48b68eaed5d1a05a8
treee41638a7e1c7faf813e942aaea4823ffd11e5748
parentcf99afc52568ab121db2db8aa3ba94b97109f396

fix array airStoreUndefined for arrays


2 files changed, 13 insertions(+), 2 deletions(-)

src/codegen/c.zig+2-2
...@@ -1583,7 +1583,7 @@ fn airStoreUndefined(f: *Function, dest_ptr: CValue, dest_type: Type) !CValue {...@@ -1583,7 +1583,7 @@ fn airStoreUndefined(f: *Function, dest_ptr: CValue, dest_type: Type) !CValue {
1583 try writer.writeAll("));\n");1583 try writer.writeAll("));\n");
1584 },1584 },
1585 else => {1585 else => {
1586 const indirection = if (dest_type.zigTypeTag() == .Array) "" else "*";1586 const indirection = if (dest_type.childType().zigTypeTag() == .Array) "" else "*";
15871587
1588 try writer.writeAll("memset(");1588 try writer.writeAll("memset(");
1589 try f.writeCValue(writer, dest_ptr);1589 try f.writeCValue(writer, dest_ptr);
...@@ -1608,7 +1608,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -1608,7 +1608,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {
1608 return try airStoreUndefined(f, dest_ptr, lhs_type);1608 return try airStoreUndefined(f, dest_ptr, lhs_type);
16091609
1610 // Don't check this for airStoreUndefined as that will work for arrays already1610 // Don't check this for airStoreUndefined as that will work for arrays already
1611 if (lhs_type.zigTypeTag() == .Array)1611 if (lhs_type.childType().zigTypeTag() == .Array)
1612 return f.fail("TODO: C backend: implement airStore for arrays", .{});1612 return f.fail("TODO: C backend: implement airStore for arrays", .{});
16131613
1614 const writer = f.object.writer();1614 const writer = f.object.writer();
test/behavior/cast_c.zig+11
...@@ -247,3 +247,14 @@ test "*const ?[*]const T to [*c]const [*c]const T" {...@@ -247,3 +247,14 @@ test "*const ?[*]const T to [*c]const [*c]const T" {
247 try expect(b.*[0] == 'o');247 try expect(b.*[0] == 'o');
248 try expect(b[0][1] == 'k');248 try expect(b[0][1] == 'k');
249}249}
250
251test "array coersion to undefined at runtime" {
252 @setRuntimeSafety(true);
253
254 var array = [4]u8{ 3, 4, 5, 6 };
255 var undefined_val = [4]u8{ 0xAA, 0xAA, 0xAA, 0xAA };
256
257 try expect(std.mem.eql(u8, &array, &array));
258 array = undefined;
259 try expect(std.mem.eql(u8, &array, &undefined_val));
260}