mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Fix #1328
This commit is contained in:
@@ -179,32 +179,24 @@ lbValue lb_emit_transmute(lbProcedure *p, lbValue value, Type *t) {
|
|||||||
GB_ASSERT_MSG(sz == dz, "Invalid transmute conversion: '%s' to '%s'", type_to_string(src_type), type_to_string(t));
|
GB_ASSERT_MSG(sz == dz, "Invalid transmute conversion: '%s' to '%s'", type_to_string(src_type), type_to_string(t));
|
||||||
|
|
||||||
// NOTE(bill): Casting between an integer and a pointer cannot be done through a bitcast
|
// NOTE(bill): Casting between an integer and a pointer cannot be done through a bitcast
|
||||||
if (is_type_uintptr(src) && is_type_pointer(dst)) {
|
if (is_type_uintptr(src) && is_type_internally_pointer_like(dst)) {
|
||||||
res.value = LLVMBuildIntToPtr(p->builder, value.value, lb_type(m, t), "");
|
res.value = LLVMBuildIntToPtr(p->builder, value.value, lb_type(m, t), "");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
if (is_type_pointer(src) && is_type_uintptr(dst)) {
|
if (is_type_internally_pointer_like(src) && is_type_uintptr(dst)) {
|
||||||
res.value = LLVMBuildPtrToInt(p->builder, value.value, lb_type(m, t), "");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (is_type_uintptr(src) && is_type_proc(dst)) {
|
|
||||||
res.value = LLVMBuildIntToPtr(p->builder, value.value, lb_type(m, t), "");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
if (is_type_proc(src) && is_type_uintptr(dst)) {
|
|
||||||
res.value = LLVMBuildPtrToInt(p->builder, value.value, lb_type(m, t), "");
|
res.value = LLVMBuildPtrToInt(p->builder, value.value, lb_type(m, t), "");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_type_integer(src) && (is_type_pointer(dst) || is_type_cstring(dst))) {
|
if (is_type_integer(src) && is_type_internally_pointer_like(dst)) {
|
||||||
res.value = LLVMBuildIntToPtr(p->builder, value.value, lb_type(m, t), "");
|
res.value = LLVMBuildIntToPtr(p->builder, value.value, lb_type(m, t), "");
|
||||||
return res;
|
return res;
|
||||||
} else if ((is_type_pointer(src) || is_type_cstring(src)) && is_type_integer(dst)) {
|
} else if (is_type_internally_pointer_like(src) && is_type_integer(dst)) {
|
||||||
res.value = LLVMBuildPtrToInt(p->builder, value.value, lb_type(m, t), "");
|
res.value = LLVMBuildPtrToInt(p->builder, value.value, lb_type(m, t), "");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_type_pointer(src) && is_type_pointer(dst)) {
|
if (is_type_internally_pointer_like(src) && is_type_internally_pointer_like(dst)) {
|
||||||
res.value = LLVMBuildPointerCast(p->builder, value.value, lb_type(p->module, t), "");
|
res.value = LLVMBuildPointerCast(p->builder, value.value, lb_type(p->module, t), "");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -697,6 +697,7 @@ Type * bit_set_to_int(Type *t);
|
|||||||
bool are_types_identical(Type *x, Type *y);
|
bool are_types_identical(Type *x, Type *y);
|
||||||
|
|
||||||
bool is_type_pointer(Type *t);
|
bool is_type_pointer(Type *t);
|
||||||
|
bool is_type_proc(Type *t);
|
||||||
bool is_type_slice(Type *t);
|
bool is_type_slice(Type *t);
|
||||||
bool is_type_integer(Type *t);
|
bool is_type_integer(Type *t);
|
||||||
bool type_set_offsets(Type *t);
|
bool type_set_offsets(Type *t);
|
||||||
@@ -1284,6 +1285,10 @@ bool is_type_multi_pointer(Type *t) {
|
|||||||
t = base_type(t);
|
t = base_type(t);
|
||||||
return t->kind == Type_MultiPointer;
|
return t->kind == Type_MultiPointer;
|
||||||
}
|
}
|
||||||
|
bool is_type_internally_pointer_like(Type *t) {
|
||||||
|
return is_type_pointer(t) || is_type_multi_pointer(t) || is_type_cstring(t) || is_type_proc(t);
|
||||||
|
}
|
||||||
|
|
||||||
bool is_type_tuple(Type *t) {
|
bool is_type_tuple(Type *t) {
|
||||||
t = base_type(t);
|
t = base_type(t);
|
||||||
return t->kind == Type_Tuple;
|
return t->kind == Type_Tuple;
|
||||||
|
|||||||
Reference in New Issue
Block a user