Skip to content

Commit 75275a1

Browse files
committed
Sema: do not emit pointer safety checks for pointers to zero-bit types
1 parent 0daa77b commit 75275a1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Sema.zig

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

0 commit comments

Comments
 (0)