aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-08-12 13:48:10 +0100
committergingerBill <bill@gingerbill.org>2022-08-12 13:48:10 +0100
commit8e7c7eeebabcf81e6ca06e44ae8b98554addd142 (patch)
treebd45472c32303fc778b84f6ec7c03e97327edcf1
parent22d16c20f8e446fb51d7faa14f22b9f86df8b393 (diff)
Fix `lb_emit_ptr_offset`
-rw-r--r--src/llvm_backend_proc.cpp10
-rw-r--r--src/llvm_backend_utility.cpp2
-rw-r--r--src/types.cpp7
3 files changed, 8 insertions, 11 deletions
diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp
index ade2a55cf..784366476 100644
--- a/src/llvm_backend_proc.cpp
+++ b/src/llvm_backend_proc.cpp
@@ -2077,15 +2077,7 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
lbValue ptr = lb_build_expr(p, ce->args[0]);
lbValue len = lb_build_expr(p, ce->args[1]);
len = lb_emit_conv(p, len, t_int);
-
- LLVMValueRef indices[1] = {
- len.value,
- };
-
- lbValue res = {};
- res.type = tv.type;
- res.value = LLVMBuildGEP2(p->builder, lb_type(p->module, type_deref(tv.type)), ptr.value, indices, gb_count_of(indices), "");
- return res;
+ return lb_emit_ptr_offset(p, ptr, len);
}
case BuiltinProc_ptr_sub:
{
diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp
index ce7b43321..35e69a1be 100644
--- a/src/llvm_backend_utility.cpp
+++ b/src/llvm_backend_utility.cpp
@@ -1285,7 +1285,7 @@ lbValue lb_emit_ptr_offset(lbProcedure *p, lbValue ptr, lbValue index) {
LLVMValueRef indices[1] = {index.value};
lbValue res = {};
res.type = ptr.type;
- LLVMTypeRef type = lb_type(p->module, type_deref(ptr.type));
+ LLVMTypeRef type = lb_type(p->module, type_deref(res.type, true));
if (lb_is_const(ptr) && lb_is_const(index)) {
res.value = LLVMConstGEP2(type, ptr.value, indices, 1);
diff --git a/src/types.cpp b/src/types.cpp
index cba27fd6f..56b310867 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -1115,7 +1115,7 @@ Type *alloc_type_simd_vector(i64 count, Type *elem, Type *generic_count=nullptr)
////////////////////////////////////////////////////////////////
-Type *type_deref(Type *t) {
+Type *type_deref(Type *t, bool allow_multi_pointer=false) {
if (t != nullptr) {
Type *bt = base_type(t);
if (bt == nullptr) {
@@ -1132,6 +1132,11 @@ Type *type_deref(Type *t) {
GB_ASSERT(elem->kind == Type_Struct && elem->Struct.soa_kind != StructSoa_None);
return elem->Struct.soa_elem;
}
+ case Type_MultiPointer:
+ if (allow_multi_pointer) {
+ return bt->MultiPointer.elem;
+ }
+ break;
}
}
return t;