| ... | ... | @@ -17477,10 +17477,10 @@ fn zirCmpEq( |
| 17477 | 17477 | |
| 17478 | 17478 | // comparing null with optionals |
| 17479 | 17479 | if (lhs_ty_tag == .null and (rhs_ty_tag == .optional or rhs_ty.isCPtr(zcu))) { |
| 17480 | | return sema.analyzeIsNull(block, src, rhs, op == .neq); |
| 17480 | return sema.analyzeIsNull(block, rhs, op == .neq); |
| 17481 | 17481 | } |
| 17482 | 17482 | if (rhs_ty_tag == .null and (lhs_ty_tag == .optional or lhs_ty.isCPtr(zcu))) { |
| 17483 | | return sema.analyzeIsNull(block, src, lhs, op == .neq); |
| 17483 | return sema.analyzeIsNull(block, lhs, op == .neq); |
| 17484 | 17484 | } |
| 17485 | 17485 | |
| 17486 | 17486 | if (lhs_ty_tag == .null or rhs_ty_tag == .null) { |
| ... | ... | @@ -19326,7 +19326,7 @@ fn zirIsNonNull( |
| 19326 | 19326 | const src = block.nodeOffset(inst_data.src_node); |
| 19327 | 19327 | const operand = try sema.resolveInst(inst_data.operand); |
| 19328 | 19328 | try sema.checkNullableType(block, src, sema.typeOf(operand)); |
| 19329 | | return sema.analyzeIsNull(block, src, operand, true); |
| 19329 | return sema.analyzeIsNull(block, operand, true); |
| 19330 | 19330 | } |
| 19331 | 19331 | |
| 19332 | 19332 | fn zirIsNonNullPtr( |
| ... | ... | @@ -19342,12 +19342,17 @@ fn zirIsNonNullPtr( |
| 19342 | 19342 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].un_node; |
| 19343 | 19343 | const src = block.nodeOffset(inst_data.src_node); |
| 19344 | 19344 | const ptr = try sema.resolveInst(inst_data.operand); |
| 19345 | const ptr_ty = sema.typeOf(ptr); |
| 19345 | 19346 | try sema.checkNullableType(block, src, sema.typeOf(ptr).elemType2(zcu)); |
| 19346 | | if ((try sema.resolveValue(ptr)) == null) { |
| 19347 | | return block.addUnOp(.is_non_null_ptr, ptr); |
| 19347 | if (try sema.resolveValue(ptr)) |ptr_val| { |
| 19348 | if (try sema.pointerDeref(block, src, ptr_val, ptr_ty)) |loaded_val| { |
| 19349 | return sema.analyzeIsNull(block, Air.internedToRef(loaded_val.toIntern()), true); |
| 19350 | } |
| 19348 | 19351 | } |
| 19349 | | const loaded = try sema.analyzeLoad(block, src, ptr, src); |
| 19350 | | return sema.analyzeIsNull(block, src, loaded, true); |
| 19352 | if (ptr_ty.childType(zcu).isNullFromType(zcu)) |is_null| { |
| 19353 | return if (is_null) .bool_false else .bool_true; |
| 19354 | } |
| 19355 | return block.addUnOp(.is_non_null_ptr, ptr); |
| 19351 | 19356 | } |
| 19352 | 19357 | |
| 19353 | 19358 | fn checkErrorType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void { |
| ... | ... | @@ -32405,7 +32410,6 @@ fn analyzeSliceLen( |
| 32405 | 32410 | fn analyzeIsNull( |
| 32406 | 32411 | sema: *Sema, |
| 32407 | 32412 | block: *Block, |
| 32408 | | src: LazySrcLoc, |
| 32409 | 32413 | operand: Air.Inst.Ref, |
| 32410 | 32414 | invert_logic: bool, |
| 32411 | 32415 | ) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -32421,15 +32425,10 @@ fn analyzeIsNull( |
| 32421 | 32425 | return if (bool_value) .bool_true else .bool_false; |
| 32422 | 32426 | } |
| 32423 | 32427 | |
| 32424 | | const inverted_non_null_res: Air.Inst.Ref = if (invert_logic) .bool_true else .bool_false; |
| 32425 | | const operand_ty = sema.typeOf(operand); |
| 32426 | | if (operand_ty.zigTypeTag(zcu) == .optional and operand_ty.optionalChild(zcu).zigTypeTag(zcu) == .noreturn) { |
| 32427 | | return inverted_non_null_res; |
| 32428 | if (sema.typeOf(operand).isNullFromType(zcu)) |is_null| { |
| 32429 | const result = is_null != invert_logic; |
| 32430 | return if (result) .bool_true else .bool_false; |
| 32428 | 32431 | } |
| 32429 | | if (operand_ty.zigTypeTag(zcu) != .optional and !operand_ty.isPtrLikeOptional(zcu)) { |
| 32430 | | return inverted_non_null_res; |
| 32431 | | } |
| 32432 | | try sema.requireRuntimeBlock(block, src, null); |
| 32433 | 32432 | const air_tag: Air.Inst.Tag = if (invert_logic) .is_non_null else .is_null; |
| 32434 | 32433 | return block.addUnOp(air_tag, operand); |
| 32435 | 32434 | } |
| ... | ... | @@ -33007,7 +33006,7 @@ fn analyzeSlice( |
| 33007 | 33006 | if (block.wantSafety()) { |
| 33008 | 33007 | // requirement: slicing C ptr is non-null |
| 33009 | 33008 | if (ptr_ptr_child_ty.isCPtr(zcu)) { |
| 33010 | | const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true); |
| 33009 | const is_non_null = try sema.analyzeIsNull(block, ptr, true); |
| 33011 | 33010 | try sema.addSafetyCheck(block, src, is_non_null, .unwrap_null); |
| 33012 | 33011 | } |
| 33013 | 33012 | |
| ... | ... | @@ -33065,7 +33064,7 @@ fn analyzeSlice( |
| 33065 | 33064 | if (block.wantSafety()) { |
| 33066 | 33065 | // requirement: slicing C ptr is non-null |
| 33067 | 33066 | if (ptr_ptr_child_ty.isCPtr(zcu)) { |
| 33068 | | const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true); |
| 33067 | const is_non_null = try sema.analyzeIsNull(block, ptr, true); |
| 33069 | 33068 | try sema.addSafetyCheck(block, src, is_non_null, .unwrap_null); |
| 33070 | 33069 | } |
| 33071 | 33070 | |