From e0c5709cc8119d4b1b1c334b2d1c0923001da4c4 Mon Sep 17 00:00:00 2001 From: Philippe Tillet Date: Mon, 17 Jan 2022 18:00:03 -0800 Subject: [PATCH] [FRONTEND] Fixed semantics bug on ptr to bool conversions (#432) --- lib/ir/dispatch.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/ir/dispatch.cc b/lib/ir/dispatch.cc index 12be53bfc..73d4ddc94 100644 --- a/lib/ir/dispatch.cc +++ b/lib/ir/dispatch.cc @@ -527,8 +527,15 @@ ir::value *dispatch::cast(ir::value *input, ir::type *dst_ty, ir::builder *build else return builder->create_si_to_fp(input, dst_ty); } - if (src_sca_ty->is_pointer_ty() && !dst_sca_ty->is_pointer_ty()) - return builder->create_cast(ir::PtrToInt, input, dst_ty); + if (src_sca_ty->is_pointer_ty() && dst_sca_ty->is_integer_ty()){ + int bitwidth = dst_sca_ty->get_integer_bitwidth(); + if(bitwidth == 64) + return builder->create_cast(ir::PtrToInt, input, dst_ty); + if(bitwidth == 1) + return dispatch::not_equal(dispatch::cast(input, builder->get_int64_ty(), builder), + builder->get_int64(0), + builder); + } if (!src_sca_ty->is_pointer_ty() && dst_sca_ty->is_pointer_ty()) return builder->create_cast(ir::IntToPtr, input, dst_ty); // Ptr -> Ptr