aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-05-03 13:40:36 +0100
committergingerBill <bill@gingerbill.org>2021-05-03 13:40:36 +0100
commit050f128554d49d69d6411e4e898541ecfe5f8a33 (patch)
tree35842ff5d255b4d65d93a5a263e2f8fd39fb8e64 /src/llvm_backend.cpp
parent1a3784c4df312df72f15b179e083d83818e08def (diff)
Correct hashing for union #maybe
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp14
1 files 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<lbValue>(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<lbValue>(permanent_allocator(), 2);
for_array(i, type->Union.variants) {
lbBlock *case_block = lb_create_block(p, "bcase");
lb_start_block(p, case_block);