@@ -264,6 +264,11 @@ pub const Object = struct {
264264 );
265265 errdefer target_machine .dispose ();
266266
267+ const target_data = target_machine .createTargetDataLayout ();
268+ defer target_data .dispose ();
269+
270+ llvm_module .setModuleDataLayout (target_data );
271+
267272 return Object {
268273 .llvm_module = llvm_module ,
269274 .context = context ,
@@ -1589,13 +1594,17 @@ pub const FuncGen = struct {
15891594 return null ;
15901595
15911596 const ty_op = self .air .instructions .items (.data )[inst ].ty_op ;
1592- const operand = try self .resolveInst (ty_op .operand );
1593- const array_len = self . air . typeOf ( ty_op . operand ). elemType (). arrayLen ();
1594- const usize_llvm_ty = try self .dg .llvmType (Type .initTag ( . usize) );
1595- const len = usize_llvm_ty .constInt (array_len , .False );
1597+ const operand_ty = self .air . typeOf (ty_op .operand );
1598+ const array_ty = operand_ty . childType ();
1599+ const llvm_usize = try self .dg .llvmType (Type .usize );
1600+ const len = llvm_usize .constInt (array_ty . arrayLen () , .False );
15961601 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 );
15971606 const indices : [2 ]* const llvm.Value = .{
1598- usize_llvm_ty .constNull (), usize_llvm_ty .constNull (),
1607+ llvm_usize .constNull (), llvm_usize .constNull (),
15991608 };
16001609 const ptr = self .builder .buildInBoundsGEP (operand , & indices , indices .len , "" );
16011610 const partial = self .builder .buildInsertValue (slice_llvm_ty .getUndef (), ptr , 0 , "" );
@@ -2454,12 +2463,12 @@ pub const FuncGen = struct {
24542463 }
24552464
24562465 fn airAlloc (self : * FuncGen , inst : Air.Inst.Index ) ! ? * const llvm.Value {
2457- if (self .liveness .isUnused (inst ))
2458- return null ;
2466+ if (self .liveness .isUnused (inst )) return null ;
24592467 // buildAlloca expects the pointee type, not the pointer type, so assert that
24602468 // a Payload.PointerSimple is passed to the alloc instruction.
24612469 const ptr_ty = self .air .typeOfIndex (inst );
24622470 const pointee_type = ptr_ty .elemType ();
2471+ if (! pointee_type .hasCodeGenBits ()) return null ;
24632472 const pointee_llvm_ty = try self .dg .llvmType (pointee_type );
24642473 const target = self .dg .module .getTarget ();
24652474 const alloca_inst = self .buildAlloca (pointee_llvm_ty );
0 commit comments