Commit Graph

7865 Commits

Author SHA1 Message Date
mlugg f28ef7ee29 tests: extern threadlocals require LLVM
This is a current limitation of our self-hosted linkers.
2025-06-06 23:42:15 -07:00
mlugg 437059f37c tests: avoid loading 16 MiB onto the stack
Currently, Zig semantically loads an array as a temporary when indexing
it. This means it cannot be guaranteed that only the requested element
is loaded; in particular, our self-hosted backends do not elide the load
of the full array, so this test case was crashing on self-hosted.
2025-06-06 23:42:15 -07:00
Jacob Young 0bf8617d96 x86_64: add support for pie executables 2025-06-06 23:42:14 -07:00
Jacob Young 5986bdf868 Compilation: enable the x86_64 backend by default for debug builds
Closes #22257
2025-06-06 23:42:14 -07:00
mlugg 38266c5035 AstGen: fix name strategy bugs
Representing this with a `GenZir` field is incredibly bug-prone.
Instead, just pass this data directly to the relevant expression in the
very few places which actually provide a name strategy.

Resolves: #22798
2025-06-06 22:04:51 +01:00
Alex Rønne Petersen 98cf81d51c test: Expand target coverage for C ABI tests. 2025-06-05 21:50:56 +02:00
Alex Rønne Petersen 9d534790eb std.Target: Introduce Cpu convenience functions for feature tests.
Before:

* std.Target.arm.featureSetHas(target.cpu.features, .has_v7)
* std.Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov })
* std.Target.wasm.featureSetHasAll(target.cpu.features, .{ .atomics, .bulk_memory })

After:

* target.cpu.has(.arm, .has_v7)
* target.cpu.hasAny(.x86, &.{ .sse, .avx, .cmov })
* target.cpu.hasAll(.wasm, &.{ .atomics, .bulk_memory })
2025-06-05 06:12:00 +02:00
Andrew Kelley 826e1c30ba Merge pull request #24013 from alexrp/test-matrix
More target coverage in the module test matrix
2025-06-03 17:05:15 -04:00
Jacob Young 80170d017b Legalize: handle packed semantics
Closes #22915
2025-06-03 15:04:43 -04:00
Jacob Young 2543e2d97c x86_64: implement integer @divFloor and @mod
Closes #24039
2025-06-02 22:45:15 -04:00
mlugg 493e37fa50 cases: include dirname in case names
For instance, the file 'cases/compile_errors/undeclared_identifier.zig'
now corresponds to test name 'compile_errors.undeclared_identifier'.
This is useful because you can now filter based on the case dirname
using `-Dtest-filter`.
2025-06-01 12:10:57 +01:00
mlugg c1a5caa454 compiler: combine @intCast safety checks
`castTruncatedData` was a poorly worded error (all shrinking casts
"truncate bits", it's just that we assume those bits to be zext/sext of
the other bits!), and `negativeToUnsigned` was a pointless distinction
which forced the compiler to emit worse code (since two separate safety
checks were required for casting e.g. 'i32' to 'u16') and wasn't even
implemented correctly. This commit combines those safety panics into one
function, `integerOutOfBounds`. The name maybe isn't perfect, but that's
not hugely important; what matters is the new default message, which is
clearer than the old ones: "integer does not fit in destination type".
2025-06-01 12:10:57 +01:00
Jacob Young 6daa37ded9 x86_64: fix packed struct equality
Closes #22990
2025-06-01 08:24:01 +01:00
Jacob Young 9edfccb9a7 Legalize: implement scalarization of overflow intrinsics 2025-06-01 08:24:01 +01:00
Jacob Young ec579aa0f3 Legalize: implement scalarization of @shuffle 2025-06-01 08:24:01 +01:00
mlugg add2976a9b compiler: implement better shuffle AIR
Runtime `@shuffle` has two cases which backends generally want to handle
differently for efficiency:

* One runtime vector operand; some result elements may be comptime-known
* Two runtime vector operands; some result elements may be undefined

The latter case happens if both vectors given to `@shuffle` are
runtime-known and they are both used (i.e. the mask refers to them).
Otherwise, if the result is not entirely comptime-known, we are in the
former case. `Sema` now diffentiates these two cases in the AIR so that
backends can easily handle them however they want to. Note that this
*doesn't* really involve Sema doing any more work than it would
otherwise need to, so there's not really a negative here!

Most existing backends have their lowerings for `@shuffle` migrated in
this commit. The LLVM backend uses new lowerings suggested by Jacob as
ones which it will handle effectively. The x86_64 backend has not yet
been migrated; for now there's a panic in there. Jacob will implement
that before this is merged anywhere.
2025-06-01 08:24:01 +01:00
Jacob Young b48d6ff619 Legalize: implement scalarization of @select 2025-06-01 08:24:01 +01:00
Jacob Young b483defc5a Legalize: implement scalarization of binary operations 2025-05-31 18:54:28 -04:00
Jacob Young c1e9ef9eaa Legalize: implement scalarization of unary operations 2025-05-31 18:54:28 -04:00
Alex Rønne Petersen aeebb131c8 test: Add NetBSD targets to module test matrix. 2025-05-29 16:48:28 +02:00
Alex Rønne Petersen c5a68e4168 test: Remove x86-freebsd-none and powerpc-freebsd-eabihf from llvm_targets.
These will be dropped in FreeBSD 15.0, so there's no point in us spending
resources these now.
2025-05-29 16:48:28 +02:00
Alex Rønne Petersen c9ee69712a test: Add FreeBSD targets to module test matrix.
std tests are temporarily disabled for arm-freebsd-eabihf due to #23949.

I omitted x86-freebsd-none and powerpc-freebsd-none because these will be
dropped in FreeBSD 15.0 anyway, so there's no point in us spending resources on
those now.
2025-05-29 16:48:28 +02:00
Alex Rønne Petersen 3d2b0a53fe test: Improve Windows module test coverage.
There's not really any point in targeting *-windows-(gnu,msvc) when not linking
libc, so add entries for *-windows-(gnu,msvc) that actually link libc, and
change the old non-libc entries to *-windows-none.

Also add missing aarch64-windows-(none,msvc) and thumb-windows-(none,msvc)
entries. thumb-windows-gnu is disabled for now due to #24016.
2025-05-29 16:47:54 +02:00
Alex Rønne Petersen 7cae6b8fa7 test: Skip *-windows-msvc + libc module tests on non-Windows.
We can't provide MSVC libc when cross-compiling (yet?).
2025-05-29 15:35:30 +02:00
Alex Rønne Petersen c8ea81bf96 test: Sort module test and C ABI test target tables.
I removed the commented-out entries for backends that are bitrotted. Can add
these back later when we reboot those backends.
2025-05-29 15:01:45 +02:00
Jacob Young 9f9e7e398f x86_64: implement strict float @reduce(.Max) 2025-05-28 15:10:22 -04:00
Jacob Young f5a1aaf2fc x86_64: implement strict float @reduce(.Min) 2025-05-28 15:10:22 -04:00
Jacob Young d29ea656b0 x86_64: implement optimized float @reduce(.Max) 2025-05-28 15:10:22 -04:00
Jacob Young 114a4eaf5c x86_64: implement optimized float @reduce(.Min) 2025-05-28 15:10:22 -04:00
Jacob Young 8bacf3e757 x86_64: implement integer @reduce(.Max) 2025-05-28 15:10:22 -04:00
Jacob Young 3fd3358f37 x86_64: implement integer @reduce(.Min) 2025-05-28 15:10:22 -04:00
Jacob Young 7d727ed7df x86_64: implement strict float @reduce(.Mul) 2025-05-28 15:10:22 -04:00
Jacob Young d1785cf61c x86_64: implement strict float @reduce(.Add) 2025-05-28 15:10:22 -04:00
Jacob Young a4a1ebdeed x86_64: implement optimized float @reduce(.Mul) 2025-05-28 15:10:22 -04:00
Jacob Young 612f5784cf x86_64: implement optimized float @reduce(.Add) 2025-05-28 15:10:22 -04:00
Jacob Young 7bfdb7f26d x86_64: implement integer @reduce(.Mul) 2025-05-28 15:10:22 -04:00
Jacob Young 1f6f8b0ffe x86_64: implement integer @reduce(.Add) 2025-05-28 15:10:22 -04:00
Jacob Young d69f4c48fc x86_64: rewrite bitwise @reduce 2025-05-28 15:10:22 -04:00
mlugg 92c63126e8 compiler: tlv pointers are not comptime-known
Pointers to thread-local variables do not have their addresses known
until runtime, so it is nonsensical for them to be comptime-known. There
was logic in the compiler which was essentially attempting to treat them
as not being comptime-known despite the pointer being an interned value.
This was a bit of a mess, the check was frequent enough to actually show
up in compiler profiles, and it was very awkward for backends to deal
with, because they had to grapple with the fact that a "constant" they
were lowering might actually require runtime operations.

So, instead, do not consider these pointers to be comptime-known in
*any* way. Never intern such a pointer; instead, when the address of a
threadlocal is taken, emit an AIR instruction which computes the pointer
at runtime. This avoids lots of special handling for TLVs across
basically all codegen backends; of all somewhat-functional backends, the
only one which wasn't improved by this change was the LLVM backend,
because LLVM pretends this complexity around threadlocals doesn't exist.

This change simplifies Sema and codegen, avoids a potential source of
bugs, and potentially improves Sema performance very slightly by
avoiding a non-trivial check on a hot path.
2025-05-27 19:23:11 +01:00
David Rubin 3ed9155f10 Sema: simplify comptime @intFromPtr logic 2025-05-27 02:40:58 +01:00
Matthew Lugg ef35c3d5fe Merge pull request #23986 from mlugg/incremental-stuff
incremental: bugfix (and a debugging feature that helped me do that bugfix)
2025-05-25 18:02:16 +01:00
Robin Voetter dc6ffc28b5 Merge pull request #23815 from alichraghi/master
spirv: unroll all vector operations
2025-05-25 12:36:53 +02:00
mlugg 3d8e760552 Zcu: fix nav_ty dependency on nav_val
In the case where a declaration has no type annotation, the interaction
between resolution of `nav_ty` and `nav_val` is a little fiddly because
of the fact that resolving `nav_val` actually implicitly resolves the
type as well. This means `nav_ty` never gets an opporunity to mark its
dependency on the `nav_val`. So, `ensureNavValUpToDate` needs to be the
one to do it. It can't do it too early, though; otherwise, our marking
of dependees as out-of-date/up-to-date will go wrong.

Resolves: #23959
2025-05-25 05:50:26 +01:00
Ali Cheraghi dacd70fbe4 spirv: super basic composite int support 2025-05-21 13:01:20 +03:30
Jacob Young cdba1d591a test-cli: port build options test to new build system API
Since we need testing for passing `--build-file` and `--cache-dir`
together anyway, use it to test the disabled build options test.
2025-05-20 23:02:51 -04:00
Alex Rønne Petersen 999777e73a compiler: Scaffold stage2_powerpc backend.
Nothing interesting here; literally just the bare minimum so I can work on this
on and off in a branch without worrying about merge conflicts in the non-backend
code.
2025-05-20 10:23:16 +02:00
Alex Rønne Petersen d000e53b29 Merge pull request #23923 from alexrp/compiler-rt-symbols
Use hidden visibility in compiler-rt and libzigc except when testing
2025-05-20 07:48:35 +02:00
Alex Rønne Petersen b27c5fbbde Merge pull request #23913 from alexrp/netbsd-libc
Support dynamically-linked NetBSD libc when cross-compiling
2025-05-20 07:46:08 +02:00
Matthew Lugg 23c817548b Merge pull request #23836 from mlugg/incr-fixes
Incremental fixes, refactor `Zcu.File`
2025-05-20 03:25:19 +01:00
mlugg f2077f57ae Sema: allow @ptrCast single-item pointer to slice
Also, rework this logic a little to make it simpler. The length of the
result slice is now computed in one place.
2025-05-19 19:26:12 +01:00