Commit 86570b3e2c

Cody Tapscott <topolarity@tapscott.me>
2022-07-05 09:58:47
stage2: Fix corrupted Type when de-referencing field pointer
1 parent 6fc9f6c
Changed files (3)
src
test
behavior
src/Sema.zig
@@ -21614,10 +21614,10 @@ fn beginComptimePtrLoad(
                 deref.ty_without_well_defined_layout = field_ptr.container_ty;
             }
 
-            const tv = &(deref.pointee orelse {
+            const tv = deref.pointee orelse {
                 deref.pointee = null;
                 break :blk deref;
-            });
+            };
             const coerce_in_mem_ok =
                 (try sema.coerceInMemoryAllowed(block, field_ptr.container_ty, tv.ty, false, target, src, src)) == .ok or
                 (try sema.coerceInMemoryAllowed(block, tv.ty, field_ptr.container_ty, false, target, src, src)) == .ok;
test/behavior/bugs/12003.zig
@@ -0,0 +1,7 @@
+test {
+    comptime {
+        const tuple_with_ptrs = .{ &0, &0 };
+        const field_ptr = (&tuple_with_ptrs.@"0");
+        _ = field_ptr.*;
+    }
+}
test/behavior.zig
@@ -82,6 +82,7 @@ test {
     _ = @import("behavior/bugs/11179.zig");
     _ = @import("behavior/bugs/11181.zig");
     _ = @import("behavior/bugs/11213.zig");
+    _ = @import("behavior/bugs/12003.zig");
     _ = @import("behavior/byteswap.zig");
     _ = @import("behavior/byval_arg_var.zig");
     _ = @import("behavior/call.zig");