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
1687716877 }
1687816878
1687916879 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())) {
1688116881 if (!type_res.isAllowzeroPtr()) {
1688216882 const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize);
1688316883 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
1716917169 }
1717017170
1717117171 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 {
1717317175 const val_payload = try sema.arena.create(Value.Payload.U64);
1717417176 val_payload.* = .{
1717517177 .base = .{ .tag = .int_u64 },
......@@ -24489,7 +24491,9 @@ fn coerceCompatiblePtrs(
2448924491 try sema.requireRuntimeBlock(block, inst_src, null);
2449024492 const inst_ty = sema.typeOf(inst);
2449124493 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 {
2449324497 const actual_ptr = if (inst_ty.isSlice())
2449424498 try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty)
2449524499 else