diff options
| author | gingerBill <bill@gingerbill.org> | 2025-01-29 15:53:34 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2025-01-29 15:53:34 +0000 |
| commit | 2656ecd4e17d448f1d972270bde87f75bc096d0d (patch) | |
| tree | e62d98a4222252def6909915ab15a57f4e010e29 /src | |
| parent | 5ebc31edcb9da281351e2ef2a0f6efbf2e6996ae (diff) | |
Fix #4773 - Change order of evaluation for slicing indices
Diffstat (limited to 'src')
| -rw-r--r-- | src/llvm_backend_expr.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/llvm_backend_expr.cpp b/src/llvm_backend_expr.cpp index df9dca801..871536927 100644 --- a/src/llvm_backend_expr.cpp +++ b/src/llvm_backend_expr.cpp @@ -4294,6 +4294,17 @@ gb_internal lbAddr lb_build_addr_index_expr(lbProcedure *p, Ast *expr) { gb_internal lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) { ast_node(se, SliceExpr, expr); + lbAddr addr = lb_build_addr(p, se->expr); + lbValue base = lb_addr_load(p, addr); + Type *type = base_type(base.type); + + if (is_type_pointer(type)) { + type = base_type(type_deref(type)); + addr = lb_addr(base); + base = lb_addr_load(p, addr); + } + + lbValue low = lb_const_int(p->module, t_int, 0); lbValue high = {}; @@ -4306,16 +4317,6 @@ gb_internal lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) { bool no_indices = se->low == nullptr && se->high == nullptr; - lbAddr addr = lb_build_addr(p, se->expr); - lbValue base = lb_addr_load(p, addr); - Type *type = base_type(base.type); - - if (is_type_pointer(type)) { - type = base_type(type_deref(type)); - addr = lb_addr(base); - base = lb_addr_load(p, addr); - } - switch (type->kind) { case Type_Slice: { Type *slice_type = type; |