Commit graph

2532 commits

Author SHA1 Message Date
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
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
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
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
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
Jacob Young
ac64c75876 Dwarf: implement pointers to more comptime values
Closes #30600
Closes #30602
2026-01-05 11:24:48 +01:00
Alex Rønne Petersen
423d117251
test: skip bitcast nan float does not modify signaling bit on powerpc
This fails on a pwr10 machine.
2025-12-16 06:23:06 +01:00
Pavel Verigo
bf58a3bc08 stage2_wasm: revival, enabling tests 2025-12-07 07:21:15 +01:00
Pavel Verigo
cc099afca5 sema: fix error_return_trace_index handling in zirCondBr 2025-12-07 07:20:59 +01:00
fn ⌃ ⌥
bfe3317059 Return a usize from @abs if given an isize
Also:
- `c_ushort` for `c_short`
- `c_uint` for `c_int`
- `c_ulong` for `c_long`
- `c_ulonglong` for `c_longlong`
2025-11-29 21:09:08 +01:00
Matthew Lugg
8f5db19791
Sema: initialize OPV comptime allocs correctly
This was caused a `[0]std.builtin.Type.StructField.Attributes` to be
considered `undefined`, even though that type is OPV so should prefer
its OPV `.{}` over `undefined`.

Resolves: #30039
2025-11-29 11:55:36 +00:00
Ali Cheraghi
dec1163fbb
all: replace all @Type usages
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-11-22 22:42:38 +00:00
Benjamin Jurk
4b5351bc0d
update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
Alex Rønne Petersen
9ab7eec23e represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi
Apple's own headers and tbd files prefer to think of Mac Catalyst as a distinct
OS target. Earlier, when DriverKit support was added to LLVM, it was represented
a distinct OS. So why Apple decided to only represent Mac Catalyst as an ABI in
the target triple is beyond me. But this isn't the first time they've ignored
established target triple norms (see: armv7k and aarch64_32) and it probably
won't be the last.

While doing this, I also audited all Darwin OS prongs throughout the codebase
and made sure they cover all the tags.
2025-11-14 11:33:35 +01:00
Matthew Lugg
532aa3c575
cbe: work around some miscompilations
The changes to `codegen.c` are blatant hacks, but the problem they work
around isn't a regression: it's an existing miscompilation. This branch
happened to *expose* that miscompilation in more cases by changing how
an incorrect result is *used*.
2025-11-12 16:00:16 +00:00
Matthew Lugg
99a7884308
behavior: disable test on cbe
This isn't so much a regression as it is foreshadowing of accepted
proposal https://github.com/ziglang/zig/issues/24657.
2025-11-12 16:00:16 +00:00
Jacob Young
459f3b7ede codegen: fix tuple padding
Closes #25797
2025-11-04 06:04:30 -05:00
Jacob Young
402c14f86a
aarch64: implement optional comparisons 2025-10-30 09:31:30 +00:00
Jacob Young
52a029e503 x86_64: continue hacking around unimplemented linker logic
Closes #25666
2025-10-29 19:31:44 -04:00
mlugg
7a5d2a196f
tweak tests to avoid timeouts 2025-10-18 09:28:42 +01:00
Jacob Young
2e31077fe0 Coff: implement threadlocal variables 2025-10-10 22:47:47 -07:00
xdBronch
60be67d3c0 don't make OPV tuple fields comptime 2025-10-08 18:04:25 +01:00
xdBronch
2c0aa1c6f5 don't make anonymous tuple fields referencing comptime vars comptime 2025-10-07 22:13:10 +01:00
xdBronch
851ae9bb43 don't pass zero-length @memset to the backend 2025-10-06 11:28:56 -07:00
Jacob Young
07c3f9ef8e x86_64: fix bool vector init register clobber
Closes #25439
2025-10-03 12:18:53 -04:00
Jacob Young
e1f3fc6ce2 Coff2: create a new linker from scratch 2025-10-02 17:44:52 -04:00
Jacob Young
d5f09f56e0 x86_64: fix windows calling convention abi 2025-10-02 15:59:51 -04:00
Jacob Young
a744fbd22f x86_64: fix ~/! miscomps 2025-09-27 18:30:52 -04:00
Andrew Kelley
2a88a6a456
Merge pull request #24497 from ziglang/aro-translate-c
compiler: update aro and translate-c to latest; delete clang translate-c
2025-09-25 14:18:49 -07:00
Jacob Young
6257f4abb7 x86_64: improve support for large enums
Closes #25247
2025-09-24 21:20:27 -07:00
Andrew Kelley
01132e0cf8 remove behavior test that depended on std.zig.c_translation
behavior tests may not depend on this namespace.
2025-09-24 20:01:19 -07:00
Andrew Kelley
ba137783ed
forbid trivial local address returned from functions (#25333)
progress towards #25312
2025-09-23 23:37:53 +00:00
Andrew Kelley
633162eb0c add behavior test: comptime C pointer to optional pointer 2025-09-20 18:58:32 -07:00
Andrew Kelley
1c9ac9dbb7 add behavior test: avoid unused field function body compile error 2025-09-20 18:51:43 -07:00
Andrew Kelley
500afbf076 add behavior test: resist alias of explicit copy...
...of array passed as arg

closes #22906
2025-09-20 18:51:26 -07:00
Andrew Kelley
ed7ff0b693 allow some test cases to regress
tracked by #24061 - these should be re-enabled once that is solved.
2025-09-20 18:33:01 -07:00
mlugg
20925f2957 Revert "frontend: another packedStructFieldPtrInfo fix"
This reverts commit dedccecda944f88a5278c12c24ffbea46126de63.
2025-09-20 18:33:01 -07:00
Jacob Young
5144f10ec9 aarch64: fix behavior failures 2025-09-20 18:33:01 -07:00
Andrew Kelley
2ba03e98c8 disable failing stage2_aarch64 behavior tests 2025-09-20 18:33:01 -07:00
Andrew Kelley
5d8c1fb6ab frontend: another packedStructFieldPtrInfo fix
it was calculating host integer size in a wrong way. just use integer
abi size
2025-09-20 18:33:01 -07:00
Andrew Kelley
0681bf06ab frontend: packed struct field ptr no longer finds byte borders
technically breaking, but I doubt anyone will notice.
2025-09-20 18:33:01 -07:00