Merge branch 'master' into llvm-integration

This commit is contained in:
gingerBill
2020-03-24 14:31:09 +00:00
4 changed files with 27 additions and 19 deletions

View File

@@ -1155,10 +1155,12 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
}
}
bool is_reference = false;
if (is_ptr &&
cc->list.count == 1 &&
case_type != nullptr) {
case_type = alloc_type_pointer(case_type);
is_reference = true;
}
if (cc->list.count > 1) {
@@ -1173,7 +1175,9 @@ void check_type_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) {
{
Entity *tag_var = alloc_entity_variable(ctx->scope, lhs->Ident.token, case_type, EntityState_Resolved);
tag_var->flags |= EntityFlag_Used;
tag_var->flags |= EntityFlag_Value;
if (!is_reference) {
tag_var->flags |= EntityFlag_Value;
}
add_entity(ctx->checker, ctx->scope, lhs, tag_var);
add_entity_use(ctx, lhs, tag_var);
add_implicit_entity(ctx, stmt, tag_var);

View File

@@ -32,7 +32,7 @@ String const entity_strings[] = {
#undef ENTITY_KIND
};
enum EntityFlag {
enum EntityFlag : u32 {
EntityFlag_Visited = 1<<0,
EntityFlag_Used = 1<<1,
EntityFlag_Using = 1<<2,

View File

@@ -9530,13 +9530,16 @@ void ir_build_range_tuple(irProcedure *proc, Ast *expr, Type *val0_type, Type *v
void ir_store_type_case_implicit(irProcedure *proc, Ast *clause, irValue *value) {
Entity *e = implicit_entity_of_node(clause);
GB_ASSERT(e != nullptr);
#if 1
irValue *x = ir_add_local(proc, e, nullptr, false);
ir_emit_store(proc, x, value);
#else
irValue *x = ir_address_from_load_or_generate_local(proc, value);
ir_module_add_value(proc->module, e, x);
#endif
if (e->flags & EntityFlag_Value) {
// by value
irValue *x = ir_add_local(proc, e, nullptr, false);
GB_ASSERT(are_types_identical(ir_type(value), e->type));
ir_emit_store(proc, x, value);
} else {
// by reference
ir_module_add_value(proc->module, e, value);
}
}
void ir_type_case_body(irProcedure *proc, Ast *label, Ast *clause, irBlock *body, irBlock *done) {
@@ -10477,14 +10480,8 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
ir_start_block(proc, body);
// bool any_or_not_ptr = is_type_any(type_deref(parent_type)) || !is_parent_ptr;
bool any_or_not_ptr = !is_parent_ptr;
if (cc->list.count == 1) {
Type *ct = case_entity->type;
if (any_or_not_ptr) {
ct = alloc_type_pointer(ct);
}
GB_ASSERT_MSG(is_type_pointer(ct), "%s", type_to_string(ct));
irValue *data = nullptr;
if (switch_kind == TypeSwitch_Union) {
data = union_data;
@@ -10492,9 +10489,17 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
irValue *any_data = ir_emit_load(proc, ir_emit_struct_ep(proc, parent_ptr, 0));
data = any_data;
}
value = ir_emit_conv(proc, data, ct);
if (any_or_not_ptr) {
Type *ct = case_entity->type;
Type *ct_ptr = alloc_type_pointer(ct);
value = ir_emit_conv(proc, data, ct_ptr);
if (case_entity->flags & EntityFlag_Value) {
// by value
value = ir_emit_load(proc, value);
} else {
// by reference
}
}

View File

@@ -3490,4 +3490,3 @@ gbString type_to_string(Type *type) {
return write_type_to_string(gb_string_make(heap_allocator(), ""), type);
}