authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-06 15:22:14+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-08-06 15:22:14+03:00
log75275a1514b6954bed09c4c14a325e883a129c7b
tree97bee127e8f35247933251e0ed580b2b5f263ffe
parent0daa77bd63a3ef9666d5ccda40929403a4bb3305

Sema: do not emit pointer safety checks for pointers to zero-bit types


1 files changed, 7 insertions(+), 3 deletions(-)

src/Sema.zig+7-3
...@@ -16877,7 +16877,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16877,7 +16877,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16877 }16877 }
1687816878
16879 try sema.requireRuntimeBlock(block, src, operand_src);16879 try sema.requireRuntimeBlock(block, src, operand_src);
16880 if (block.wantSafety()) {16880 if (block.wantSafety() and try sema.typeHasRuntimeBits(block, sema.src, type_res.elemType2())) {
16881 if (!type_res.isAllowzeroPtr()) {16881 if (!type_res.isAllowzeroPtr()) {
16882 const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize);16882 const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize);
16883 try sema.addSafetyCheck(block, is_non_zero, .cast_to_null);16883 try sema.addSafetyCheck(block, is_non_zero, .cast_to_null);
...@@ -17169,7 +17169,9 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -17169,7 +17169,9 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
17169 }17169 }
1717017170
17171 try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);17171 try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src);
17172 if (block.wantSafety() and dest_align > 1) {17172 if (block.wantSafety() and dest_align > 1 and
17173 try sema.typeHasRuntimeBits(block, sema.src, dest_ty.elemType2()))
17174 {
17173 const val_payload = try sema.arena.create(Value.Payload.U64);17175 const val_payload = try sema.arena.create(Value.Payload.U64);
17174 val_payload.* = .{17176 val_payload.* = .{
17175 .base = .{ .tag = .int_u64 },17177 .base = .{ .tag = .int_u64 },
...@@ -24489,7 +24491,9 @@ fn coerceCompatiblePtrs(...@@ -24489,7 +24491,9 @@ fn coerceCompatiblePtrs(
24489 try sema.requireRuntimeBlock(block, inst_src, null);24491 try sema.requireRuntimeBlock(block, inst_src, null);
24490 const inst_ty = sema.typeOf(inst);24492 const inst_ty = sema.typeOf(inst);
24491 const inst_allows_zero = (inst_ty.zigTypeTag() == .Pointer and inst_ty.ptrAllowsZero()) or true;24493 const inst_allows_zero = (inst_ty.zigTypeTag() == .Pointer and inst_ty.ptrAllowsZero()) or true;
24492 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero()) {24494 if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero() and
24495 try sema.typeHasRuntimeBits(block, sema.src, dest_ty.elemType2()))
24496 {
24493 const actual_ptr = if (inst_ty.isSlice())24497 const actual_ptr = if (inst_ty.isSlice())
24494 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)24498 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)
24495 else24499 else