Commit Graph

8232 Commits

Author SHA1 Message Date
pentuppup 6193470cee error on tuples in extern contexts 2026-04-08 15:22:48 +02:00
Neel 86853ba0a4 Add RISC-V ABI register alias names for inline asm clobbers 2026-04-08 14:37:48 +02:00
Jan200101 9fd63daff2 std.Build.Step.ConfigHeader: handle leading whitespace for cmake 2026-04-08 14:24:48 +02:00
Alex Rønne Petersen a38c6bbcc4 test: disable incremental tests on x86_64-windows-selfhosted
https://codeberg.org/ziglang/zig/issues/31773
2026-04-06 23:04:14 +02:00
Pavel Verigo ad7a028228 stage2-wasm: pass incremental tests
This PR enables all incremental tests under the `test/incremental` directory, except one: `change_exports`, which is currently ignored as it requires a non-trivial amount of work on the linker, since we do not currently support exporting data symbols.

To enable the other tests, the following fixes were needed:

1. `src/link/Wasm.zig`: instead of chasing function type through Nav, get it directly.
2. `src/target.zig`: `.panic_fn` appears to work fine with the wasm backend.
3. `src/codegen/wasm/CodeGen.zig`: there was a liveness related bug that caused some `ArenaAllocator` code to crash the backend.

More info on (3), the liveness and local reuse code in the backend for years in unfinished state. For example there is currently no branch merging and reuse happens only when inst die in same block level. I initially considered doing a large refactor to implement everything correctly, but aborted due to its sheer size and currently! no clear idea about how to do this efficiently.

Instead, I fixed the bug with minimal changes and removed useless code, keeping the old solution otherwise intact.
2026-04-04 15:21:35 +02:00
rpkak 90ccd6051c test-libc: do not skip search_hsearch on wasi-libc
emmalloc is not used anymore
2026-04-03 13:28:33 +02:00
Kendall Condon d8ba173e5e multiprocess fuzzing
- New Features

-- Multiprocess Fuzzing

The fuzzer now is able to utilize multiple cores. This is controllable
with the `-j` build option. Limited fuzzing still uses one core.

-- Fuzzing Infinite Mode

When provided multiple tests, the fuzzer now switches between them and
prioritizes the most effective and interesting ones. Over time already
explored tests will become barely run compared to tests yielding new
inputs.

-- Crash Dumps

Crashing inputs are now saved to a file indicated by the crash message.
It is recommended to use these files to reproduce the crash using
`std.testing.FuzzInputOptions.corpus` and @embedFile.

- Design

Each fuzzing process is assigned an instance id which has the following
uses:
* In conjunction with the pc hash and running test index, they uniquely
  identify input files in the case of a crash.
* It is combined with the test seed for a unique rng seed.
* Instance 0 is solely responsible for syncing the filesystem corpus.

When new inputs are found, they are sent to the build server. It then
distributes the new input to the other instances. Each instance has a
concurrent poller managed by the test runner which sends received
inputs to libfuzzer. (note that this is affected by #31718 and so can
(rarely) deadlock)

For fuzzing infinite mode, the test runner now receives a list of tests
from the build server. The fuzzer runs tests in batches of one second,
approximated in cycles by the previous batch's run speed. Tests finding
new inputs or with few runs are given a higher run chance. The baseline
run chance is based off the recency of the last find and the number of
pcs the test has hit.
2026-04-03 12:27:34 +02:00
mihael e15d8dd3d2 libc-test/math: Enable rint tests
The `rint` tests were commented out when added along with other functions to
the `libc-test` runner, presumably because they were failing. In the meantime,
we moved to using a Zig-implemented `rint` and I found that the tests are now
passing. To celebrate, I'm putting them back into commission.

Having these tests in a working state is nice because functions like `lrint`,
`llrint`, and `nearbyint` depend on `rint` implementation being correct.

Results:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=rint -fqemu -fwasmtime --summary line
Build Summary: 2209/2209 steps succeeded
```
2026-04-02 23:54:19 +02:00
Alex Rønne Petersen 7f3c1329f8 libc-test: disable pthread_cond-smasher.c
Prone to flaky timeouts under heavy load.
2026-04-02 20:53:45 +02:00
Pavel Verigo 557caecaaa stage2-wasm: start big int support 2026-04-02 15:48:43 +02:00
Andrew Kelley 3e0f55fcc7 Merge pull request 'add an ast smith' (#31635) from gooncreeper/zig:ast-smith into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31635
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-02 15:41:05 +02:00
badayvedat 6cdd576d41 libzigc: fdim 2026-04-02 14:50:19 +02:00
Jacob Young 28ae5d4158 llvm: fix missing return attributes
Closes #31636
2026-04-02 14:31:12 +02:00
Alex Rønne Petersen dd10d3fb52 libc-test: disable pthread_cancel-points.c
This test is racey if multiple instances of it run concurrently.
2026-04-02 12:33:19 +02:00
Matthew Lugg abaf3dfbe9 tests: fix wouldUseLlvm on x86_64-windows 2026-03-28 19:25:01 +00:00
Matthew Lugg 2ac47fe314 tests: disable safe compiler-rt tests on LLVM
Disabling due to multiple LLVM bugs:
* https://codeberg.org/ziglang/zig/issues/31701
* https://codeberg.org/ziglang/zig/issues/31702
2026-03-28 19:25:01 +00:00
Matthew Lugg 29faeeee9d tests: fix passing -fno-builtin to module tests 2026-03-28 16:50:43 +00:00
Matthew Lugg 4a494a8cf9 tests: enable incremental tests for x86_64-linux-llvm
These all pass now! I have also removed the warning about the LLVM
backend not supporting incremental compilation; I expect it will work
sort of okay in practice by now.
2026-03-28 16:50:43 +00:00
Alex Rønne Petersen 49fa67d826 fixup 58490f588c 2026-03-27 02:49:12 +01:00
Alex Rønne Petersen 58490f588c test: disable standalone test run_output_caching on windows
https://codeberg.org/ziglang/zig/issues/31564
2026-03-27 02:24:23 +01:00
Alex Rønne Petersen 6bdb45beaf test: don't run test-zigc on targets that don't support libzigc 2026-03-26 08:48:38 +01:00
Alex Rønne Petersen a216c74131 test: partial revert of ac793232ee
This is just obviously wrong?! I'm fairly certain I didn't intend to push that
commit in that state.
2026-03-26 05:50:51 +01:00
Alex Rønne Petersen cef16b5130 std.Target: don't claim that OpenBSD requires libc
https://codeberg.org/ziglang/zig/issues/30982
2026-03-26 05:50:51 +01:00
Kendall Condon ebca8c2dbb x86_64: fix runtime array concat with comptime slice 2026-03-25 17:27:18 -04:00
squidy239 4c3877069d remove various workarounds for issues that are now fixed (#31567)
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31567
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: squidy239 <sachabarsayuracko@gmail.com>
Co-committed-by: squidy239 <sachabarsayuracko@gmail.com>
2026-03-20 19:58:33 +01:00
Jacob Young 3c8b96df6d windows: use enums for boolean types 2026-03-20 02:25:16 +01:00
Matthew Lugg 10d523f068 Air.Legalize: fix typo in bitcast legalization
A typo meant that the legalization of vector `@bitCast` was literally
just not considering the operand. Oops!

We had a behavior test which should have caught this, but it wasn't
really testing the right thing, so failed to do so. I've updated it to
test what it's supposed to test, so it fails before this patch and
passes after this patch.

Resolves: https://github.com/ziglang/zig/issues/26008
2026-03-19 15:41:22 +00:00
Jacob Young 9ac1386c10 std.Io.Threaded: windows networking without ws2_32 2026-03-18 20:13:59 -04:00
Justus Klausecker c10089d060 test: enable 'switch arbitrary int size' behavior test for cbe
was disabled in b25d93e7d9
2026-03-18 16:57:40 +01:00
Justus Klausecker 0b857eebeb test: disable 'switch on large types' behavior tests for wasm backend
The self-hosted wasm backend doesn't properly support very large integers yet.
2026-03-18 15:49:14 +01:00
Justus Klausecker dbe787a984 Revert "test: disable switch behavior test switching on type >64bits for cbe"
This reverts commit e91654b1e7.
2026-03-18 15:49:14 +01:00
Justus Klausecker 047df44d71 cbe: fix switch statements on large types
`switch` statements on types >128bits are now lowered to conditionals.
This is necessary because Zig lowers integers with more than 128 bits to
bigints, which are not 'native' integers and thus cannot be used as case
values.
128-bit integers get special treatment because Zig will emit actual 128bit
ints if they are supported by the target. They still *may* be lowered to
bigints though, e.g. for 32-bit targets or MSVC. To solve this, this commit
adds a bunch of switch macros to `zig.h` which will either resolve to an
actual `switch` statement or to conditionals. The `if` statements this
approach can generate are not as optimal as they could be but I think this
is a good trade-off since the generated `switch` statements are still the
same as the ones generated for smaller integers. Also the macros result
in pretty readable code.
2026-03-18 15:47:18 +01:00
Techatrix 097ca369d5 detect when switch on error shadows it's own switch case capture 2026-03-17 02:05:31 +01:00
Justus Klausecker 524345b635 Sema: handle containers as inline assembly output types correctly
Inline assembly now rejects output types that don't have a well-defined
in-memory layout and correctly resolves the layout of the ones that do.
2026-03-17 01:51:55 +01:00
mlugg abd099e97f Merge pull request 'compiler: fix missing "local variable is never mutated" error' (#31534) from variable-not-mutated into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31534
2026-03-16 00:05:30 +01:00
pentuppup 2383709431 coerce assembly clobbers in sema 2026-03-15 22:37:38 +01:00
Jan200101 43d5bea7af test: use expectEqualStrings to check cmakedefine behavior
this has the added benefit of outputting the difference making it
easier to figure out why the test is flakey.

https://codeberg.org/ziglang/zig/issues/31368
2026-03-15 21:41:37 +01:00
Matthew Lugg 827a96b1ef compiler: fix missing "local variable is never mutated" error
This regressed back in https://github.com/ziglang/zig/pull/25154. I
didn't get around to fixing it until now, so a few instances of the
warning snuck into the repo over the past few months, which were fixed
in the previous commit. The regression has not appeared in a tagged
release though, so this is not a breaking change in 0.16.0.

Resolves: https://codeberg.org/ziglang/zig/issues/31049
2026-03-15 18:24:32 +00:00
David Rubin 50cc3b91a5 Sema: coerce tail call result to immediate function 2026-03-14 05:23:13 -07:00
Matthew Lugg 0978566db8 incremental: handle loss of main struct instruction
My changes to how incremental compilation handles container types mean
that, at least for now, it is possible for the ZIR `.main_struct_inst`
of a source file to be lost (this happens if the number of top-level
fields in a file changes for instance). I missed a few things which
needed changing to account for this, which could lead to crashes with
certain (trivial) changes---oops!

Adds two new incremental test cases. They are currently disabled for
wasm32-wasi-selfhosted because they both trigger a crash in the WASM
backend.
2026-03-12 21:27:16 +01:00
Justus Klausecker 499aba9ca6 Sema: require else prong for comptime_int
This fixes a bug introduced a couple of commits ago.
2026-03-12 21:03:16 +01:00
Andrew Kelley d5bfa657c4 Merge pull request 'fix several fuzzing bugs' (#31470) from gooncreeper/zig:fuzzing-fixes into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31470
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-12 20:25:02 +01:00
Kendall Condon c3e6ff7206 libfuzzer: use error.SkipZigTest 2026-03-11 21:14:46 -04:00
Andrew Kelley 58890066d9 Merge pull request 'Sema: Support peer type resolution for floats and small integers' (#30921) from jayschwa/zig:ptr-small-int-and-floats into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30921
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-12 00:41:05 +01:00
Andrew Kelley 109d01371e Merge pull request 'Sema: implement switch for packed structs/unions' (#31464) from justusk/zig:packed-switch into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31464
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-12 00:39:19 +01:00
Pavel Verigo 2802276091 stage2-wasm: address TODO in instruction selection code
This PR started as addressing the long-standing TODO above `buildOpcode`:

    /// TODO: deprecated, should be split up per tag.

The code around this area was written a long time ago and has effectively
become a legacy approach. When I started doing semi-occasional work for
bringing >128-bit integer operations to the wasm backend, which is
the last big missing piece of this backend, this design became annoying.

While thinking about how to support that work, and also how vector unrolling
should be handled (in cases where we do not rely purely on the legalize pass),
I decided to do some architectural changes were needed.

The first step is removing helpers like `intBinOp`, `floatBinOp`, `UnOp`, etc.
They do not really capture all operations and resulted in a lot of small
pieces of code trying to artificially unify different ops.

Instead, the direction taken here is similar to `Sema/arith.zig`,  introduce
backend-oriented helpers such as `int*Op*Scalar` and `float*Op*` that operate
purely in backend structures without referencing AIR at all.

Additionally, the idea of introducing dedicated `IntType` and `FloatType`
types was chosen. Using `Type` from Sema inside the backend is awkward,
especially when strange or temporary types are needed. Creating them through
`PerThread` is also undesirable since the backend strives to not modify
`InternPool`. This goal is not fully achieved yet, some parts still require
changes, and `InternPool` type formatting still requires `pt` for error
reporting.

This PR also enables legalize passes for some packed operations. The previous
code in this area was buggy, and given the current state of the backend,
relying on legalization is simpler.

Finally, this PR disables one behavior test: `atomicrmw` with floats. The test
seems to only run the non-concurrency path, because it would crash otherwise,
and since we do not currently run behavior tests for the self-hosted backend
with concurrency or atomics enabled, it does not provide meaningful coverage yet.

In summary, this refactor reworks instruction selection in the wasm backend
to simplify the code and make future work, especially adding big integer
support.
2026-03-11 22:46:58 +01:00
Justus Klausecker e91654b1e7 test: disable switch behavior test switching on type >64bits for cbe
workaround for #31467
2026-03-11 21:14:43 +01:00
Justus Klausecker 28886ca9ec Sema: implement switch for packed structs/unions
Since packed containers are now represented by `bitpack` and can't include
pointers anymore this has become a very easy change to make. This commit
largely just reuses the logic already in place for integers.

Also fixes a small bug where captures-by-ref of errors wouldn't cause a
compile error for regular switch statements. There was already an astgen
error in place for error handling switch statements (`switch_block_err_union`)
capturing their error by reference.
2026-03-11 21:04:04 +01:00
Jay Petacat fcf64761d0 Sema: Support peer type resolution for floats and small integers
This builds on the changes in PR #30053 / commit 484cc15366.

Previously, peer type resolution would always result in a conflict for
fixed-width integer and float types. Now that small integer types can
coerce to floats, peer type resolution can take that into account. This
primarily benefits arithmetic with mixed float and integer operands. If
the integer operand can coerce to the float operand's type, it will do
so without requiring an explicit cast. If the integer type can't coerce,
there will be a compiler error; no float widening will occur. Explicit
casting will still be required to make it work.
2026-03-11 11:31:58 -06:00
Jay Petacat 89c98e2001 Sema: fix integer coercion to c_longdouble
This is a follow-up to PR #30053 / commit 484cc15366.

The code previously did not handle `c_longdouble`, whose size depends on
the target. A `floatSignificandBits` helper function and a smoke test
were added.

Also added the missing max int value to the exhaustive `f16` test cases.
2026-03-11 10:24:42 -06:00