Commit graph

1373 commits

Author SHA1 Message Date
Prokop Randáček
94e98bfe80
Dedupe types when printing error messages 2025-11-16 16:20:45 +02:00
xdBronch
f6fecfdc00 improve assembly error test coverage 2025-11-16 06:30:51 +00:00
Justus Klausecker
06d08dabab Sema: fix illegal multi level pointer coercions
Moves a premature check that allowed pointers to mutable pointers to coerce
to any other pointer to a mutable pointer.
2025-11-14 23:25:54 +00:00
xdBronch
071453d5b9 fix 'redundant comptime keyword' error source location and add tests 2025-11-13 19:47:36 +00:00
So1aric
49e19fc94f
Sema: fix inline fn compiler crash (#25586)
Resolves: https://github.com/ziglang/zig/issues/25581
2025-11-12 19:21:28 +00:00
xdBronch
fb914a9a10 sema: print @panic message at comptime 2025-11-10 14:21:26 +00:00
Mateusz Poliwczak
d942f693c5 std.zig.AstGen: properly handle grouped_expression
This fixes an endless loop in the compiler.
2025-11-10 14:02:37 +00:00
xdBronch
92f64899c1 sema: disallow slices of opaque types 2025-11-07 12:12:32 +00:00
Alex Rønne Petersen
beb507a1ed
std.builtin: add CallingConvention.x86_64_x32
This was forgotten during the refactoring of std.builtin.CallingConvention. It
mirrors mips64_n32 for MIPS.
2025-10-23 09:27:17 +02:00
xdBronch
f785e4745d detect invalid @bitCast with arrays 2025-10-16 19:36:11 +01:00
xdBronch
60be67d3c0 don't make OPV tuple fields comptime 2025-10-08 18:04:25 +01:00
xdBronch
2810e4b173 detect references to comptime var in default values and sentinels 2025-10-07 11:58:12 +01:00
Alex Rønne Petersen
c68f9bc207
test: remove some tests that are now covered well enough by test-stack-traces
The amount of cross compilation required for these tests was too time-consuming
for how much value they added. test-stack-traces now cover these well enough,
especially as we add more exotic machines to the CI fleet to run native tests.
2025-10-04 20:51:07 +02:00
mlugg
3a9c680ad7
std: allow disabling stack tracing
This option disables both capturing and printing stack traces. The
default is to disable if debug info is stripped.
2025-09-30 13:44:55 +01:00
Andrew Kelley
1bdcdbd996 delete all the translate-c tests
the ziglang/translate-c package has its own test suite, so these are
redundant
2025-09-24 20:01:17 -07:00
Andrew Kelley
ba137783ed
forbid trivial local address returned from functions (#25333)
progress towards #25312
2025-09-23 23:37:53 +00:00
Alex Rønne Petersen
7b92d5f405
std.pie: fix register constraint in getDynamicSymbol() for s390x (#25327)
If the compiler happens to pick `ret = r0`, then this will assemble to
`ag r0, 0` which is obviously not what we want. Using `a` instead of `r` will
ensure that we get an appropriate address register, i.e. `r1` through `r15`.

Re-enable pie_linux for s390x-linux which was disabled in
ed7ff0b693.
2025-09-22 18:36:47 +02: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
0e16d933be fix rebase error 2025-09-20 18:33:01 -07:00
mlugg
baaf715d21 cases: update for new error
The latest bugfix reverted this case to its old behavior (which is a
reasonable behavior to have).
2025-09-20 18:33:01 -07:00
mlugg
fcc7e378f8 Revert "delete failing test case"
This reverts commit ba4d4602ab9bb0dc17fc0d57141d9324bdbb356d.
2025-09-20 18:33:01 -07:00
Andrew Kelley
725dec6aa7 Sema: add missed logic to checkPtrAttributes
It wasn't checking bit pointer data.
2025-09-20 18:33:01 -07:00
Andrew Kelley
7ffe068a79 delete failing test case
Matthew can revert this commit when he's ready to tackle the assertion
failure
2025-09-20 18:33:01 -07:00
Andrew Kelley
aacff8c800 add compile error coverage for dependency loop 2025-09-20 18:33:00 -07:00
Andrew Kelley
3bd62e1bb6 Sema: fix source location of "declared here" note
point at the var not at the init expression
2025-09-20 18:33:00 -07:00
Andrew Kelley
426af68b7d compiler: require comptime vector indexes 2025-09-20 18:33:00 -07:00
Alex Rønne Petersen
4dba253cd2
test: pull tests in test/cases/llvm/ up to test/cases/
There is nothing inherently LLVM-specific about any of these.
2025-09-16 23:39:29 +02:00
Alex Rønne Petersen
589e564f16
test: delete old stage1 compile_errors tests
generic_function_returning_opaque_type.zig was salvaged as it's still worth
having.
2025-09-16 23:39:29 +02:00
Alex Rønne Petersen
2e3fac3626
test: rename backend=stage2 to backend=selfhosted, and add backend=auto
backend=auto (now the default if backend is omitted) means to let the compiler
pick whatever backend it wants as the default. This is important for platforms
where we don't yet have a self-hosted backend, such as loongarch64.

Also purge a bunch of redundant target=native.
2025-09-16 23:39:26 +02:00
mlugg
8744865425 frontend: fix reference tracking through coerced function bodies
This bug was manifesting for user as a nasty link error because they
were calling their application's main entry point as a coerced function,
which essentially broke reference tracking for the entire ZCU, causing
exported symbols to silently not get exported.

I've been a little unsure about how coerced functions should interact
with the unit graph before, but the solution is actually really obvious
now: they shouldn't! `Sema` is now responsible for unwrapping
possibly-coerced functions *before* queuing analysis or marking unit
references. This makes the reference graph optimal (there are no
redundant edges representing coerced versions of the same function) and
simplifies logic elsewhere at the expense of just a few lines in Sema.
2025-09-15 11:29:31 +01:00
Andrew Kelley
7666d5fc26 add compile error test case 2025-09-07 23:03:06 -07:00
Andrew Kelley
5dc5bf6a6b add compile error test case for new error 2025-09-05 19:55:45 -07:00
mlugg
8adabaa4ed Zcu: don't tell linkers about exports if there are compile errors
In the best case, this is redundant work, because we aren't actually
going to emit a working binary this update. In the worst case, it causes
bugs because the linker may not have *seen* the thing being exported due
to the compile errors.

Resolves: #24417
2025-08-15 20:00:30 +01:00
Will Lillis
e9eee8dace fix: print error set members in a consistent order
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-08-15 07:43:46 +01:00
Matthew Lugg
a495628862
Merge pull request #24674 from Justus2308/undef-shift-bitwise
Sema: Improve comptime arithmetic undef handling
2025-08-13 14:04:59 +01:00
Justus Klausecker
4ec421372f add remaining undef value tests ; fix @truncate undef retval type 2025-08-12 16:33:58 +02:00
Justus Klausecker
f0ffe30f2f add undef shift tests ; mirror zirShl logic for @shlWithOverflow 2025-08-12 16:33:58 +02:00
Justus Klausecker
79756e681d remove redundant test cases 2025-08-12 16:33:58 +02:00
Justus Klausecker
05762ca02f address most comments 2025-08-12 16:33:57 +02:00
Justus Klausecker
0ef26d113a make >> a compile error with any undef arg ; add a bunch of test cases 2025-08-12 16:33:57 +02:00
Justus Klausecker
d0586da18e Sema: Improve comptime arithmetic undef handling
This commit expands on the foundations laid by https://github.com/ziglang/zig/pull/23177
and moves even more `Sema`-only functionality from `Value`
to `Sema.arith`. Specifically all shift and bitwise operations,
`@truncate`, `@bitReverse` and `@byteSwap` have been moved and
adapted to the new rules around `undefined`.

Especially the comptime shift operations have been basically
rewritten, fixing many open issues in the process.

New rules applied to operators:
* `<<`, `@shlExact`, `@shlWithOverflow`, `>>`, `@shrExact`: compile error if any operand is undef
* `<<|`, `~`, `^`, `@truncate`, `@bitReverse`, `@byteSwap`: return undef if any operand is undef
* `&`, `|`: Return undef if both operands are undef, turn undef into actual `0xAA` bytes otherwise

Additionally this commit canonicalizes the representation of
aggregates with all-undefined members in the `InternPool` by
disallowing them and enforcing the usage of a single typed
`undef` value instead. This reduces the amount of edge cases
and fixes a bunch of bugs related to partially undefined vecs.

List of operations directly affected by this patch:
* `<<`, `<<|`, `@shlExact`, `@shlWithOverflow`
* `>>`, `@shrExact`
* `&`, `|`, `~`, `^` and their atomic rmw + reduce pendants
* `@truncate`, `@bitReverse`, `@byteSwap`
2025-08-12 16:33:57 +02:00
Justus Klausecker
0ecbd5a0e1 address comments 2025-08-07 13:58:49 +02:00
Justus Klausecker
ba549a7d67 Add support for both '_' and 'else' prongs at the same time in switch statements
If both are used, 'else' handles named members and '_' handles
unnamed members. In this case the 'else' prong will be unrolled
to an explicit case containing all remaining named values.
2025-08-07 13:58:47 +02:00
Justus Klausecker
1d9b1c0212 Permit explicit tags with '_' switch prong
Mainly affects ZIR representation of switch_block[_ref]
and special prong (detection) logic for switch.
Adds a new SpecialProng tag 'absorbing_under' that allows
specifying additional explicit tags in a '_' prong which
are respected when checking that every value is handled
during semantic analysis but are not transformed into AIR
and instead 'absorbed' by the '_' branch.
2025-08-07 13:57:57 +02:00
Justus Klausecker
7c35070b90 zig fmt: apply new cast builtin order 2025-08-03 14:59:56 +02:00
David Rubin
e82d67233b
disallow alignment on packed union fields 2025-08-02 09:51:26 -07:00
David Rubin
d6c74a95fd
remove usages of .alignment = 0 2025-08-01 14:57:16 -07:00
David Rubin
17330867eb
Sema: compile error on reifying align(0) struct fields 2025-08-01 14:57:16 -07:00
Jackson Wambolt
264bd7053e Sema: remove incorrect requireRuntimeBlock calls
Part of #22353

Resolves: #24273
Co-Authored-By: Matthew Lugg <mlugg@mlugg.co.uk>
2025-07-31 22:28:46 +01:00
Matthew Lugg
04d7b491b4
Merge pull request #24632 from mlugg/lossy-int-to-float-coercion
Sema: compile error on lossy int to float coercion
2025-07-31 21:49:37 +01:00