diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-01-14 23:05:33 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-01-14 23:08:11 -0700 |
| commit | 41f3799bf0cfc8241f458094781ba45967e2576e (patch) | |
| tree | b26beee8643ba7ebac7774898366f6add4667e3b /src/Sema.zig | |
| parent | ba0f72363accc19edbfc5a7ae42d5a8970f56f64 (diff) | |
| download | zig-41f3799bf0cfc8241f458094781ba45967e2576e.tar.gz zig-41f3799bf0cfc8241f458094781ba45967e2576e.zip | |
Sema: fix array_init with runtime element
Previously it emitted an invalid AIR encoding.
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 7504352576..563b1d5096 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -367,10 +367,20 @@ pub const Block = struct { elem_index: Air.Inst.Ref, elem_ptr_ty: Type, ) !Air.Inst.Ref { + const ty_ref = try block.sema.addType(elem_ptr_ty); + return block.addPtrElemPtrTypeRef(array_ptr, elem_index, ty_ref); + } + + pub fn addPtrElemPtrTypeRef( + block: *Block, + array_ptr: Air.Inst.Ref, + elem_index: Air.Inst.Ref, + elem_ptr_ty: Air.Inst.Ref, + ) !Air.Inst.Ref { return block.addInst(.{ .tag = .ptr_elem_ptr, .data = .{ .ty_pl = .{ - .ty = try block.sema.addType(elem_ptr_ty), + .ty = elem_ptr_ty, .payload = try block.sema.addExtra(Air.Bin{ .lhs = array_ptr, .rhs = elem_index, @@ -10538,9 +10548,16 @@ fn zirArrayInit( }); const alloc = try block.addTy(.alloc, alloc_ty); + const elem_ptr_ty = try Type.ptr(sema.arena, .{ + .mutable = true, + .@"addrspace" = target_util.defaultAddressSpace(sema.mod.getTarget(), .local), + .pointee_type = elem_ty, + }); + const elem_ptr_ty_ref = try sema.addType(elem_ptr_ty); + for (resolved_args) |arg, i| { - const index = try sema.addIntUnsigned(Type.initTag(.u64), i); - const elem_ptr = try block.addBinOp(.ptr_elem_ptr, alloc, index); + const index = try sema.addIntUnsigned(Type.u64, i); + const elem_ptr = try block.addPtrElemPtrTypeRef(alloc, index, elem_ptr_ty_ref); _ = try block.addBinOp(.store, elem_ptr, arg); } if (is_ref) { |
