| ... | @@ -264,6 +264,11 @@ pub const Object = struct { | ... | @@ -264,6 +264,11 @@ pub const Object = struct { |
| 264 | ); | 264 | ); |
| 265 | errdefer target_machine.dispose(); | 265 | errdefer target_machine.dispose(); |
| 266 | | 266 | |
| | 267 | const target_data = target_machine.createTargetDataLayout(); |
| | 268 | defer target_data.dispose(); |
| | 269 | |
| | 270 | llvm_module.setModuleDataLayout(target_data); |
| | 271 | |
| 267 | return Object{ | 272 | return Object{ |
| 268 | .llvm_module = llvm_module, | 273 | .llvm_module = llvm_module, |
| 269 | .context = context, | 274 | .context = context, |
| ... | @@ -1589,13 +1594,17 @@ pub const FuncGen = struct { | ... | @@ -1589,13 +1594,17 @@ pub const FuncGen = struct { |
| 1589 | return null; | 1594 | return null; |
| 1590 | | 1595 | |
| 1591 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; | 1596 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 1592 | const operand = try self.resolveInst(ty_op.operand); | 1597 | const operand_ty = self.air.typeOf(ty_op.operand); |
| 1593 | const array_len = self.air.typeOf(ty_op.operand).elemType().arrayLen(); | 1598 | const array_ty = operand_ty.childType(); |
| 1594 | const usize_llvm_ty = try self.dg.llvmType(Type.initTag(.usize)); | 1599 | const llvm_usize = try self.dg.llvmType(Type.usize); |
| 1595 | const len = usize_llvm_ty.constInt(array_len, .False); | 1600 | const len = llvm_usize.constInt(array_ty.arrayLen(), .False); |
| 1596 | const slice_llvm_ty = try self.dg.llvmType(self.air.typeOfIndex(inst)); | 1601 | const slice_llvm_ty = try self.dg.llvmType(self.air.typeOfIndex(inst)); |
| | 1602 | if (!array_ty.hasCodeGenBits()) { |
| | 1603 | return self.builder.buildInsertValue(slice_llvm_ty.getUndef(), len, 1, ""); |
| | 1604 | } |
| | 1605 | const operand = try self.resolveInst(ty_op.operand); |
| 1597 | const indices: [2]*const llvm.Value = .{ | 1606 | const indices: [2]*const llvm.Value = .{ |
| 1598 | usize_llvm_ty.constNull(), usize_llvm_ty.constNull(), | 1607 | llvm_usize.constNull(), llvm_usize.constNull(), |
| 1599 | }; | 1608 | }; |
| 1600 | const ptr = self.builder.buildInBoundsGEP(operand, &indices, indices.len, ""); | 1609 | const ptr = self.builder.buildInBoundsGEP(operand, &indices, indices.len, ""); |
| 1601 | const partial = self.builder.buildInsertValue(slice_llvm_ty.getUndef(), ptr, 0, ""); | 1610 | const partial = self.builder.buildInsertValue(slice_llvm_ty.getUndef(), ptr, 0, ""); |
| ... | @@ -2454,12 +2463,12 @@ pub const FuncGen = struct { | ... | @@ -2454,12 +2463,12 @@ pub const FuncGen = struct { |
| 2454 | } | 2463 | } |
| 2455 | | 2464 | |
| 2456 | fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { | 2465 | fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { |
| 2457 | if (self.liveness.isUnused(inst)) | 2466 | if (self.liveness.isUnused(inst)) return null; |
| 2458 | return null; | | |
| 2459 | // buildAlloca expects the pointee type, not the pointer type, so assert that | 2467 | // buildAlloca expects the pointee type, not the pointer type, so assert that |
| 2460 | // a Payload.PointerSimple is passed to the alloc instruction. | 2468 | // a Payload.PointerSimple is passed to the alloc instruction. |
| 2461 | const ptr_ty = self.air.typeOfIndex(inst); | 2469 | const ptr_ty = self.air.typeOfIndex(inst); |
| 2462 | const pointee_type = ptr_ty.elemType(); | 2470 | const pointee_type = ptr_ty.elemType(); |
| | 2471 | if (!pointee_type.hasCodeGenBits()) return null; |
| 2463 | const pointee_llvm_ty = try self.dg.llvmType(pointee_type); | 2472 | const pointee_llvm_ty = try self.dg.llvmType(pointee_type); |
| 2464 | const target = self.dg.module.getTarget(); | 2473 | const target = self.dg.module.getTarget(); |
| 2465 | const alloca_inst = self.buildAlloca(pointee_llvm_ty); | 2474 | const alloca_inst = self.buildAlloca(pointee_llvm_ty); |