Browse Source

Fix #4773 - Change order of evaluation for slicing indices

gingerBill 6 months ago
parent
commit
2656ecd4e1
1 changed files with 11 additions and 10 deletions
  1. 11 10
      src/llvm_backend_expr.cpp

+ 11 - 10
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) {
 gb_internal lbAddr lb_build_addr_slice_expr(lbProcedure *p, Ast *expr) {
 	ast_node(se, SliceExpr, 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 low  = lb_const_int(p->module, t_int, 0);
 	lbValue high = {};
 	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;
 	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) {
 	switch (type->kind) {
 	case Type_Slice: {
 	case Type_Slice: {
 		Type *slice_type = type;
 		Type *slice_type = type;