| ... | @@ -4761,7 +4761,15 @@ pub const FuncGen = struct { | ... | @@ -4761,7 +4761,15 @@ pub const FuncGen = struct { |
| 4761 | const inst_ty = self.air.typeOfIndex(inst); | 4761 | const inst_ty = self.air.typeOfIndex(inst); |
| 4762 | const llvm_slice_ty = try self.dg.llvmType(inst_ty); | 4762 | const llvm_slice_ty = try self.dg.llvmType(inst_ty); |
| 4763 | | 4763 | |
| 4764 | const partial = self.builder.buildInsertValue(llvm_slice_ty.getUndef(), ptr, 0, ""); | 4764 | // In case of slicing a global, the result type looks something like `{ i8*, i64 }` |
| | 4765 | // but `ptr` is pointing to the global directly. If it's an array, we would want to |
| | 4766 | // do GEP(0,0), or we can just bitcast it to be correct, like we do here. |
| | 4767 | // This prevents an assertion failure. |
| | 4768 | var buf: Type.SlicePtrFieldTypeBuffer = undefined; |
| | 4769 | const ptr_ty = inst_ty.slicePtrFieldType(&buf); |
| | 4770 | const ptr_llvm_ty = try self.dg.llvmType(ptr_ty); |
| | 4771 | const casted_ptr = self.builder.buildBitCast(ptr, ptr_llvm_ty, ""); |
| | 4772 | const partial = self.builder.buildInsertValue(llvm_slice_ty.getUndef(), casted_ptr, 0, ""); |
| 4765 | return self.builder.buildInsertValue(partial, len, 1, ""); | 4773 | return self.builder.buildInsertValue(partial, len, 1, ""); |
| 4766 | } | 4774 | } |
| 4767 | | 4775 | |