diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-04-24 16:23:03 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-24 16:23:03 -0700 |
| commit | a2fe81a63992aa8d0d9b56dfbb6ffe525fdc907a (patch) | |
| tree | 92e1179cff284e603aac60b3d68c6c9ada946474 /src/Sema.zig | |
| parent | bba90b8863102d75578d521cebdf4c2443451f59 (diff) | |
| parent | f1e43d1f4fde4f7b6909c660ec210f9b14cacb4d (diff) | |
| download | zig-a2fe81a63992aa8d0d9b56dfbb6ffe525fdc907a.tar.gz zig-a2fe81a63992aa8d0d9b56dfbb6ffe525fdc907a.zip | |
Merge pull request #15421 from Vexu/fixes
Runtime safety improvements
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index eed53a8264..ed36417876 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -19627,7 +19627,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai } try sema.requireRuntimeBlock(block, src, operand_src); - if (block.wantSafety() and try sema.typeHasRuntimeBits(elem_ty)) { + if (block.wantSafety() and (try sema.typeHasRuntimeBits(elem_ty) or elem_ty.zigTypeTag() == .Fn)) { if (!ptr_ty.isAllowzeroPtr()) { const is_non_zero = try block.addBinOp(.cmp_neq, operand_coerced, .zero_usize); try sema.addSafetyCheck(block, is_non_zero, .cast_to_null); @@ -19853,7 +19853,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air try sema.requireRuntimeBlock(block, src, null); if (block.wantSafety() and operand_ty.ptrAllowsZero() and !dest_ty.ptrAllowsZero() and - try sema.typeHasRuntimeBits(dest_ty.elemType2())) + (try sema.typeHasRuntimeBits(dest_ty.elemType2()) or dest_ty.elemType2().zigTypeTag() == .Fn)) { const ptr_int = try block.addUnOp(.ptrtoint, ptr); const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize); @@ -27742,7 +27742,7 @@ fn coerceCompatiblePtrs( try sema.requireRuntimeBlock(block, inst_src, null); const inst_allows_zero = inst_ty.zigTypeTag() != .Pointer or inst_ty.ptrAllowsZero(); if (block.wantSafety() and inst_allows_zero and !dest_ty.ptrAllowsZero() and - try sema.typeHasRuntimeBits(dest_ty.elemType2())) + (try sema.typeHasRuntimeBits(dest_ty.elemType2()) or dest_ty.elemType2().zigTypeTag() == .Fn)) { const actual_ptr = if (inst_ty.isSlice()) try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty) |
