13443 Commits

Author SHA1 Message Date
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
Andrew Kelley abd131e336 zig cc: make --version use the full clang CLI lowering code path
because clang wants to parse the -target argument with clang -target
syntax.

closes #30178
2026-03-25 18:29:19 -07:00
kcbanner ca99896d73 - x86_64: Copy arguments into the shadow store when generating a variadic function on Win64
- x86_64: Implement @cVaStart for Win64
- x86_64: Implement @cVaArg for Win64
- x86_64: Duplicate floating point register args equivalent integer registers when calling variadic functions on Win64
- tests: Enable var_args tests for the self-hosted backend on windows
- tests: Add var_args test for floating point arguments
2026-03-25 20:05:51 -04:00
Kendall Condon 0b52cac434 zig fmt: add missed maybe_spaces 2026-03-25 17:30:51 -04:00
Kendall Condon 09e523bd51 zig fmt: fix overindent tracking in sub-renders
This problem also affected determining if an expression became multiline
as that depends on if the line is overindented. As such,
`becomesMultilineExpr` has been replaced by `rendersMultiline` which
constructs a temporary writer which returns `error.WriteFailed` when
newlines are written. This new approach also has the advantage of being
more maintainable.
2026-03-25 17:30:51 -04:00
Kendall Condon 92915a42b5 zig fmt: do not reorder pointer casts with comments
This was especially bad as it could crash or duplicate them due to
them being moved around "zig fmt: on/off".

As a bonus this fixes a crash from reordering at the start of the file.
2026-03-25 17:30:51 -04:00
Kendall Condon ab237855b8 zig fmt: render asm colons with trailing comments
Previously, the comments would be lost with the colons.

This required a substantial rewrite of renderAsm to determine how many
colons should be rendered.
2026-03-25 17:30:51 -04:00
Kendall Condon c818a1e61f zig fmt: handle skip space for multiline strings 2026-03-25 17:30:51 -04:00
Kendall Condon ed3ca0f570 zig fmt: call ais.resetLine after "zig fmt: on" 2026-03-25 17:30:51 -04:00
Kendall Condon d70a9ea5d7 zig fmt: properly revert nested asm indentation 2026-03-25 17:30:51 -04:00
Kendall Condon 23db309043 zig fmt: use AstSmith in fuzz test 2026-03-25 17:30:51 -04:00
Kendall Condon 785fb1be11 fix several inconsistencies between parser and PEG
- PEG / Parser Changes

All the changes made here are to places where the PEG was more
permissive than the parser. Changes to the parser make it more
permissive and changes to the PEG make it more strict. When choosing
between these two options for discrepancies, I opted for the choice
that was more natural and increased code readability.

Changes to the Parser
* Tuple types can now be `inline` and `extern` (e.g. `extern struct`).
* Break labels are now only consumed if both the colon and identifier
  are present instead of failing if there is only a colon.
* Labeled blocks are no longer parsed in PrimaryExpr (so they are now
  allowed to have CurlySuffixExpr) as in the PEG.
* While expressions can now be grouped on the same line.
* Added distinction in error messages for "a multiline string literal"
  so places where only single string literals are allowed do not give
  "expected 'a string literal', found 'a string literal'".

Changes to the PEG
* Made it so extern functions cannot have a body
* Made it so ... can be only the last function argument
* Made it so many item pointers can't have bit alignment
* Made it so asm inputs / outputs can not be multiline string literals
* Added distinction between block-level statements and regular
  statements

-- Pointer Qualifier Order

The PEG allowed for duplicated qualifiers, which the parser did not.
The simplest fix for this was to make each be allowed zero or one times
which required giving them a order similar to how FnProto already
works. The chosen order is the same as used by zig fmt. The parser
still accepts them in any order similar to functions.

-- Backtracking

Made it so several places could not backtrack in the PEG. A common
pattern for this was (A / !A).

--- !ExprSuffix

Expressions ending with expressions now have !ExprSuffix after.
This change prevents expressions such as `if (a) T else U{}` being be
parsable as `(if (a) T else U){}`. It also stops some backtracking,
take for example:

`if (a) for (b) |c| d else |e| f`

It may seem at first that the else clause belongs to the `for`, however
it actually belongs to the `if` because for else-clauses cannot have a
payload. This is fixed by a new `KEYWORD_else / !KEYWORD_else`, however
this alone does not fix more complex cases such as:

`if (a) for (b) |c| d() else |e| f`

The PEG would first attempt to parse it as expected but fail due to the
new guard. It will then backtrack to

`if (a) (for (b) |c| d)() else |e| f`

which is surprising but avoids the new gaurd. So, !ExprSuffix is
required to disallow this type of backtracking.

--- !LabelableExpr

For identifiers, excluding labels is necessary despite ordered choice
due to pointer bit alignment. For example `*align(a : b: for (c) e) T`
could backtrack to `*align(a : b : (for (c) e)) T`.

--- !SinglePtrTypeStart

Prevents expressions like `break * break` which is parsed as
`break (*break)` backtracking to `(break) * (break)`

--- !BlockExpr

Prevents expressions like `test { {} = a; }` being backtracked to and
parsed as `test { ({} = a); }` (the parenthesis are just for
demonstration, that expression is not legal either)

--- !ExprStatement

In addition to splitting up block level statements, statements that are
also parsable as expressions are now part of ExprStatement to disallow
backtracking.
2026-03-25 17:29:56 -04:00
Kendall Condon 2aee0cd6b9 add an ast smith
This generates zig ASTs from `testing.Smith` and is based off the
langref's PEG.

The choice to not build the Ast while generating and instead parsing it
afterwards makes the smith more versatile by not being tied to a single
implementation at a cost of efficiency.

Additionally, a new function `boolWeighted` was added to `Smith` due to
its frequent use in `AstSmith`.
2026-03-25 17:27:18 -04:00
Justus Klausecker 5363a81a57 std.heap.FixedBufferAllocator: fix end_index memory ordering
This prevents a race between `alloc` and `free` where T1 receives memory
from `alloc` that is semantically about to be freed by T2 and still being
accessed, but the `free` is already visible to T1. Using acquire-release
here guarantees that any `free` is only published after all accesses to
the memory being freed have already happened.

Co-authored-by: Jacob Young <amazingjacob@gmail.com>
2026-03-25 11:48:45 +01:00
Justus Klausecker 3af5f81e11 std.heap.ArenaAllocator: fix end_index memory ordering
This prevents a race between `alloc` and `free` where T1 receives memory
from `alloc` that is semantically about to be freed by T2 and still being
accessed, but the `free` is already visible to T1. Using acquire-release
here guarantees that any `free` is only published after all accesses to
the memory being freed have already happened.

Co-authored-by: Jacob Young <amazingjacob@gmail.com>
2026-03-25 11:48:43 +01:00
Justus Klausecker 9bfe827ade Revert "std.heap.ArenaAllocator: Make resize and free check whether allocation is within current node more rigorously"
This reverts commit 589bcb2544.

The scenario presented in the reverted commit cannot actually happen.
Even if there are two contiguous arena nodes N1 and N2 and the `end_index`
of N1 points to somewhere in N2, a `resize` can never lead to an increase
of the `end_index` of N1 since it checks whether it's `<= size` first.
A `resize`/`free` *can* decrease `end_index`, but even if it is wrongly
assumed that some allocation that belongs to N2 actually belongs to N1
based on the `end_index` of N1, it can only ever be decreased to the start
of the buffer of N2. That's because a valid allocation of N2 logically
cannot be at any lower address than N2 itself. And any point still in N2
can never also be in N1, so there's no danger of overwriting any other
allocations of N1.
2026-03-25 11:20:21 +01:00
Isaac Freund 4848c3a1ad std: fix sentinel handling in Allocator interface
Currently the only function that handles sentinel terminated slices
properly is free. All uses of mem.sliceAsBytes() in the allocator
interface lack proper handling of a possible sentinel.

This commit changes the Allocator interface to use @ptrCast() plus
the new mem.absorbSentinel() instead.

Reported-by: David Vanderson <david.vanderson@gmail.com>
References: https://github.com/ziglang/zig/pull/19984
References: https://github.com/ziglang/zig/pull/23020
2026-03-25 10:50:24 +01:00
Isaac Freund 3d16c1eb76 std: add mem.absorbSentinel()
This will allow replacing (currently buggy) mem.sliceAsBytes() usage in
the mem.Allocator implementation with, for example:

const bytes: []u8 = @constCast(@ptrCast(mem.absorbSentinel(allocation)));

References: https://github.com/ziglang/zig/pull/22706
2026-03-25 10:50:24 +01:00
rpkak 8f6bad065e std.Thread.setName/getName: remove wrong error handling
std.posix.prctl already does error handling.
According to the man page PR_SET_NAME(2const), 0 is returned on success.
2026-03-25 08:10:25 +01:00
kcbanner 4e3fcbea84 - Build: support installing the compiler_rt.dll
This is an extension of the existing hack used for the x86_64 backend combined with the Coff linker
2026-03-25 00:58:37 -04:00
Jake Greenfield 4431ca28b8 fix Windows clock handling
Address two separate but related issues:
- Return value of `RtlQueryPerformanceFrequency` was used inconsistently; it
  returns a nonzero value to indicate success.
- `timeoutToWindowsInterval` wasn't converting absolute deadlines back to the
  Windows epoch before passing them to the system, which meant that values (in
  the Unix epoch) were always in the distant past, so sleeps would return
  immediately.

Fixes #31653
2026-03-24 21:33:27 -04:00
akhildevelops eec244c5a2 std.crypto.tls.Client: expose InitError (#31610)
Fixes: https://codeberg.org/ziglang/zig/issues/31581
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31610
Co-authored-by: akhildevelops <akhildevelops@noreply.codeberg.org>
Co-committed-by: akhildevelops <akhildevelops@noreply.codeberg.org>
2026-03-25 00:56:22 +01:00
Justus Klausecker 589bcb2544 std.heap.ArenaAllocator: Make resize and free check whether allocation is within current node more rigorously
This prevents the following scenario where an allocation is wrongly assumed
to be part of the current head node (`node0`):

```
| node0 - - - - | node1 - - - - - - - - - - - - |
          |   |         |   |           |
          |   |         |   end_index0  end_index1
          |   |         |   |
          alloc0        alloc1

free(alloc1):
    load node0
    buf0.ptr + end_index0 == alloc1.ptr + alloc1.len ? yes!
    end_index0 -= alloc1.len

| node0 - - - - | node1 - - - - - - - - - - - |
          | | |                         |
          | end_index0                  end_index1
          |   |
          alloc0
```

which could move `end_index0` *into* `alloc0` and make it possible for any
subsequent calls to `alloc` to overwrite its contents!
2026-03-25 00:54:44 +01:00
Alex Rønne Petersen b0ab55b8ea Merge pull request 'Add psp os' (#31609) from IridescentRose/zig:psp-os-target into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31609
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-03-25 00:51:01 +01:00
Alex Rønne Petersen 558a5c7913 std.c: audit some time types for non-Linux OSs
Some initial work towards https://codeberg.org/ziglang/zig/issues/31414.

Conclusion from this: Only x86-freebsd, x86-haiku, and x86-illumos remain time32
and are currently unfixable. I don't think the upstreams for any of these
targets actually care about them anymore (probably why they weren't migrated to
time64), so this is not a particularly big concern.

I split UTIME constants out from timespec because they were causing unreasonable
code duplication by being there.
2026-03-24 09:42:32 +01:00
Evgenii Orlov 0ee6a79da5 std.Io.net.HostName.netLookup: make canonical_name_buffer optional 2026-03-23 11:02:47 +01:00
Alex Rønne Petersen c7d69f0160 std.mem: delete illegal code in findSentinel()
I understand the temptation to exploit page size knowledge to make this function
faster, but I don't think this code can ever be compatible with any reasonable
set of pointer provenance/aliasing rules. At the very least, I don't believe it
is compatible with LLVM's.

closes https://github.com/ziglang/zig/issues/23184
2026-03-23 05:35:04 +01:00
Techatrix 029719cf47 std.Uri: reject invalid URI schemes according to RFC3986 2026-03-23 05:22:46 +01:00
Frank Denis b2c2b4d063 Merge pull request 'crypto: correct aes-siv s2v' (#31623) from sinon/zig:fix-aes-siv into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31623
Reviewed-by: Frank Denis <jedisct1@noreply.codeberg.org>
2026-03-23 03:11:13 +01:00
rpkak 9857dabfea std.c.MFD: support linux 2026-03-22 18:06:00 +01:00
David Rubin 8efd539305 crypto: correct aes-siv s2v
The first issue is that when len(Sn) >= 128,
we perform Sn xor D instead of the Sn xorend D
that is specified in RFC 5297.

The second issue is that we truncate the Sn
if it is larger than 4096 bytes, which could
lead to collisions between inputs. We solve
this by absoring the Sn into the CMAC state
perform the last 16 bytes, xoring those 16
bytes with D as described in the first issue,
and then updating and squeezing the CMAC.
2026-03-22 07:21:41 -07:00
Jacob Young ccf8e223f4 std.Io.net: disable unix socket test due to presumed windows kernel bug
Tracked by #31499
2026-03-22 09:37:12 -04:00
Nathan Bourgeois c824ce954e misc: Add allegrex CPU & features, run tool, update semver 2026-03-21 19:39:04 -04:00
Alex Rønne Petersen cb7d2b0563 Revert "std.Progress: use cmpxchgStrong instead of cmpxchgWeak for locking/unlocking IPC"
This reverts commit b6f99a59a3.

https://codeberg.org/ziglang/zig/pulls/31608#issuecomment-11875362
2026-03-21 14:04:24 +01:00
Nathan Bourgeois 2037dba90f std.posix: Minimal set to build an Io on PSP 2026-03-21 06:34:45 -04:00
Nathan Bourgeois fdf19984b8 std.Target: add psp os 2026-03-21 02:56:24 -04:00
Justus Klausecker 1f78e34de0 std.Io.Threaded: make mutexLock() use cmpxchgStrong instead of cmpxchgWeak
As established in 048e38624e and d70bd0b37e, mutexes should use a strong
cmpxchg when attempting to lock to guarantee that they actually succeed
if they aren't locked yet.

Also deletes an unused near-duplicate of `mutexLock()`.
2026-03-21 03:00:50 +01:00
Justus Klausecker b6f99a59a3 std.Progress: use cmpxchgStrong instead of cmpxchgWeak for locking/unlocking IPC
The `cmpxchgWeak` in `setIpcFile` could lead to the IPC file not being set
even though there's still a slot available because one or more slots were
spuriously skipped.

The `cmpxcheWeak` in `serialize` could lead to an unused IPC slot not
being locked and used even though it could be.
2026-03-21 03:00:50 +01:00
Andrew Kelley e938344100 Merge pull request 'linux: fix handling of O_TMPFILE flag on filesystems that do not support it' (#31543) from eshom/zig:tmpfile-not-supported into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31543
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-21 00:04:10 +01:00
Andrew Kelley a9e5c72aa8 Io.Uring: simplify openat error handling 2026-03-20 12:18:25 -07:00
eshom 2054a257c2 std.Io.Uring: handle UnsupportedOperation for O_TMPFILE case
Having `std.Io.Uring` contain OpenError error set
allows handling of OperationUnsupported specifically for `.openat`,
while avoiding propagating this error to the more general
`File.OpenError`.

This more specific subset also eliminated 2 unreachable prongs that
previously inherited from `File.OpenError`.

Added comments when handling OperationUnsupported, making it clear it is
an unexpected error when TMPFILE bit is not set.
2026-03-20 12:12:29 -07:00
eshom 5119cf6ffd std.Io.Threaded: syscall with O_TMPFILE flag can return OPNOTSUPP 2026-03-20 12:12:29 -07: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 83c7aba127 windows: trigger automatic fetching of root certificates 2026-03-20 19:23:48 +01:00
Justus Klausecker d78f096c49 zig fmt 2026-03-20 18:09:01 +01:00
Justus Klausecker 591bc39e57 std.heap.ArenaAllocator: decrease fuzz test workload per run
At smaller workloads the overhead of setting up a new `std.Io.Threaded`
for every run to reset thread-local state becomes more noticeable, so this
commit also switches from thread-local storage to a shared atomic variable
for keeping track of the most recent allocation. This has the side-effect
of simplifying the overall implementation a bit.
2026-03-20 17:32:17 +01:00
Justus Klausecker 79f8cf1326 std.debug.Info: make Mach-O source location resolution more resilient
`resolveAddresses` now also works if some calls to `getDwarfForAddress`
fail with `error.MissingDebugInfo`; the affected source location is set
to `.invalid`.

This makes fuzzing work with `ReleaseSafe` for Mach-O.
2026-03-20 17:19:28 +01:00
Adrià Arrufat c10cb44701 Zir: unify float rounding instructions into round_op 2026-03-20 21:27:38 +09:00
Andrew Kelley 06b85a4fd0 CLI: use zon format for clang options
- plain old data ftw
- 177K -> 151K
- data bypasses Sema

This change is not really important but it was nice to explore best
practices for data like this.

When I measured building the compiler, I found no statistically
significant difference in compilation time.
2026-03-20 06:46:13 +01:00
Jacob Young 982f26bcdd netReceiveOneWindows: fix typo 2026-03-20 00:37:00 -04:00