authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-16 00:08:44-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-16 00:09:00-07:00
log8a43d67c3bf878fa32ef4876897a32969a4b5d24
tree320ad0f9103506cdf11cfae0ea3ca19e3c381f2a
parentc3663f2617fd317f458bfa013ea94efb7dbcfee5

LLVM: fix LLVM assertion when slicing


1 files changed, 9 insertions(+), 1 deletions(-)

src/codegen/llvm.zig+9-1
......@@ -4761,7 +4761,15 @@ pub const FuncGen = struct {
47614761 const inst_ty = self.air.typeOfIndex(inst);
47624762 const llvm_slice_ty = try self.dg.llvmType(inst_ty);
47634763
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, "");
47654773 return self.builder.buildInsertValue(partial, len, 1, "");
47664774 }
47674775