Browse Source

Fix `ir_copy_value_to_ptr` usage in `ir_emit_call` #350

gingerBill 6 years ago
parent
commit
712744ef36
1 changed files with 10 additions and 4 deletions
  1. 10 4
      src/ir.cpp

+ 10 - 4
src/ir.cpp

@@ -2875,12 +2875,12 @@ irValue *ir_copy_value_to_ptr(irProcedure *proc, irValue *val, Type *new_type, i
 	if (alignment < type_alignment) {
 		alignment = type_alignment;
 	}
+	GB_ASSERT_MSG(are_types_identical(new_type, ir_type(val)), "%s %s", type_to_string(new_type), type_to_string(ir_type(val)));
+
 	irValue *ptr = ir_add_local_generated(proc, new_type, false);
 	ptr->Instr.Local.alignment = alignment;
 	ir_emit_store(proc, ptr, val);
 
-	if (val) val->uses += 1;
-
 	return ptr;
 }
 
@@ -2972,12 +2972,18 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, Array<irValue *> args, Pro
 
 		Type *original_type = e->type;
 		Type *new_type = pt->Proc.abi_compat_params[i];
-		if (original_type != new_type) {
+		if (!are_types_identical(original_type, new_type)) {
+			Type *arg_type = ir_type(args[i]);
+
 			if (is_type_pointer(new_type)) {
 				if (e->flags&EntityFlag_Value) {
 					args[i] = ir_address_from_load_or_generate_local(p, args[i]);
 				} else {
-					args[i] = ir_copy_value_to_ptr(p, args[i], original_type, 16);
+					if (is_type_pointer(arg_type)) {
+						args[i] = ir_copy_value_to_ptr(p, ir_emit_load(p, args[i]), original_type, 16);
+					} else {
+						args[i] = ir_copy_value_to_ptr(p, args[i], original_type, 16);
+					}
 				}
 			} else if (is_type_integer(new_type)) {
 				args[i] = ir_emit_transmute(p, args[i], new_type);