0
Fork 0
mirror of https://codeberg.org/ziglang/zig synced 2026-11-18 07:05:05 +00:00
zig/test/behavior
Isaac Freund 23b7d28896 std: restrict mem.span() and mem.len() to sentinel terminated pointers
These functions are currently footgunny when working with pointers to
arrays and slices. They just return the stated length of the array/slice
without iterating and looking for the first sentinel, even if the
array/slice is a sentinel terminated type.

From looking at the quite small list of places in the standard
library/compiler that this change breaks existing code, the new code
looks to be more readable in all cases.

The usage of std.mem.span/len was totally unneeded in most of the cases
affected by this breaking change.

We could remove these functions entirely in favor of other existing
functions in std.mem such as std.mem.sliceTo(), but that would be a
somewhat nasty breaking change as std.mem.span() is very widely used for
converting sentinel terminated pointers to slices. It is however not at
all widely used for anything else.

Therefore I think it is better to break these few non-standard and
potentially incorrect usages of these functions now and at some later
time, if deemed worthwhile, finally remove these functions.

If we wait for at least a full release cycle so that everyone adapts to
this change first, updating for the removal could be a simple find and
replace without needing to worry about the semantics.
History 2023-01-29 15:07:06 -05:00
..
bugs Sema: handle lazy values in more places 2023-01-22 00:12:36 +02:00
hasdecl move behavior tests from test/stage1/ to test/ 2021-04-29 15:54:04 -07:00
import move behavior tests from test/stage1/ to test/ 2021-04-29 15:54:04 -07:00
namespace_depends_on_compile_var move behavior tests from test/stage1/ to test/ 2021-04-29 15:54:04 -07:00
pub_enum move behavior tests from test/stage1/ to test/ 2021-04-29 15:54:04 -07:00
usingnamespace stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
align.zig target: use 16 byte alignment for 128-bit types on x86 and ofmt .c 2023-01-23 13:48:37 -05:00
alignof.zig stage2 AArch64: unify callee-preserved regs on all targets 2022-12-27 21:17:52 +08:00
array.zig add tests for fixed stage1 bugs 2022-12-31 20:49:02 -05:00
asm.zig avoid testing inline for in unrelated behavior tests 2023-01-02 14:09:01 -07:00
async_fn.zig remove references to stage1 in behavior tests 2022-12-06 19:06:48 -07:00
atomics.zig fix behavior test compile error 2023-01-02 15:02:33 -07:00
await_struct.zig remove references to stage1 in behavior tests 2022-12-06 19:06:48 -07:00
basic.zig std: restrict mem.span() and mem.len() to sentinel terminated pointers 2023-01-29 15:07:06 -05:00
bit_shifting.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
bitcast.zig added test for bitcast signaled nan float 2023-01-20 16:42:24 +02:00
bitreverse.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
bool.zig C backend: fix @boolToInt 2021-10-28 17:33:05 -07:00
byteswap.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
byval_arg_var.zig stage2 AArch64: unify callee-preserved regs on all targets 2022-12-27 21:17:52 +08:00
call.zig add tests for fixed stage1 bugs 2022-12-31 20:49:02 -05:00
cast.zig add tests for fixed stage1 bugs 2022-12-31 20:49:02 -05:00
cast_int.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
comptime_memory.zig remove references to stage1 in behavior tests 2022-12-06 19:06:48 -07:00
const_slice_child.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
decltest.zig stage2: add decltests 2022-02-13 14:42:20 +02:00
defer.zig fix errdefers in functions that can't return errors 2023-01-10 19:17:42 +02:00
empty_file_level_struct.zig fix overflow found while fuzzing 2022-12-23 23:10:04 +02:00
empty_file_level_union.zig fix overflow found while fuzzing 2022-12-23 23:10:04 +02:00
empty_tuple_fields.zig fix overflow found while fuzzing 2022-12-23 23:10:04 +02:00
empty_union.zig stage2: fix onePossibleValue of empty unions and enums 2022-11-04 23:13:50 +02:00
enum.zig Sema: handle enum expressions referencing local variables 2023-01-05 22:03:32 +02:00
error.zig stage2 AArch64: bump up alignment of stack items fitting in regs 2023-01-03 19:56:09 +01:00
eval.zig add tests for fixed stage1 bugs 2022-12-31 20:49:02 -05:00
export.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
export_self_referential_type_info.zig behavior: fix redefined exports 2022-10-25 05:11:28 -04:00
field_parent_ptr.zig stage2 AArch64: implement field_parent_ptr 2022-12-27 21:26:18 +08:00
floatop.zig disable failing CBE behavior tests failing on aarch64-windows 2022-12-10 16:28:49 -07:00
fn.zig Sema: handle lazy values in more places 2023-01-22 00:12:36 +02:00
fn_delegation.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
fn_in_struct_in_comptime.zig Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen 2021-05-08 14:45:21 -07:00
for.zig add tests for fixed stage1 bugs 2022-12-29 12:42:44 +02:00
generics.zig std.builtin: remove layout field from Type.Enum 2022-12-18 13:31:38 +01:00
hasdecl.zig Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen 2021-05-08 14:45:21 -07:00
hasfield.zig Sema: make @hasField support tuples too 2022-03-11 12:59:20 -07:00
if.zig stage2 AArch64: implement errUnion{Err,Payload} for registers 2022-12-29 11:12:08 +01:00
import.zig lint: duplicate import (#10519) 2022-01-07 00:06:06 -05:00
incomplete_struct_param_tld.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
inline_switch.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
int128.zig cbe: fixes for x86 2023-01-23 13:48:36 -05:00
int_comparison_elision.zig Sema: elide integer comparisons with guaranteed outcomes 2022-12-15 00:56:27 -08:00
int_div.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
inttoptr.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
ir_block_deps.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
lower_strlit_to_vector.zig codegen - lower str_lit to vector 2022-12-16 06:08:10 -05:00
math.zig cbe: fixes for tls, support for not linking libc, and enabling tests 2023-01-29 15:04:13 -05:00
maximum_minimum.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
member_func.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
merge_error_sets.zig stage2 AArch64: unify callee-preserved regs on all targets 2022-12-27 21:17:52 +08:00
muladd.zig cbe: fixes for tls, support for not linking libc, and enabling tests 2023-01-29 15:04:13 -05:00
namespace_depends_on_compile_var.zig CBE: enable more tests that are currently passing 2022-03-17 11:39:56 -07:00
null.zig stage2 AArch64: unify callee-preserved regs on all targets 2022-12-27 21:17:52 +08:00
optional.zig add tests for fixed stage1 bugs 2022-12-29 12:42:44 +02:00
packed-struct.zig llvm: do not offset packed struct field pointers if they have a host size 2023-01-17 20:28:42 +02:00
packed_struct_explicit_backing_int.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
pointers.zig stage2 ARM: add basic debug info for locals 2023-01-22 12:00:04 +01:00
popcount.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
prefetch.zig stage1: implement @prefetch() builtin 2021-12-11 00:29:31 +01:00
ptrcast.zig add tests for fixed stage1 bugs 2022-12-29 12:42:44 +02:00
pub_enum.zig Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen 2021-05-08 14:45:21 -07:00
ref_var_in_if_after_if_2nd_switch_prong.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
reflection.zig std.builtin: rename Type.Fn's args to params 2022-12-17 14:11:33 +01:00
saturating_arithmetic.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
select.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
shuffle.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
sizeof_and_typeof.zig stage2 AArch64: unify callee-preserved regs on all targets 2022-12-27 21:17:52 +08:00
slice.zig add tests for fixed stage1 bugs 2022-12-31 20:49:02 -05:00
slice_sentinel_comptime.zig std, src, doc, test: remove unused variables 2021-06-21 17:03:03 -07:00
src.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
struct.zig Sema: resolve fields before checking tuple len 2023-01-22 00:12:37 +02:00
struct_contains_null_ptr_itself.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
struct_contains_slice_of_itself.zig stage2 AArch64: unify callee-preserved regs on all targets 2022-12-27 21:17:52 +08:00
switch.zig Sema: resolve lazy values in switch prong items 2023-01-17 20:28:43 +02:00
switch_prong_err_enum.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
switch_prong_implicit_cast.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
this.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
threadlocal.zig cbe: fixes for tls, support for not linking libc, and enabling tests 2023-01-29 15:04:13 -05:00
translate_c_macros.h Translate-C Remainder Macro Fix 2022-11-03 14:07:00 +02:00
translate_c_macros.zig add tests for fixed stage1 bugs 2022-12-31 20:49:02 -05:00
translate_c_macros_not_utf8.h translate-c: Escape non-ASCII characters that appear in macros 2022-09-10 01:50:17 +03:00
truncate.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
try.zig stage2 AArch64: implement errUnion{Err,Payload} for registers 2022-12-29 11:12:08 +01:00
tuple.zig add tests for fixed stage1 bugs 2022-12-31 20:49:02 -05:00
tuple_declarations.zig std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
type.zig std.builtin: remove layout field from Type.Enum 2022-12-18 13:31:38 +01:00
type_info.zig Sema: ignore dependency loops in typeinfo decls 2023-01-17 20:28:43 +02:00
typename.zig swap align and callconv in function typeName 2023-01-16 14:04:03 +02:00
undefined.zig stage2 AArch64: unify callee-preserved regs on all targets 2022-12-27 21:17:52 +08:00
underscore.zig stage2 AArch64: unify callee-preserved regs on all targets 2022-12-27 21:17:52 +08:00
union.zig add tests for fixed stage1 bugs 2022-12-31 20:49:02 -05:00
union_with_members.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
usingnamespace.zig stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
var_args.zig disable failing C var arg behavior tests 2022-12-27 23:13:03 -07:00
vector.zig Value: implement compareAllWithZero for bytes and str_lit 2023-01-22 00:12:37 +02:00
void.zig stage2 AArch64: unify callee-preserved regs on all targets 2022-12-27 21:17:52 +08:00
wasm.zig stage2: cleanups to wasm memory intrinsics 2022-03-03 18:31:55 -07:00
while.zig stage2 AArch64: implement errUnion{Err,Payload} for registers 2022-12-29 11:12:08 +01:00
widening.zig disable failing CBE behavior tests failing on aarch64-windows 2022-12-10 16:28:49 -07:00
wrapping_arithmetic.zig stage1: fix saturating arithmetic producing incorrect results on type comptime_int, allow saturating left shift on type comptime int 2022-01-29 18:12:28 +02:00