authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-04 10:06:25+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-08 11:23:38+02:00
log1f4a097117a75b053d620658df4cb4e81c40fe1a
tree121da35d4732ae008b662911428198cae3a7cb71
parentba17552b4eb8def495053013eebbe39fc324c8ae

stage2: fix mem{set,cpy} for non comptime mutable pointers


4 files changed, 16 insertions(+), 15 deletions(-)

src/Sema.zig+8-12
......@@ -13831,13 +13831,11 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
1383113831 const src_ptr = try sema.coerce(block, wanted_src_ptr_ty, uncasted_src_ptr, src_src);
1383213832 const len = try sema.coerce(block, Type.usize, sema.resolveInst(extra.byte_count), len_src);
1383313833
13834 const maybe_dest_ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr);
13835 const maybe_src_ptr_val = try sema.resolveDefinedValue(block, src_src, src_ptr);
13836 const maybe_len_val = try sema.resolveDefinedValue(block, len_src, len);
13837
13838 const runtime_src = if (maybe_dest_ptr_val) |dest_ptr_val| rs: {
13839 if (maybe_src_ptr_val) |src_ptr_val| {
13840 if (maybe_len_val) |len_val| {
13834 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |dest_ptr_val| rs: {
13835 if (!dest_ptr_val.isComptimeMutablePtr()) break :rs dest_src;
13836 if (try sema.resolveDefinedValue(block, src_src, src_ptr)) |src_ptr_val| {
13837 if (!src_ptr_val.isComptimeMutablePtr()) break :rs src_src;
13838 if (try sema.resolveDefinedValue(block, len_src, len)) |len_val| {
1384113839 _ = dest_ptr_val;
1384213840 _ = src_ptr_val;
1384313841 _ = len_val;
......@@ -13876,11 +13874,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
1387613874 const value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.byte), value_src);
1387713875 const len = try sema.coerce(block, Type.usize, sema.resolveInst(extra.byte_count), len_src);
1387813876
13879 const maybe_dest_ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr);
13880 const maybe_len_val = try sema.resolveDefinedValue(block, len_src, len);
13881
13882 const runtime_src = if (maybe_dest_ptr_val) |ptr_val| rs: {
13883 if (maybe_len_val) |len_val| {
13877 const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: {
13878 if (!ptr_val.isComptimeMutablePtr()) break :rs dest_src;
13879 if (try sema.resolveDefinedValue(block, len_src, len)) |len_val| {
1388413880 if (try sema.resolveMaybeUndefVal(block, value_src, value)) |val| {
1388513881 _ = ptr_val;
1388613882 _ = len_val;
test/behavior.zig+2-2
......@@ -17,6 +17,7 @@ test {
1717 _ = @import("behavior/bugs/656.zig");
1818 _ = @import("behavior/bugs/679.zig");
1919 _ = @import("behavior/bugs/704.zig");
20 _ = @import("behavior/bugs/718.zig");
2021 _ = @import("behavior/bugs/1025.zig");
2122 _ = @import("behavior/bugs/1076.zig");
2223 _ = @import("behavior/bugs/1111.zig");
......@@ -124,6 +125,7 @@ test {
124125 _ = @import("behavior/bugs/10970.zig");
125126 _ = @import("behavior/cast_int.zig");
126127 _ = @import("behavior/eval.zig");
128 _ = @import("behavior/export_self_referential_type_info.zig");
127129 _ = @import("behavior/int128.zig");
128130 _ = @import("behavior/merge_error_sets.zig");
129131 _ = @import("behavior/translate_c_macros.zig");
......@@ -154,7 +156,6 @@ test {
154156 }
155157 _ = @import("behavior/await_struct.zig");
156158 _ = @import("behavior/bugs/529.zig");
157 _ = @import("behavior/bugs/718.zig");
158159 _ = @import("behavior/bugs/920.zig");
159160 _ = @import("behavior/bugs/1120.zig");
160161 _ = @import("behavior/bugs/1851.zig");
......@@ -166,7 +167,6 @@ test {
166167 _ = @import("behavior/bugs/10147.zig");
167168 _ = @import("behavior/const_slice_child.zig");
168169 _ = @import("behavior/export.zig");
169 _ = @import("behavior/export_self_referential_type_info.zig");
170170 _ = @import("behavior/select.zig");
171171 _ = @import("behavior/shuffle.zig");
172172 _ = @import("behavior/struct_contains_slice_of_itself.zig");
test/behavior/bugs/718.zig+5
......@@ -1,4 +1,5 @@
11const std = @import("std");
2const builtin = @import("builtin");
23const mem = std.mem;
34const expect = std.testing.expect;
45const Keys = struct {
......@@ -9,6 +10,10 @@ const Keys = struct {
910};
1011var keys: Keys = undefined;
1112test "zero keys with @memset" {
13 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
14 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
15 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
16
1217 @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys)));
1318 try expect(!keys.up);
1419 try expect(!keys.down);
test/behavior/export_self_referential_type_info.zig+1-1
......@@ -1 +1 @@
1export const foo = @typeInfo(@This()).Struct.decls;
1export const foo: c_int = @boolToInt(@typeInfo(@This()).Struct.is_tuple);