Add more check_is_operand_compound_lit_constant uses

This commit is contained in:
gingerBill
2025-09-28 23:53:07 +01:00
parent dd15a5bc8e
commit 4877214f34
3 changed files with 28 additions and 7 deletions
+16 -4
View File
@@ -8686,8 +8686,12 @@ gb_internal bool check_is_operand_compound_lit_constant(CheckerContext *c, Opera
} }
} }
if (field_type != nullptr && is_type_typeid(field_type) && o->mode == Addressing_Type) { if (field_type != nullptr && is_type_typeid(field_type) && o->mode == Addressing_Type) {
add_type_info_type(c, o->type);
return true; return true;
} }
if (is_type_any(field_type)) {
return false;
}
return o->mode == Addressing_Constant; return o->mode == Addressing_Constant;
} }
@@ -10052,7 +10056,9 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
check_expr_with_type_hint(c, &operand, fv->value, elem_type); check_expr_with_type_hint(c, &operand, fv->value, elem_type);
check_assignment(c, &operand, elem_type, context_name); check_assignment(c, &operand, elem_type, context_name);
is_constant = is_constant && operand.mode == Addressing_Constant; if (is_constant) {
is_constant = check_is_operand_compound_lit_constant(c, &operand, elem_type);
}
} else { } else {
Operand op_index = {}; Operand op_index = {};
check_expr(c, &op_index, fv->field); check_expr(c, &op_index, fv->field);
@@ -10289,7 +10295,9 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
check_expr_with_type_hint(c, &operand, fv->value, elem_type); check_expr_with_type_hint(c, &operand, fv->value, elem_type);
check_assignment(c, &operand, elem_type, context_name); check_assignment(c, &operand, elem_type, context_name);
is_constant = is_constant && operand.mode == Addressing_Constant; if (is_constant) {
is_constant = check_is_operand_compound_lit_constant(c, &operand, elem_type);
}
TokenKind upper_op = Token_LtEq; TokenKind upper_op = Token_LtEq;
if (op.kind == Token_RangeHalf) { if (op.kind == Token_RangeHalf) {
@@ -10330,7 +10338,9 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
check_expr_with_type_hint(c, &operand, fv->value, elem_type); check_expr_with_type_hint(c, &operand, fv->value, elem_type);
check_assignment(c, &operand, elem_type, context_name); check_assignment(c, &operand, elem_type, context_name);
is_constant = is_constant && operand.mode == Addressing_Constant; if (is_constant) {
is_constant = check_is_operand_compound_lit_constant(c, &operand, elem_type);
}
add_to_seen_map(c, &seen, op_index); add_to_seen_map(c, &seen, op_index);
} }
@@ -10360,7 +10370,9 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
check_expr_with_type_hint(c, &operand, e, elem_type); check_expr_with_type_hint(c, &operand, e, elem_type);
check_assignment(c, &operand, elem_type, context_name); check_assignment(c, &operand, elem_type, context_name);
is_constant = is_constant && operand.mode == Addressing_Constant; if (is_constant) {
is_constant = check_is_operand_compound_lit_constant(c, &operand, elem_type);
}
} }
if (max < index) { if (max < index) {
+8 -2
View File
@@ -1947,7 +1947,7 @@ gb_internal bool lb_init_global_var(lbModule *m, lbProcedure *p, Entity *e, Ast
GB_PANIC("Invalid init value, got %s", expr_to_string(init_expr)); GB_PANIC("Invalid init value, got %s", expr_to_string(init_expr));
} }
if (is_type_any(e->type) || is_type_union(e->type)) { if (is_type_any(e->type)) {
var.init = init; var.init = init;
} else if (lb_is_const_or_global(init)) { } else if (lb_is_const_or_global(init)) {
if (!var.is_initialized) { if (!var.is_initialized) {
@@ -3272,7 +3272,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
if (decl->init_expr != nullptr) { if (decl->init_expr != nullptr) {
TypeAndValue tav = type_and_value_of_expr(decl->init_expr); TypeAndValue tav = type_and_value_of_expr(decl->init_expr);
if (!is_type_any(e->type) && !is_type_union(e->type)) { if (!is_type_any(e->type)) {
if (tav.mode != Addressing_Invalid) { if (tav.mode != Addressing_Invalid) {
if (tav.value.kind != ExactValue_Invalid) { if (tav.value.kind != ExactValue_Invalid) {
auto cc = LB_CONST_CONTEXT_DEFAULT; auto cc = LB_CONST_CONTEXT_DEFAULT;
@@ -3287,6 +3287,12 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
g.value = nullptr; g.value = nullptr;
g.value = LLVMAddGlobal(m->mod, LLVMTypeOf(init.value), alloc_cstring(permanent_allocator(), name)); g.value = LLVMAddGlobal(m->mod, LLVMTypeOf(init.value), alloc_cstring(permanent_allocator(), name));
if (e->token.string == "node_camera_info") {
gb_printf_err("HERE!\n");
gb_printf_err("%s\n", LLVMPrintValueToString(init.value));
}
LLVMSetInitializer(g.value, init.value); LLVMSetInitializer(g.value, init.value);
var.is_initialized = true; var.is_initialized = true;
if (cc.is_rodata) { if (cc.is_rodata) {
+4 -1
View File
@@ -2536,7 +2536,10 @@ gb_internal bool elem_type_can_be_constant(Type *t) {
if (t == t_invalid) { if (t == t_invalid) {
return false; return false;
} }
if (is_type_any(t) || is_type_raw_union(t)) { if (is_type_any(t)) {
return false;
}
if (is_type_raw_union(t)) {
return false; return false;
} }
if (is_type_union(t)) { if (is_type_union(t)) {