From 050f128554d49d69d6411e4e898541ecfe5f8a33 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 3 May 2021 13:40:36 +0100 Subject: [PATCH] Correct hashing for union #maybe --- src/llvm_backend.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index e931d1ce9..92cc40094 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -10429,8 +10429,19 @@ lbValue lb_get_hasher_proc_for_type(lbModule *m, Type *type) { } LLVMBuildRet(p->builder, seed.value); } else if (type->kind == Type_Union) { - lbBlock *end_block = lb_create_block(p, "bend"); + auto args = array_make(permanent_allocator(), 2); + if (is_type_union_maybe_pointer(type)) { + Type *v = type->Union.variants[0]; + lbValue variant_hasher = lb_get_hasher_proc_for_type(m, v); + + args[0] = data; + args[1] = seed; + lbValue res = lb_emit_call(p, variant_hasher, args); + LLVMBuildRet(p->builder, res.value); + } + + lbBlock *end_block = lb_create_block(p, "bend"); data = lb_emit_conv(p, data, pt); lbValue tag_ptr = lb_emit_union_tag_ptr(p, data); @@ -10438,7 +10449,6 @@ lbValue lb_get_hasher_proc_for_type(lbModule *m, Type *type) { LLVMValueRef v_switch = LLVMBuildSwitch(p->builder, tag.value, end_block->block, cast(unsigned)type->Union.variants.count); - auto args = array_make(permanent_allocator(), 2); for_array(i, type->Union.variants) { lbBlock *case_block = lb_create_block(p, "bcase"); lb_start_block(p, case_block);