mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 21:08:36 +00:00
fix array airStoreUndefined for arrays
This commit is contained in:
parent
cf99afc525
commit
f33af8f071
@ -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();
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user