Commit graph

8132 commits

Author SHA1 Message Date
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
Andrew Kelley
520397b48f tests: delete redundant cases
These were originally supposed to be incremental test cases but have
long since been made redundant.
2026-01-07 17:33:06 -08:00
David Rubin
938efe4aab compiler-rt: fix f80 ceil/floor optimization
Our implementation did the classic add-sub rounding trick `(y = x +/- C =+ C - x)`
with `C = 1 / eps(T) = 2^(mantissa - 1)`. This approach only works for values whose
magnitude is below the rounding capacity of the constant. For a 64-bit mantissa
(like f80 has), `C = 2^63` only rounds for `|x| < 2^63`. Before we allowed this to
be ran on `e < bias + 64` aka `|x| < 2^64`. And because it isn't large enough,
we lose a bit to rounding.

For reference, the musl implementation does the same thing, using `mantissa - 1`:
https://git.musl-libc.org/cgit/musl/tree/src/math/ceill.c#n18
where `LDBL_MANT_DIG` is 64 for `long double` on x86.

This commit also combines the floor and ceil implementations into one generic one.
2026-01-08 00:45:52 +01:00
Andrew Kelley
5e5b328dac test-standalone: update cases from posix.getrandom 2026-01-07 11:03:37 -08:00
Andrew Kelley
1f1381a866 update API usage of std.crypto.random to io.random 2026-01-07 11:03:36 -08:00
Alex Rønne Petersen
4f8cfcbbfd
test: disable libfuzzer standalone test on OpenBSD
https://codeberg.org/ziglang/zig/issues/30728
2026-01-07 05:42:50 +01:00
Alex Rønne Petersen
4296ed9c42
test: skip self_exe_symlink on OpenBSD
realPath is unsupported.
2026-01-07 05:42:49 +01:00
Alex Rønne Petersen
bb46709762
test: disable an error trace test on optimized x86_64-openbsd 2026-01-07 05:42:49 +01:00
Alex Rønne Petersen
e226df2ed5 Merge pull request 'add OpenBSD libc cross-compilation support' (#30064) from alexrp/zig:openbsd into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30064
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
2026-01-06 16:12:54 +01:00
Ryan Liptak
52141fe85f standalone tests: Delete all ad hoc TmpDir instances, use the build system instead 2026-01-05 20:41:18 +01:00
Alex Rønne Petersen
00dc4d000f
test: add openbsd targets to module test matrix 2026-01-05 16:50:46 +01:00
Alex Rønne Petersen
d0ad76c03c
update_openbsd_libc: add tool for updating openbsd libc startup code 2026-01-05 16:50:44 +01:00
Jacob Young
ac64c75876 Dwarf: implement pointers to more comptime values
Closes #30600
Closes #30602
2026-01-05 11:24:48 +01:00
Andrew Kelley
b4dbe483a7 std.Build: adjust temp files API
Remove the RemoveDir step with no replacement. This step had no valid
purpose. Mutating source files? That should be done with
UpdateSourceFiles step. Deleting temporary directories? That required
creating the tmp directories in the configure phase which is broken.
Deleting cached artifacts? That's going to cause problems.

Similarly, remove the `Build.makeTempPath` function. This was used to
create a temporary path in the configure place which, again, is the
wrong place to do it.

Instead, the WriteFile step has been updated with more functionality:

tmp mode: In this mode, the directory will be placed inside "tmp" rather
than "o", and caching will be skipped. During the `make` phase, the step
will always do all the file system operations, and on successful build
completion, the dir will be deleted along with all other tmp
directories. The directory is therefore eligible to be used for
mutations by other steps. `Build.addTempFiles` is introduced to
initialize a WriteFile step with this mode.

mutate mode: The operations will not be performed against a freshly
created directory, but instead act against a temporary directory.
`Build.addMutateFiles` is introduced to initialize a WriteFile step with
this mode.

`Build.tmpPath` is introduced, which is a shortcut for
`Build.addTempFiles` followed by `WriteFile.getDirectory`.

* give Cache a gpa rather than arena because that's what it asks for
2026-01-04 17:23:45 -08:00
Andrew Kelley
854c076ff7 std.Io.Threaded: improve posix spawning
* avoid unreachable when the OS does something unexpected
* make waiting for the fork/exec error report cancelable
2026-01-04 00:27:09 -08:00
Andrew Kelley
e2c04a4651 fix some windows compilation errors 2026-01-04 00:27:09 -08:00
Andrew Kelley
2fee64ceb0 update init template for new main API 2026-01-04 00:27:09 -08:00
Andrew Kelley
e55fa3d525 fix two standalone tests on windows 2026-01-04 00:27:09 -08:00
Andrew Kelley
84da158afb test-stack-traces: update to new main API 2026-01-04 00:27:09 -08:00
Andrew Kelley
1070c2a71a rename env_map to environ_map
For naming consistency with `std.process.Environ.Map`.
2026-01-04 00:27:09 -08:00
Andrew Kelley
f25de4c7a2 fix native path lookup on macOS 2026-01-04 00:27:08 -08:00
Andrew Kelley
4afed3e9ef test-standalone: update the rest of the cases to new API 2026-01-04 00:27:08 -08:00
Andrew Kelley
bf74827ddb test-standalone: update more cases to new main API 2026-01-04 00:27:08 -08:00
Andrew Kelley
1b56686012 test-standalone: update cases to new main API 2026-01-04 00:27:08 -08:00
Andrew Kelley
f28802a9c6 zig libc: fix subcommand
This branch regressed the child process "run" mechanism because it
didn't pass the correct stdin, stdout, stderr values to process.spawn

Fixed now.
2026-01-04 00:27:08 -08:00