diff options
| author | gingerBill <bill@gingerbill.org> | 2022-11-11 15:52:49 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-11-11 15:52:49 +0000 |
| commit | fcd8860990f2f389dd257e316f78c69b3d486aac (patch) | |
| tree | ca89063110640a3af28ee30021f2403933dce261 /src/llvm_backend_proc.cpp | |
| parent | 035c75d6a9312762ea74a83af67430700596b1fd (diff) | |
Make `intrinsics.ptr_sub` use explicit integer arithmetic internally
Diffstat (limited to 'src/llvm_backend_proc.cpp')
| -rw-r--r-- | src/llvm_backend_proc.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp index a9de7b231..ae8236a71 100644 --- a/src/llvm_backend_proc.cpp +++ b/src/llvm_backend_proc.cpp @@ -2125,17 +2125,17 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv, } case BuiltinProc_ptr_sub: { - lbValue ptr0 = lb_build_expr(p, ce->args[0]); - lbValue ptr1 = lb_build_expr(p, ce->args[1]); + Type *elem0 = type_deref(type_of_expr(ce->args[0])); + Type *elem1 = type_deref(type_of_expr(ce->args[1])); + GB_ASSERT(are_types_identical(elem0, elem1)); + Type *elem = elem0; - LLVMTypeRef type_int = lb_type(p->module, t_int); - LLVMValueRef diff = LLVMBuildPtrDiff2(p->builder, lb_type(p->module, ptr0.type), ptr0.value, ptr1.value, ""); - diff = LLVMBuildIntCast2(p->builder, diff, type_int, /*signed*/true, ""); + lbValue ptr0 = lb_emit_conv(p, lb_build_expr(p, ce->args[0]), t_uintptr); + lbValue ptr1 = lb_emit_conv(p, lb_build_expr(p, ce->args[1]), t_uintptr); - lbValue res = {}; - res.type = t_int; - res.value = diff; - return res; + lbValue diff = lb_emit_arith(p, Token_Sub, ptr0, ptr1, t_uintptr); + diff = lb_emit_conv(p, diff, t_int); + return lb_emit_arith(p, Token_Quo, diff, lb_const_int(p->module, t_int, type_size_of(elem)), t_int); } |