aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 15de638737..c4b381f6d6 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -4761,7 +4761,15 @@ pub const FuncGen = struct {
const inst_ty = self.air.typeOfIndex(inst);
const llvm_slice_ty = try self.dg.llvmType(inst_ty);
- const partial = self.builder.buildInsertValue(llvm_slice_ty.getUndef(), ptr, 0, "");
+ // In case of slicing a global, the result type looks something like `{ i8*, i64 }`
+ // but `ptr` is pointing to the global directly. If it's an array, we would want to
+ // do GEP(0,0), or we can just bitcast it to be correct, like we do here.
+ // This prevents an assertion failure.
+ var buf: Type.SlicePtrFieldTypeBuffer = undefined;
+ const ptr_ty = inst_ty.slicePtrFieldType(&buf);
+ const ptr_llvm_ty = try self.dg.llvmType(ptr_ty);
+ const casted_ptr = self.builder.buildBitCast(ptr, ptr_llvm_ty, "");
+ const partial = self.builder.buildInsertValue(llvm_slice_ty.getUndef(), casted_ptr, 0, "");
return self.builder.buildInsertValue(partial, len, 1, "");
}