diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-08-06 15:22:14 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-08-06 15:22:14 +0300 |
| commit | 75275a1514b6954bed09c4c14a325e883a129c7b (patch) | |
| tree | 97bee127e8f35247933251e0ed580b2b5f263ffe /src/Sema.zig | |
| parent | 0daa77bd63a3ef9666d5ccda40929403a4bb3305 (diff) | |
| download | zig-75275a1514b6954bed09c4c14a325e883a129c7b.tar.gz zig-75275a1514b6954bed09c4c14a325e883a129c7b.zip | |
Sema: do not emit pointer safety checks for pointers to zero-bit types
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 56e08d081b..4c11894c24 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -16877,7 +16877,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai } try sema.requireRuntimeBlock(block, src, operand_src); - if (block.wantSafety()) { + if (block.wantSafety() and try sema.typeHasRuntimeBits(block, sema.src, type_res.elemType2())) { if (!type_res.isAllowzeroPtr()) { const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize); 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 } try sema.requireRuntimeBlock(block, inst_data.src(), ptr_src); - if (block.wantSafety() and dest_align > 1) { + if (block.wantSafety() and dest_align > 1 and + try sema.typeHasRuntimeBits(block, sema.src, dest_ty.elemType2())) + { const val_payload = try sema.arena.create(Value.Payload.U64); val_payload.* = .{ .base = .{ .tag = .int_u64 }, @@ -24489,7 +24491,9 @@ fn coerceCompatiblePtrs( try sema.requireRuntimeBlock(block, inst_src, null); const inst_ty = sema.typeOf(inst); const inst_allows_zero = (inst_ty.zigTypeTag() == .Pointer and inst_ty.ptrAllowsZero()) or true; - if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero()) { + if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero() and + try sema.typeHasRuntimeBits(block, sema.src, dest_ty.elemType2())) + { const actual_ptr = if (inst_ty.isSlice()) try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty) else |
