Commit graph

8156 commits

Author SHA1 Message Date
Alex Rønne Petersen
bf13b6b41d
test: partially disable cmakedefine standalone test
https://codeberg.org/ziglang/zig/issues/31368
2026-03-01 11:53:05 +01:00
Alex Rønne Petersen
b781615e09
test: disable an error trace test on optimized aarch64-freebsd 2026-02-27 08:49:27 +01:00
Andrew Kelley
e0173c2ce0 Merge pull request 'rework fuzz testing to be smith based' (#31205) from gooncreeper/zig:integrated-smith into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31205
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-25 20:23:36 +01:00
Justus Klausecker
360bc28c96 fix cmpxchg behavior test
This has to be a `@cmpxchgStrong` instead of a `@cmpxchgWeak` otherwise
this test will fail spuriously on LL/SC architectures like PowerPC.
2026-02-23 21:13:26 +01:00
Kendall Condon
5d58306162 rework fuzz testing to be smith based
-- On the standard library side:

The `input: []const u8` parameter of functions passed to `testing.fuzz`
has changed to `smith: *testing.Smith`. `Smith` is used to generate
values from libfuzzer or input bytes generated by libfuzzer.

`Smith` contains the following base methods:
* `value` as a generic method for generating any type
* `eos` for generating end-of-stream markers. Provides the additional
  guarantee `true` will eventually by provided.
* `bytes` for filling a byte array.
* `slice` for filling part of a buffer and providing the length.

`Smith.Weight` is used for giving value ranges a higher probability of
being selected. By default, every value has a weight of zero (i.e. they
will not be selected). Weights can only apply to values that fit within
a u64. The above functions have corresponding ones that accept weights.
Additionally, the following functions are provided:
* `baselineWeights` which provides a set of weights containing every
  possible value of a type.
* `eosSimpleWeighted` for unique weights for `true` and `false`
* `valueRangeAtMost` and `valueRangeLessThan` for weighing only a range
  of values.

-- On the libfuzzer and abi side:

--- Uids

These are u32s which are used to classify requested values. This solves
the problem of a mutation causing a new value to be requested and
shifting all future values; for example:

1. An initial input contains the values 1, 2, 3 which are interpreted
as a, b, and c respectively by the test.

2. The 1 is mutated to a 4 which causes the test to request an extra
value interpreted as d. The input is now 4, 2, 3, 5 (new value) which
the test corresponds to a, d, b, c; however, b and c no longer
correspond to their original values.

Uids contain a hash component and type component. The hash component
is currently determined in `Smith` by taking a hash of the calling
`@returnAddress()` or via an argument in the corresponding `WithHash`
functions. The type component is used extensively in libfuzzer with its
hashmaps.

--- Mutations

At the start of a cycle (a run), a random number of values to mutate is
selected with less being exponentially more likely. The indexes of the
values are selected from a selected uid with a logarithmic bias to uids
with more values.

Mutations may change a single values, several consecutive values in a
uid, or several consecutive values in the uid-independent order they
were requested. They may generate random values, mutate from previous
ones, or copy from other values in the same uid from the same input or
spliced from another.

For integers, mutations from previous ones currently only generates
random values. For bytes, mutations from previous mix new random data
and previous bytes with a set number of mutations.

--- Passive Minimization

A different approach has been taken for minimizing inputs: instead of
trying a fixed set of mutations when a fresh input is found, the input
is instead simply added to the corpus and removed when it is no longer
valuable.

The quality of an input is measured based off how many unique pcs it
hit and how many values it needed from the fuzzer. It is tracked which
inputs hold the best qualities for each pc for hitting the minimum and
maximum unique pcs while needing the least values.

Once all an input's qualities have been superseded for the pcs it hit,
it is removed from the corpus.

-- Comparison to byte-based smith

A byte-based smith would be much more inefficient and complex than this
solution. It would be unable to solve the shifting problem that Uids
do. It is unable to provide values from the fuzzer past end-of-stream.
Even with feedback, it would be unable to act on dynamic weights which
have proven essential with the updated tests (e.g. to constrain values
to a range).

-- Test updates

All the standard library tests have been updated to use the new smith
interface. For `Deque`, an ad hoc allocator was written to improve
performance and remove reliance on heap allocation. `TokenSmith` has
been added to aid in testing Ast and help inform decisions on the smith
interface.
2026-02-13 22:12:19 -05:00
Kendall Condon
5b9bb0a404 add -Dfuzz-only
Runs only one configuration suitable for fuzzing.
2026-02-13 17:58:09 -05:00
kj4tmp@gmail.com
3dc2a1f9ac zig libc: acosf 2026-02-13 11:30:14 -08:00
Andrew Kelley
0de7668c01 test harness: refmt for readability 2026-02-12 13:14:51 -08:00
GasInfinity
a6f64096a1
chore(test/standalone): test linking libc in a shared library 2026-02-11 15:48:18 +01:00
Jacob Young
b5bd494606 std.Threaded: replace more kernel32 functions with ntdll 2026-02-07 00:02:50 -05:00
Ryan Liptak
bcb5218a2b Environ: reinstate null return on = in environment variable keys
Changes an assert back into a conditional to match the behavior of `getPosix`, see https://codeberg.org/ziglang/zig/pulls/31113#issuecomment-10371698 and https://github.com/ziglang/zig/issues/23331.
Note: the conditional has been updated to also return null early on 0-length key lookups, since there's no need to iterate the block in that case.

For `Environ.Map`, validation of keys has been split into two categories: 'put' and 'fetch', each of which are tailored to the constraints that the implementation actually relies upon. Specifically:
- Hashing (fetching) requires the keys to be valid WTF-8 on Windows, but does not rely on any other properties of the keys (attempting to fetch `F\x00=` is not a problem, it just won't be found)
- `create{Posix,Windows}Block` relies on the Map to always have fully valid keys (no NUL, no `=` in an invalid location, no zero-length keys), which means that the 'put' APIs need to validate that incoming keys adhere to those properties.
The relevant assertions are now documented on each of the Map functions.

Also reinstates some test cases in the `env_vars` standalone test. Some of the reinstated tests are effectively just testing the Environ.Map implementation due to how `Environ.contains`, `Environ.getAlloc`, etc are implemented, but that is not inherent to those functions so the tests are still potentially relevant if e.g. `contains` is implemented in terms of `getPosix`/`getWindows` in the future (which is totally possible and maybe a good idea since constructing the whole map is not necessary for looking up one key).
2026-02-05 20:24:31 +01:00
Andrew Kelley
2a193a3987 std: move GetFinalPathNameByHandle to Io.Threaded
unfortunately this function calls NtCreateFile so it has to participate
in cancelation
2026-02-04 16:27:13 -08:00
Jacob Young
ffc6da29e3 std.Io.Threaded: implement and cleanup windows codepaths 2026-02-04 14:15:41 -05:00
Alex Rønne Petersen
fce7878a91
test: disable hexagon-linux-musl C ABI tests for now
https://gitlab.com/qemu-project/qemu/-/issues/3291
2026-02-04 11:11:39 +01:00
Alex Rønne Petersen
2fce12b42a test: improve logic for generating stack trace test combinations 2026-02-03 20:19:15 +01:00
Ryan Liptak
05346e123b Add process.Child.Cwd, use it for cwd and remove cwd_dir field
The user must now explicitly choose between inheriting the current CWD, passing a path for the CWD, or passing a Dir for the CWD.
2026-02-02 01:41:35 -08:00
Jeff Anderson
379d128cba libzigc: roundf 2026-01-31 18:18:29 -08:00
Jeff Anderson
69a95571ed libzigc: round 2026-01-31 17:26:17 -08:00
kj4tmp@gmail.com
e60ba21114 libzigc: roundl 2026-02-01 00:59:35 +01:00
Andrew Kelley
b1d1806fef std.process: currentDir -> currentPath
In Zig standard library, Dir means an open directory handle. path
represents a file system identifier string. This function is better
named after "current path" than "current dir". "get" and "working" are
superfluous.
2026-01-29 18:47:58 -08:00
Andrew Kelley
649aaf4814 std: migrate getcwd to Io
progress towards #30150
2026-01-29 18:40:55 -08:00
Andrew Kelley
9b415761dd std.os.windows: delete unused APIs
Intention is to go through std.Io for these things.
2026-01-30 03:39:46 +01:00
Andrew Kelley
5571c08e66 add behavior test for i96 operations 2026-01-29 19:57:36 +01:00
Andrew Kelley
4d6f4e9cfd behavior: add coverage for extern struct field overalignment 2026-01-29 19:56:46 +01:00
Ryan Liptak
1655a666d5 windows_resources standalone test: Load a resource and check its data
Just a potential way to catch regressions and to ensure the resources actually make it into the binary correctly.
2026-01-27 20:48:59 +01:00
Alex Rønne Petersen
e437efd601
test: enable thumb-windows-gnu module tests
We use long calls for these just like thumb*-linux-* to prevent range issues as
the binaries grow larger over time.

We also need function and data sections due to the many __stack_chk_guard
references within the std test binary; without these options, the linker is not
able to insert range thunks in between functions because the std binary just has
one giant .text section that's opaque to the linker.

closes https://codeberg.org/ziglang/zig/issues/30923
2026-01-23 21:16:03 +01:00
Alex Rønne Petersen
200fb7c2ac
test-libc: disable raise-race.c 2026-01-21 18:51:02 +01:00
Alex Rønne Petersen
34aa1bb94f
test-libc: enable loongarch64-linux-muslsf 2026-01-21 17:53:38 +01:00
Alex Rønne Petersen
eb3f16db5e
test: clarify that self_exe_symlink fails on NetBSD due to bad F_GETPATH
closes https://codeberg.org/ziglang/zig/issues/30841
2026-01-21 16:42:17 +01:00
Mathias Lafeldt
2207c62bb5 MachO: fix dynamic lookup of undefined symbols at runtime
Ensures `MH_NOUNDEFS` is not set when dynamic lookup is enabled for
undefined symbols via `linker_allow_shlib_undefined`.
2026-01-21 00:31:21 +01:00
rpkak
e6ac1b77f0
libzigc: test and fix acos 2026-01-20 18:02:15 +01:00
Alex Rønne Petersen
ac793232ee
test: skip non-libc module tests for targets that require or default to libc
We were just creating duplicate work and breaking -Dskip-libc.
2026-01-19 13:16:25 +01:00
Alex Rønne Petersen
b1b234daa0
test: disable self_exe_symlink standalone test on NetBSD
https://codeberg.org/ziglang/zig/issues/30841
2026-01-19 13:16:16 +01:00
Alex Rønne Petersen
016255ad09
test: disable an error trace test on optimized x86_64-netbsd 2026-01-19 13:16:11 +01:00
Vladislav Shabanov
63f345a75a link.MachO: support sdata4 pointer encoding (#30846)
Fixes https://codeberg.org/ziglang/zig/issues/30669

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30846
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Vladislav Shabanov <vshabanov88@gmail.com>
Co-committed-by: Vladislav Shabanov <vshabanov88@gmail.com>
2026-01-15 19:48:16 +01:00
Justus Klausecker
044ba3e0b0 Sema: fix single-range switch prong capture (for real this time)
e2338edb47 didn't *quite* do it, the call sites of all switch prong related
functions now have to do their part too and be a little more precise about
what kind of prong they're currently analyzing.

Also removes some unused/unnecessary stuff.
2026-01-13 06:03:07 +01:00
Justus Klausecker
e2338edb47 Sema: fix single-range switch prong capture
This kind of capture cannot always be comptime-known, assuming so caused
access of undefined memory during payload capture analysis!
2026-01-11 20:22:32 +01:00
Matthew Lugg
01546e68cd
compiler: handle switch rewrite review feedback 2026-01-11 14:37:28 +00:00
Justus Klausecker
dbfeade221
Sema: better switch_block_err_union result location if operand has wrong type
also fixes related test case and makes it run everywhere, not just on x86_64-linux!
2026-01-11 11:37:18 +00:00
Justus Klausecker
2e99c3042e
test: add some more switch regression tests
switch evaluation order, switch lazy value resolution
2026-01-11 11:37:18 +00:00
Justus Klausecker
0b3b536f18
test: re-enable packed struct field type behavior test
With new code courtesy of mlugg
2026-01-11 11:37:17 +00:00
Justus Klausecker
bce7e7a52b
AstGen: Re-allow labeled break from loop else block targeting its label
This fixes a regression from a couple of commits ago; breaking from the
`else` block of a loop to the loop's tag should be allowed when explicitly
targeting the label by name.
2026-01-11 11:37:17 +00:00
Justus Klausecker
39ca03e515
test: disable packed struct field type behavior test
This test was previously masked by a bug which prevented its evaluation.
Skipping it for now.
2026-01-11 11:37:17 +00:00
Justus Klausecker
b79bd31356
Sema: rework switch_block[_ref/_err_union] logic
This commit aims to simplify and de-duplicate the logic required for
semantically analyzing `switch` expressions.

The core logic has been moved to `analyzeSwitchBlock`, `resolveSwitchBlock`
and `finishSwitchBlock` and has been rewritten around the new iterator-based
API exposed by `Zir.UnwrappedSwitchBlock`.

All validation logic and switch prong item resolution have been moved to
`validateSwitchBlock`, which produces a `ValidatedSwitchBlock` containing
all the necessary information for further analysis.

`Zir.UnwrappedSwitchBlock`, `ValidatedSwitchBlock` and `SwitchOperand`
replace `SwitchProngAnalysis` while adding more flexibility, mainly for
better integration with `switch_block_err_union`.

`analyzeSwitchBlock` has an explicit code path for OPV types which lowers
them to either a `block`-`br` or a `loop`-`repeat` construct instead of a
switch. Backends expect `switch` to actually have an operand that exists
at runtime, so this is a bug fix and avoids further special cases in the
rest of the switch logic.
`resolveSwitchBlock` and `finishSwitchBr` exclusively deal with operands
which can have more than one value, at comptime and at runtime respectively.

This commit also reworks `RangeSet` to be an unmanaged container and adds
`Air.SwitchBr.BranchHints` to offload some complexity from Sema to there
and save a few bytes of memory in the process.

Additionally, some new features have been implemented:
- decl literals and everything else requiring a result type (`@enumFromInt`!)
  may now be used as switch prong items
- union tag captures are now allowed for all prongs, not just `inline` ones
- switch prongs may contain errors which are not in the error set being
  switched on, if these prongs contain `=> comptime unreachable`

and some bugs have been fixed:
- lots of issues with switching on OPV types are now fixed
- the rules around unreachable `else` prongs when switching on errors now
  apply to *any* switch on an error, not just to `switch_block_err_union`,
  and are applied properly based on the AST
- switching on `void` no longer requires an `else` prong unconditionally
- lazy values are properly resolved before any comparisons with prong items
- evaluation order between all kinds of switch statements is now the same,
  with or without label
2026-01-11 11:37:17 +00:00
Justus Klausecker
42dea36ce9
llvm: fix jump table gen for labeled switch with single else prong
Avoids a null unwrap if there are no cases with explicit values present
while trying to construct a jump table for a labeled switch statement.
2026-01-11 11:37:16 +00:00
Justus Klausecker
e0108dec54
AstGen: allow labels to provide separate break and continue targets
Enhances `GenZir` to allow labels to provide separate `break` and `continue`
target blocks and adds some more information on continue targets to
communicate whether the target is a switch block or cannot be targeted by
`continue` at all.

The main motivation is enabling this:
```
const result: u32 = operand catch |err| label: switch (err) {
    else => continue :label error.MyError,
    error.MyError => break :label 1,
};
```
to be lowered to something like this:
```
%1 = block({
  %2 = is_non_err(%operand)
  %3 = condbr(%2, {
    %4 = err_union_payload_unsafe(%operand)
    %5 = break(%1, result) // targets enclosing `block`
  }, {
    %6 = err_union_code(%operand)
    %7 = switch_block(%6,
      else => {
        %8 = switch_continue(%7, "error.MyError") // targets `switch_block`
      },
      "error.MyError" => {
        %9 = break(%1, @one) // targets enclosing `block`
      },
    )
    %10 = break(%1, @void_value)
  })
})
```
which makes the non-error case and all breaks from switch prongs, but not
continues from switch prongs, peers.

This is required to avoid the problems described in gh#11957 for labeled
switches without having to introduce a fairly complex special case to the
`switch_block_err_union` logic. Since this construct is very rare in practice,
introducing this additional complexity just to save a few ZIR bytes is
likely not worth it, so the simplified lowering described above will be
used instead.

As a nice bonus, AstGen can now also detect a `continue` trying to target
a labeled block and emit an appropriate error message.
2026-01-11 11:37:16 +00:00
David Rubin
aa2b178029
disallow switch case capture discards
Previously Zig allowed you to write something like,
```zig
switch (x) {
    .y => |_| {
```

This seems a bit strange because in other cases, such as when
capturing the tag in a switch case,
```zig
switch (x) {
    .y => |_, _| {
```
this produces an error.

The only usecase I can think of for the previous behaviour is
if you wanted to assert that all union payloads are able
to coerce,
```zig
const X = union(enum) { y: u8, z: f32 };

switch (x) {
    .y, .z => |_| {
```

This will compile-error with the `|_|` and pass without it.

I don't believe this usecase is strong enough to keep the current
behaviour; it was never used in the Zig codebase and I cannot
find a single usage of this behaviour in the real world, searching
through Sourcegraph.
2026-01-11 11:37:16 +00:00
Jay Petacat
484cc15366 Sema: Allow small integer types to coerce to floats
If the float can store all possible values of the integer without
rounding, coercion is allowed. The integer's precision must be less than
or equal to the float's significand precision.

Closes #18614
2026-01-10 22:19:20 +01:00
rpkak
b94a65ed40
test-libc: run some math tests 2026-01-10 00:09:54 +01:00
Alex Rønne Petersen
d1be8b138e Merge pull request 'enable x86_64-openbsd CI' (#30733) from alexrp/zig:openbsd-ci into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30733
2026-01-08 12:35:11 +01:00