| ... | @@ -19964,6 +19964,14 @@ fn analyzeSlice( | ... | @@ -19964,6 +19964,14 @@ fn analyzeSlice( |
| 19964 | slice_ty = ptr_ptr_child_ty; | 19964 | slice_ty = ptr_ptr_child_ty; |
| 19965 | array_ty = ptr_ptr_child_ty; | 19965 | array_ty = ptr_ptr_child_ty; |
| 19966 | elem_ty = ptr_ptr_child_ty.childType(); | 19966 | elem_ty = ptr_ptr_child_ty.childType(); |
| | 19967 | |
| | 19968 | if (ptr_ptr_child_ty.ptrSize() == .C) { |
| | 19969 | if (try sema.resolveDefinedValue(block, ptr_src, ptr_or_slice)) |ptr_val| { |
| | 19970 | if (ptr_val.isNull()) { |
| | 19971 | return sema.fail(block, ptr_src, "slice of null pointer", .{}); |
| | 19972 | } |
| | 19973 | } |
| | 19974 | } |
| 19967 | }, | 19975 | }, |
| 19968 | .Slice => { | 19976 | .Slice => { |
| 19969 | ptr_sentinel = ptr_ptr_child_ty.sentinel(); | 19977 | ptr_sentinel = ptr_ptr_child_ty.sentinel(); |
| ... | @@ -20162,6 +20170,12 @@ fn analyzeSlice( | ... | @@ -20162,6 +20170,12 @@ fn analyzeSlice( |
| 20162 | | 20170 | |
| 20163 | try sema.requireRuntimeBlock(block, src); | 20171 | try sema.requireRuntimeBlock(block, src); |
| 20164 | if (block.wantSafety()) { | 20172 | if (block.wantSafety()) { |
| | 20173 | // requirement: slicing C ptr is non-null |
| | 20174 | if (ptr_ptr_child_ty.isCPtr()) { |
| | 20175 | const is_non_null = try sema.analyzeIsNull(block, ptr_src, ptr, true); |
| | 20176 | try sema.addSafetyCheck(block, is_non_null, .unwrap_null); |
| | 20177 | } |
| | 20178 | |
| 20165 | // requirement: end <= len | 20179 | // requirement: end <= len |
| 20166 | const opt_len_inst = if (array_ty.zigTypeTag() == .Array) | 20180 | const opt_len_inst = if (array_ty.zigTypeTag() == .Array) |
| 20167 | try sema.addIntUnsigned(Type.usize, array_ty.arrayLenIncludingSentinel()) | 20181 | try sema.addIntUnsigned(Type.usize, array_ty.arrayLenIncludingSentinel()) |