fixes chained indexing for soa containers with array element type

This commit is contained in:
corley
2026-08-09 22:23:32 +03:00
parent 769184db41
commit e374541599
4 changed files with 287 additions and 8 deletions

View File

@@ -2996,8 +2996,13 @@ gb_internal void check_unary_expr(CheckerContext *c, Operand *o, Token op, Ast *
if (ast_node_expect(index_expr, Ast_IndexExpr)) {
ast_node(ie, IndexExpr, index_expr);
Type *soa_type = type_deref(type_of_expr(ie->expr));
GB_ASSERT(is_type_soa_struct(soa_type));
o->type = alloc_type_soa_pointer(soa_type);
if (is_type_soa_struct(soa_type)) {
o->type = alloc_type_soa_pointer(soa_type);
} else {
// &soa[i][j]
GB_ASSERT_MSG(is_type_array(soa_type), "%s", type_to_string(soa_type));
o->type = alloc_type_pointer(o->type);
}
} else {
o->type = alloc_type_pointer(o->type);
}
@@ -9158,7 +9163,11 @@ gb_internal bool check_set_index_data(Operand *o, Type *t, bool indirection, i64
if (indirection) {
o->mode = Addressing_Variable;
} else if (o->mode != Addressing_Variable &&
o->mode != Addressing_SoaVariable &&
o->mode != Addressing_Constant) {
// NOTE: an #soa element of array type keeps SoaVariable, so soa[i][j] stays an
// lvalue. Its components are one per lane rather than contiguous, but a single
// component still has a real address, the same one soa[i].y denotes.
o->mode = Addressing_Value;
}
o->type = t->Array.elem;