fix array airStoreUndefined for arrays

This commit is contained in:
drew 2021-11-15 00:08:57 -08:00 committed by Andrew Kelley
parent cf99afc525
commit f33af8f071
2 changed files with 13 additions and 2 deletions

View File

@ -1583,7 +1583,7 @@ fn airStoreUndefined(f: *Function, dest_ptr: CValue, dest_type: Type) !CValue {
try writer.writeAll("));\n");
},
else => {
const indirection = if (dest_type.zigTypeTag() == .Array) "" else "*";
const indirection = if (dest_type.childType().zigTypeTag() == .Array) "" else "*";
try writer.writeAll("memset(");
try f.writeCValue(writer, dest_ptr);
@ -1608,7 +1608,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index) !CValue {
return try airStoreUndefined(f, dest_ptr, lhs_type);
// Don't check this for airStoreUndefined as that will work for arrays already
if (lhs_type.zigTypeTag() == .Array)
if (lhs_type.childType().zigTypeTag() == .Array)
return f.fail("TODO: C backend: implement airStore for arrays", .{});
const writer = f.object.writer();

View File

@ -247,3 +247,14 @@ test "*const ?[*]const T to [*c]const [*c]const T" {
try expect(b.*[0] == 'o');
try expect(b[0][1] == 'k');
}
test "array coersion to undefined at runtime" {
@setRuntimeSafety(true);
var array = [4]u8{ 3, 4, 5, 6 };
var undefined_val = [4]u8{ 0xAA, 0xAA, 0xAA, 0xAA };
try expect(std.mem.eql(u8, &array, &array));
array = undefined;
try expect(std.mem.eql(u8, &array, &undefined_val));
}