mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Fix slice and dynamic array lengths determined from ranged compound literals
This commit is contained in:
+2
-5
@@ -7209,9 +7209,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
|||||||
if (op.kind == Token_RangeHalf) {
|
if (op.kind == Token_RangeHalf) {
|
||||||
hi -= 1;
|
hi -= 1;
|
||||||
}
|
}
|
||||||
if (op.kind == Token_Ellipsis) {
|
|
||||||
max_index += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool new_range = range_cache_add_range(&rc, lo, hi);
|
bool new_range = range_cache_add_range(&rc, lo, hi);
|
||||||
if (!new_range) {
|
if (!new_range) {
|
||||||
@@ -7229,7 +7226,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max < max_index) {
|
if (max < hi) {
|
||||||
max = max_index;
|
max = max_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7272,7 +7269,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cl->max_index = max;
|
cl->max_count = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1552,7 +1552,7 @@ irValue *ir_add_module_constant(irModule *m, Type *type, ExactValue value) {
|
|||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
return ir_value_nil(type);
|
return ir_value_nil(type);
|
||||||
}
|
}
|
||||||
count = gb_max(cl->max_index+1, count);
|
count = gb_max(cl->max_count, count);
|
||||||
Type *elem = base_type(type)->Slice.elem;
|
Type *elem = base_type(type)->Slice.elem;
|
||||||
Type *t = alloc_type_array(elem, count);
|
Type *t = alloc_type_array(elem, count);
|
||||||
irValue *backing_array = ir_add_module_constant(m, t, value);
|
irValue *backing_array = ir_add_module_constant(m, t, value);
|
||||||
@@ -8047,7 +8047,7 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) {
|
|||||||
irValue *size = ir_const_int(type_size_of(et));
|
irValue *size = ir_const_int(type_size_of(et));
|
||||||
irValue *align = ir_const_int(type_align_of(et));
|
irValue *align = ir_const_int(type_align_of(et));
|
||||||
|
|
||||||
i64 item_count = gb_max(cl->max_index+1, cl->elems.count);
|
i64 item_count = gb_max(cl->max_count, cl->elems.count);
|
||||||
{
|
{
|
||||||
|
|
||||||
auto args = array_make<irValue *>(a, 5);
|
auto args = array_make<irValue *>(a, 5);
|
||||||
|
|||||||
+1
-1
@@ -250,7 +250,7 @@ enum StmtAllowFlag {
|
|||||||
Ast *type; \
|
Ast *type; \
|
||||||
Array<Ast *> elems; \
|
Array<Ast *> elems; \
|
||||||
Token open, close; \
|
Token open, close; \
|
||||||
i64 max_index; \
|
i64 max_count; \
|
||||||
}) \
|
}) \
|
||||||
AST_KIND(_ExprBegin, "", bool) \
|
AST_KIND(_ExprBegin, "", bool) \
|
||||||
AST_KIND(BadExpr, "bad expression", struct { Token begin, end; }) \
|
AST_KIND(BadExpr, "bad expression", struct { Token begin, end; }) \
|
||||||
|
|||||||
Reference in New Issue
Block a user