diff options
| author | gingerBill <bill@gingerbill.org> | 2020-03-24 14:31:09 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-03-24 14:31:09 +0000 |
| commit | 1e375ba8de75f2649cd66089b87d273b749c575f (patch) | |
| tree | 61d05c65cbb2c36c780d96a77188572dc76165c6 /src/ir.cpp | |
| parent | 0730e01b24bfba4bd91f224dd4ecbeef23bd6c1c (diff) | |
| parent | 5cbb266ef5666c1df5d25d3afe23e4a777abd22b (diff) | |
Merge branch 'master' into llvm-integration
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index e938049c4..f51538a2e 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -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 } } |