From 21bf3b80666c14c9b2a2e1ec984a6b4bb23a5bb7 Mon Sep 17 00:00:00 2001 From: Robin Voetter Date: Tue, 26 Oct 2021 00:51:46 +0200 Subject: stage2: runtime c pointer null comparison --- src/codegen/llvm.zig | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 646633a90d..1a4bada192 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -2450,6 +2450,12 @@ pub const FuncGen = struct { const operand = try self.resolveInst(un_op); const operand_ty = self.air.typeOf(un_op); const optional_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty; + if (optional_ty.isPtrLikeOptional()) { + const optional_llvm_ty = try self.dg.llvmType(optional_ty); + const loaded = if (operand_is_ptr) self.builder.buildLoad(operand, "") else operand; + return self.builder.buildICmp(pred, loaded, optional_llvm_ty.constNull(), ""); + } + var buf: Type.Payload.ElemType = undefined; const payload_ty = optional_ty.optionalChild(&buf); if (!payload_ty.hasCodeGenBits()) { @@ -2459,11 +2465,6 @@ pub const FuncGen = struct { return operand; } } - if (optional_ty.isPtrLikeOptional()) { - const optional_llvm_ty = try self.dg.llvmType(optional_ty); - const loaded = if (operand_is_ptr) self.builder.buildLoad(operand, "") else operand; - return self.builder.buildICmp(pred, loaded, optional_llvm_ty.constNull(), ""); - } if (operand_is_ptr or isByRef(optional_ty)) { const index_type = self.context.intType(32); -- cgit v1.2.3