diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-13 21:20:38 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-13 21:20:38 -0700 |
| commit | 0d4a94f32fc71f81d54db038f013854b8e9f0ac4 (patch) | |
| tree | 163668781596539d8d6f95e2de506aad544be355 /src/codegen | |
| parent | b0f80ef0d5517b5ce8ba60dfae6dd986346f8d4c (diff) | |
| download | zig-0d4a94f32fc71f81d54db038f013854b8e9f0ac4.tar.gz zig-0d4a94f32fc71f81d54db038f013854b8e9f0ac4.zip | |
stage2: improve handling of 0-bit types and arrays
* Make `alloc` AIR instructions call `resolveTypeLayout`.
* `Sema.zirResolveInferredAlloc` now calls `requireRuntimeBlock` in the
case that it operates on a non-comptime instruction.
* `Type.abiSize` and `Type.abiAlignment` now return 0 for `void`
* Sema: implement `resolveTypeFields` for unions.
* LLVM Backend: support `ptr_elem_ptr` when the element type is 0-bit.
* Type: improve `abiAlignment` implementation for structs to properly
handle fields with non-default alignment.
* Value: implement hashing array, vector, and structs.
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/llvm.zig | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index d7dbeade15..d4ee13c32d 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1863,14 +1863,16 @@ pub const FuncGen = struct { } fn airPtrElemPtr(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { - if (self.liveness.isUnused(inst)) - return null; + if (self.liveness.isUnused(inst)) return null; const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data; + const lhs_ty = self.air.typeOf(bin_op.lhs); + if (!lhs_ty.hasCodeGenBits()) return null; + const base_ptr = try self.resolveInst(bin_op.lhs); const rhs = try self.resolveInst(bin_op.rhs); - if (self.air.typeOf(bin_op.lhs).isSinglePointer()) { + if (lhs_ty.isSinglePointer()) { // If this is a single-item pointer to an array, we need another index in the GEP. const indices: [2]*const llvm.Value = .{ self.context.intType(32).constNull(), rhs }; return self.builder.buildInBoundsGEP(base_ptr, &indices, indices.len, ""); |
