Fix case: in type switch issue

This commit is contained in:
gingerBill
2024-07-15 13:22:50 +01:00
parent 7d643bcae3
commit 5cefab8229
2 changed files with 10 additions and 3 deletions
+1 -1
View File
@@ -1110,7 +1110,7 @@ gb_internal lbValue lb_emit_load(lbProcedure *p, lbValue value) {
return lb_addr_load(p, addr);
}
GB_ASSERT(is_type_pointer(value.type));
GB_ASSERT_MSG(is_type_pointer(value.type), "%s", type_to_string(value.type));
Type *t = type_deref(value.type);
LLVMValueRef v = LLVMBuildLoad2(p->builder, lb_type(p->module, t), value.value, "");
+9 -2
View File
@@ -1736,10 +1736,17 @@ gb_internal void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss
for (Ast *clause : body->stmts) {
ast_node(cc, CaseClause, clause);
Entity *case_entity = implicit_entity_of_node(clause);
lb_open_scope(p, cc->scope);
if (cc->list.count == 0) {
lb_start_block(p, default_block);
lb_store_type_case_implicit(p, clause, parent_value, true);
if (case_entity->flags & EntityFlag_Value) {
lb_store_type_case_implicit(p, clause, parent_value, true);
} else {
lb_store_type_case_implicit(p, clause, parent_ptr, true);
}
lb_type_case_body(p, ss->label, clause, p->curr_block, done);
continue;
}
@@ -1769,7 +1776,6 @@ gb_internal void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss
LLVMAddCase(switch_instr, on_val.value, body->block);
}
Entity *case_entity = implicit_entity_of_node(clause);
lb_start_block(p, body);
@@ -1782,6 +1788,7 @@ gb_internal void lb_build_type_switch_stmt(lbProcedure *p, AstTypeSwitchStmt *ss
} else if (switch_kind == TypeSwitch_Any) {
data = lb_emit_load(p, lb_emit_struct_ep(p, parent_ptr, 0));
}
GB_ASSERT(is_type_pointer(data.type));
Type *ct = case_entity->type;
Type *ct_ptr = alloc_type_pointer(ct);