Commit 1f4a097117

Veikka Tuominen <git@vexu.eu>
2022-03-04 09:06:25
stage2: fix mem{set,cpy} for non comptime mutable pointers
1 parent ba17552
src/Sema.zig
@@ -13831,13 +13831,11 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
     const src_ptr = try sema.coerce(block, wanted_src_ptr_ty, uncasted_src_ptr, src_src);
     const len = try sema.coerce(block, Type.usize, sema.resolveInst(extra.byte_count), len_src);
 
-    const maybe_dest_ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr);
-    const maybe_src_ptr_val = try sema.resolveDefinedValue(block, src_src, src_ptr);
-    const maybe_len_val = try sema.resolveDefinedValue(block, len_src, len);
-
-    const runtime_src = if (maybe_dest_ptr_val) |dest_ptr_val| rs: {
-        if (maybe_src_ptr_val) |src_ptr_val| {
-            if (maybe_len_val) |len_val| {
+    const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |dest_ptr_val| rs: {
+        if (!dest_ptr_val.isComptimeMutablePtr()) break :rs dest_src;
+        if (try sema.resolveDefinedValue(block, src_src, src_ptr)) |src_ptr_val| {
+            if (!src_ptr_val.isComptimeMutablePtr()) break :rs src_src;
+            if (try sema.resolveDefinedValue(block, len_src, len)) |len_val| {
                 _ = dest_ptr_val;
                 _ = src_ptr_val;
                 _ = len_val;
@@ -13876,11 +13874,9 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
     const value = try sema.coerce(block, elem_ty, sema.resolveInst(extra.byte), value_src);
     const len = try sema.coerce(block, Type.usize, sema.resolveInst(extra.byte_count), len_src);
 
-    const maybe_dest_ptr_val = try sema.resolveDefinedValue(block, dest_src, dest_ptr);
-    const maybe_len_val = try sema.resolveDefinedValue(block, len_src, len);
-
-    const runtime_src = if (maybe_dest_ptr_val) |ptr_val| rs: {
-        if (maybe_len_val) |len_val| {
+    const runtime_src = if (try sema.resolveDefinedValue(block, dest_src, dest_ptr)) |ptr_val| rs: {
+        if (!ptr_val.isComptimeMutablePtr()) break :rs dest_src;
+        if (try sema.resolveDefinedValue(block, len_src, len)) |len_val| {
             if (try sema.resolveMaybeUndefVal(block, value_src, value)) |val| {
                 _ = ptr_val;
                 _ = len_val;
test/behavior/bugs/718.zig
@@ -1,4 +1,5 @@
 const std = @import("std");
+const builtin = @import("builtin");
 const mem = std.mem;
 const expect = std.testing.expect;
 const Keys = struct {
@@ -9,6 +10,10 @@ const Keys = struct {
 };
 var keys: Keys = undefined;
 test "zero keys with @memset" {
+    if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+    if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+    if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
+
     @memset(@ptrCast([*]u8, &keys), 0, @sizeOf(@TypeOf(keys)));
     try expect(!keys.up);
     try expect(!keys.down);
test/behavior/export_self_referential_type_info.zig
@@ -1,1 +1,1 @@
-export const foo = @typeInfo(@This()).Struct.decls;
+export const foo: c_int = @boolToInt(@typeInfo(@This()).Struct.is_tuple);
test/behavior.zig
@@ -17,6 +17,7 @@ test {
     _ = @import("behavior/bugs/656.zig");
     _ = @import("behavior/bugs/679.zig");
     _ = @import("behavior/bugs/704.zig");
+    _ = @import("behavior/bugs/718.zig");
     _ = @import("behavior/bugs/1025.zig");
     _ = @import("behavior/bugs/1076.zig");
     _ = @import("behavior/bugs/1111.zig");
@@ -124,6 +125,7 @@ test {
         _ = @import("behavior/bugs/10970.zig");
         _ = @import("behavior/cast_int.zig");
         _ = @import("behavior/eval.zig");
+        _ = @import("behavior/export_self_referential_type_info.zig");
         _ = @import("behavior/int128.zig");
         _ = @import("behavior/merge_error_sets.zig");
         _ = @import("behavior/translate_c_macros.zig");
@@ -154,7 +156,6 @@ test {
                 }
                 _ = @import("behavior/await_struct.zig");
                 _ = @import("behavior/bugs/529.zig");
-                _ = @import("behavior/bugs/718.zig");
                 _ = @import("behavior/bugs/920.zig");
                 _ = @import("behavior/bugs/1120.zig");
                 _ = @import("behavior/bugs/1851.zig");
@@ -166,7 +167,6 @@ test {
                 _ = @import("behavior/bugs/10147.zig");
                 _ = @import("behavior/const_slice_child.zig");
                 _ = @import("behavior/export.zig");
-                _ = @import("behavior/export_self_referential_type_info.zig");
                 _ = @import("behavior/select.zig");
                 _ = @import("behavior/shuffle.zig");
                 _ = @import("behavior/struct_contains_slice_of_itself.zig");