From 1fa3f2b6aee2e4571b549188a47cd82e12f93d99 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 14 Dec 2023 13:15:16 +0300 Subject: [PATCH] Fixed LLVM "ptrtoint" and "inttoptr" conversion --- ir_load_llvm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ir_load_llvm.c b/ir_load_llvm.c index 3552689..51a97fa 100644 --- a/ir_load_llvm.c +++ b/ir_load_llvm.c @@ -303,6 +303,8 @@ static ir_ref llvm2ir_cast_op(ir_ctx *ctx, LLVMValueRef expr, ir_op op) dst_type = llvm2ir_type(LLVMTypeOf(expr)); if (op == IR_ZEXT && src_type == IR_BOOL && (dst_type == IR_I8 || dst_type == IR_U8)) { op = IR_BITCAST; + } else if (op == IR_BITCAST && ir_type_size[src_type] != ir_type_size[dst_type]) { + op = (ir_type_size[src_type] < ir_type_size[dst_type]) ? IR_ZEXT : IR_TRUNC; } ref = llvm2ir_op(ctx, op0, src_type); ref = ir_fold1(ctx, IR_OPT(op, dst_type), ref);