aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-06-22 16:57:21 +0100
committergingerBill <bill@gingerbill.org>2020-06-22 16:57:21 +0100
commit2b27300387030c635acee783a2e573960ae3f748 (patch)
treed718a117e76c77482f6e75d415fc5b3bfd3ca198 /src/llvm_backend.cpp
parent0db1ebb4e5bf36a7c44b9119bcf3055a58fd6103 (diff)
Fix LLVM code gen bug
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index d24f40040..050bff9e3 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -2270,12 +2270,17 @@ lbProcedure *lb_create_dummy_procedure(lbModule *m, String link_name, Type *type
lbValue lb_value_param(lbProcedure *p, Entity *e, Type *abi_type, i32 index, lbParamPasskind *kind_) {
lbParamPasskind kind = lbParamPass_Value;
- if (e != nullptr && abi_type != e->type) {
+ if (e != nullptr && !are_types_identical(abi_type, e->type)) {
if (is_type_pointer(abi_type)) {
GB_ASSERT(e->kind == Entity_Variable);
- kind = lbParamPass_Pointer;
- if (e->flags&EntityFlag_Value) {
- kind = lbParamPass_ConstRef;
+ Type *av = type_deref(abi_type);
+ if (are_types_identical(av, e->type)) {
+ kind = lbParamPass_Pointer;
+ if (e->flags&EntityFlag_Value) {
+ kind = lbParamPass_ConstRef;
+ }
+ } else {
+ kind = lbParamPass_BitCast;
}
} else if (is_type_integer(abi_type)) {
kind = lbParamPass_Integer;
@@ -2364,6 +2369,7 @@ lbValue lb_add_param(lbProcedure *p, Entity *e, Ast *expr, Type *abi_type, i32 i
}
+
GB_PANIC("Unreachable");
return {};
}
@@ -7035,10 +7041,15 @@ lbValue lb_emit_call(lbProcedure *p, lbValue value, Array<lbValue> const &args,
array_add(&processed_args, args[i]);
} else if (!are_types_identical(original_type, new_type)) {
if (is_type_pointer(new_type) && !is_type_pointer(original_type)) {
- if (e->flags&EntityFlag_ImplicitReference) {
- array_add(&processed_args, lb_address_from_load_or_generate_local(p, args[i]));
- } else if (!is_type_pointer(arg_type)) {
- array_add(&processed_args, lb_copy_value_to_ptr(p, args[i], original_type, 16));
+ Type *av = type_deref(new_type);
+ if (are_types_identical(av, arg_type)) {
+ if (e->flags&EntityFlag_ImplicitReference) {
+ array_add(&processed_args, lb_address_from_load_or_generate_local(p, args[i]));
+ } else if (!is_type_pointer(arg_type)) {
+ array_add(&processed_args, lb_copy_value_to_ptr(p, args[i], original_type, 16));
+ }
+ } else {
+ array_add(&processed_args, lb_emit_transmute(p, args[i], new_type));
}
} else if (new_type == t_llvm_bool) {
array_add(&processed_args, lb_emit_conv(p, args[i], new_type));