aboutsummaryrefslogtreecommitdiff
path: root/src/tilde_expr.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-07-24 16:09:01 +0100
committergingerBill <bill@gingerbill.org>2023-07-24 16:09:01 +0100
commit28fca190ee11f5c19d30007f20caa4c7bf89f655 (patch)
tree595c387e0d83bec411e346d301c6c6d3e3d65676 /src/tilde_expr.cpp
parent78116e0ea24aef3f663832edfb5f9cd6aa7b6e57 (diff)
Fix `transmute(uintptr)ptr` etc
Diffstat (limited to 'src/tilde_expr.cpp')
-rw-r--r--src/tilde_expr.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/tilde_expr.cpp b/src/tilde_expr.cpp
index 993270c14..8737e75cd 100644
--- a/src/tilde_expr.cpp
+++ b/src/tilde_expr.cpp
@@ -191,7 +191,46 @@ gb_internal cgValue cg_emit_transmute(cgProcedure *p, cgValue value, Type *type)
GB_ASSERT_MSG(!TB_IS_VOID_TYPE(dt), "%d %s -> %s", dt.type, type_to_string(value.type), type_to_string(type));
value.type = type;
if (value.node->dt.raw != dt.raw) {
- value.node = tb_inst_bitcast(p->func, value.node, dt);
+ switch (value.node->dt.type) {
+ case TB_INT:
+ switch (value.node->dt.type) {
+ case TB_INT:
+ break;
+ case TB_FLOAT:
+ value.node = tb_inst_bitcast(p->func, value.node, dt);
+ break;
+ case TB_PTR:
+ value.node = tb_inst_int2ptr(p->func, value.node);
+ break;
+ }
+ break;
+ case TB_FLOAT:
+ switch (value.node->dt.type) {
+ case TB_INT:
+ value.node = tb_inst_bitcast(p->func, value.node, dt);
+ break;
+ case TB_FLOAT:
+ break;
+ case TB_PTR:
+ value.node = tb_inst_bitcast(p->func, value.node, TB_TYPE_INTPTR);
+ value.node = tb_inst_int2ptr(p->func, value.node);
+ break;
+ }
+ break;
+ case TB_PTR:
+ switch (value.node->dt.type) {
+ case TB_INT:
+ value.node = tb_inst_ptr2int(p->func, value.node, dt);
+ break;
+ case TB_FLOAT:
+ value.node = tb_inst_ptr2int(p->func, value.node, TB_TYPE_INTPTR);
+ value.node = tb_inst_bitcast(p->func, value.node, dt);
+ break;
+ case TB_PTR:
+ break;
+ }
+ break;
+ }
}
return value;
case cgValue_Addr: