diff options
| author | Veikka Tuominen <git@vexu.eu> | 2023-04-23 13:00:33 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2023-04-23 19:09:14 +0300 |
| commit | f1e43d1f4fde4f7b6909c660ec210f9b14cacb4d (patch) | |
| tree | 41b36885dbc1b57a82e505f4e3d8c1dae977d6d6 /src/Sema.zig | |
| parent | c3b30a0fd0b0f4f0bd8966cc8c5fadb028d0517e (diff) | |
| download | zig-f1e43d1f4fde4f7b6909c660ec210f9b14cacb4d.tar.gz zig-f1e43d1f4fde4f7b6909c660ec210f9b14cacb4d.zip | |
Sema: emit cast to null panics for function pointers
Closes #14676
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 5c19d37431..d5c3dbef6b 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -19626,7 +19626,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); @@ -19852,7 +19852,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); @@ -27718,7 +27718,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) |
