diff options
| author | gingerBill <bill@gingerbill.org> | 2020-02-23 10:55:09 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-02-23 10:55:09 +0000 |
| commit | 15f5c8537942e85d25819c7799991fab73b2564a (patch) | |
| tree | 4f79ef7d8dc55bf8777379f411237cbf1e6073b3 /src/ir.cpp | |
| parent | 10fe5e97b3eea5409660220a903bc6ad09478c1b (diff) | |
Fix comparison against nil for union #maybe pointers
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index b171e8589..e13530aca 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -4405,6 +4405,12 @@ irValue *ir_emit_comp_against_nil(irProcedure *proc, TokenKind op_kind, irValue } else if (is_type_union(t)) { if (type_size_of(t) == 0) { return ir_emit_comp(proc, op_kind, v_zero, v_zero); + } else if (is_type_union_maybe_pointer(t)) { + Type *bt = base_type(t); + irValue *ptr = ir_address_from_load_or_generate_local(proc, x); + ptr = ir_emit_bitcast(proc, ptr, alloc_type_pointer(bt->Union.variants[0])); + irValue *data = ir_emit_load(proc, ptr); + return ir_emit_comp_against_nil(proc, op_kind, data); } else { irValue *tag = ir_emit_union_tag_value(proc, x); return ir_emit_comp(proc, op_kind, tag, v_zero); |