diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-09-02 10:06:44 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-09-02 10:06:44 +0100 |
| commit | 566a242ba3d7708aec2492a166899142d96a02b4 (patch) | |
| tree | 794c78b2f5232f0fd9e6559c57e3d2dafef0562c /src | |
| parent | 1e3b3c107ca76ef57460dc1b010efcf6c03b8cd7 (diff) | |
Fix issue #92
Diffstat (limited to 'src')
| -rw-r--r-- | src/ir.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index b10d3089a..7c38c721e 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -3178,11 +3178,7 @@ irValue *ir_emit_transmute(irProcedure *proc, irValue *value, Type *t) { Type *src = base_type(src_type); Type *dst = base_type(t); -#if 0 - if (are_types_identical(t, src_type)) { - return value; - } -#endif + irModule *m = proc->module; i64 sz = type_size_of(m->allocator, src); @@ -3190,6 +3186,14 @@ irValue *ir_emit_transmute(irProcedure *proc, irValue *value, Type *t) { GB_ASSERT_MSG(sz == dz, "Invalid transmute conversion: `%s` to `%s`", type_to_string(src_type), type_to_string(t)); + // NOTE(bill): Casting between an integer and a pointer cannot be done through a bitcast + if (is_type_int_or_uint(src) && is_type_pointer(dst)) { + return ir_emit_int_to_ptr(proc, value, t); + } + if (is_type_pointer(src) && is_type_int_or_uint(dst)) { + return ir_emit_ptr_to_int(proc, value, t); + } + if (ir_is_type_aggregate(src) || ir_is_type_aggregate(dst)) { irValue *s = ir_address_from_load_or_generate_local(proc, value); irValue *d = ir_emit_bitcast(proc, s, make_type_pointer(m->allocator, t)); @@ -3197,7 +3201,6 @@ irValue *ir_emit_transmute(irProcedure *proc, irValue *value, Type *t) { } // TODO(bill): Actually figure out what the conversion needs to be correctly 'cause LLVM - return ir_emit_bitcast(proc, value, dst); } @@ -3463,7 +3466,7 @@ irValue *ir_emit_logical_binary_expr(irProcedure *proc, AstNode *expr) { return ir_emit_load(proc, result); #else - irBlock *rhs = ir_new_block(proc, nullptr, "logical.cmp.rhs"); + irBlock *rhs = ir_new_block(proc, nullptr, "logical.cmp.rhs"); irBlock *done = ir_new_block(proc, nullptr, "logical.cmp.done"); Type *type = type_of_expr(proc->module->info, expr); @@ -3705,12 +3708,11 @@ void ir_gen_global_type_name(irModule *m, Entity *e, String name) { } if (is_poly) { auto found = map_get(&m->info->gen_types, hash_pointer(e->type)); - if (found == nullptr) { - return; - } - for_array(i, *found) { - Entity *e = (*found)[i]; - ir_mangle_add_sub_type_name(m, e, name); + if (found != nullptr) { + for_array(i, *found) { + Entity *e = (*found)[i]; + ir_mangle_add_sub_type_name(m, e, name); + } } return; } |