aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_utility.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/llvm_backend_utility.cpp')
-rw-r--r--src/llvm_backend_utility.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp
index db3cb443e..63e27f428 100644
--- a/src/llvm_backend_utility.cpp
+++ b/src/llvm_backend_utility.cpp
@@ -807,6 +807,13 @@ lbValue lb_address_from_load(lbProcedure *p, lbValue value) {
return {};
}
+i32 lb_convert_struct_index(Type *t, i32 index) {
+ if (t->kind == Type_Struct && t->Struct.custom_align != 0) {
+ index += 1;
+ }
+ return index;
+}
+
lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) {
GB_ASSERT(is_type_pointer(s.type));
Type *t = base_type(type_deref(s.type));
@@ -883,10 +890,9 @@ lbValue lb_emit_struct_ep(lbProcedure *p, lbValue s, i32 index) {
}
GB_ASSERT_MSG(result_type != nullptr, "%s %d", type_to_string(t), index);
-
- if (t->kind == Type_Struct && t->Struct.custom_align != 0) {
- index += 1;
- }
+
+ index = lb_convert_struct_index(t, index);
+
if (lb_is_const(s)) {
lbModule *m = p->module;
lbValue res = {};
@@ -1006,10 +1012,8 @@ lbValue lb_emit_struct_ev(lbProcedure *p, lbValue s, i32 index) {
}
GB_ASSERT_MSG(result_type != nullptr, "%s, %d", type_to_string(s.type), index);
-
- if (t->kind == Type_Struct && t->Struct.custom_align != 0) {
- index += 1;
- }
+
+ index = lb_convert_struct_index(t, index);
lbValue res = {};
res.value = LLVMBuildExtractValue(p->builder, s.value, cast(unsigned)index, "");