mirror of
https://github.com/odin-lang/Odin.git
synced 2026-09-02 18:23:35 +00:00
Merge pull request #7400 from kalsprite/union_slice_assert
backend: only reuse a compound literal's storage for a variable of its type
This commit is contained in:
@@ -3390,7 +3390,10 @@ gb_internal void lb_build_stmt(lbProcedure *p, Ast *node) {
|
||||
// NOTE(bill, 2023-02-17): lb_const_value might produce a stack local variable for the
|
||||
// compound literal, so reusing that variable should minimize the stack wastage
|
||||
lbAddr *comp_lit_addr = map_get(&p->module->exact_value_compound_literal_addr_map, rhs);
|
||||
if (comp_lit_addr) {
|
||||
// Only when the variable IS the literal. `x: U = []int{0}` declares a union and
|
||||
// the literal is one of its variants, so reusing that storage would bind the
|
||||
// variable to a bare `[]int` and never build the union at all
|
||||
if (comp_lit_addr && are_types_identical(lb_addr_type(*comp_lit_addr), type_of_expr(vd->names[lval_index]))) {
|
||||
if (Entity *e = entity_of_node(vd->names[lval_index])) {
|
||||
lbValue val = comp_lit_addr->addr;
|
||||
lb_add_entity(p->module, e, val);
|
||||
|
||||
Reference in New Issue
Block a user