Commit graph

17075 commits

Author SHA1 Message Date
Jacob Young
98640cbeb8
Merge pull request #23209 from jacobly0/x86_64-rewrite
x86_64: rewrite wrapping multiplication
2025-03-23 21:56:58 -04:00
Jacob Young
f7e045c806 Merge pull request #23256 from xtexx/fix-gh-20113
x86_64: fix packedStore miscomp by spilling EFLAGS
2025-03-23 21:46:46 -04:00
Jacob Young
6705cbd5eb codegen: fix packed byte-aligned relocations
Closes #23131
2025-03-23 18:35:34 -04:00
Carl Åstholm
f45f9649e3 Lower @returnAddress to a constant 0 in Emscripten release builds
Emscripten currently implements `emscripten_return_address()` by calling
out into JavaScript and parsing a stack trace, which introduces
significant overhead that we would prefer to avoid in release builds.

This is especially problematic for allocators because the generic parts
of `std.mem.Allocator` make frequent use of `@returnAddress`, even
though very few allocator implementations even observe the return
address, which makes allocators nigh unusable for performance-critical
applications like games if the compiler is unable to devirtualize the
allocator calls.
2025-03-23 17:13:19 -04:00
mlugg
9f235a105b link: mark prelink tasks as procesed under -fno-emit-bin
The old logic only decremented `remaining_prelink_tasks` if `bin_file`
was not `null`. This meant that on `-fno-emit-bin` builds with
registered prelink tasks (e.g. C source files), we exited from
`Compilation.performAllTheWorkInner` early, assuming a prelink error.

Instead, when `bin_file` is `null`, we still decrement
`remaining_prelink_tasks`; we just don't do any actual work.

Resolves: #22682
2025-03-22 21:44:46 -04:00
Jacob Young
3c3a6c937b x86_64: fix rare miscomp that clobbers memory 2025-03-22 04:29:18 -04:00
Bingwu Zhang
c62fb118e7
x86_64: fix packedStore miscomp by spilling EFLAGS
Fixes #20113 and #20581.

AND instructions in packedStore clobbers EFLAGS.

Bug: https://github.com/ziglang/zig/issues/20113
Bug: https://github.com/ziglang/zig/issues/20581
Signed-off-by: Bingwu Zhang <xtex@aosc.io>
2025-03-22 16:06:07 +08:00
Jacob Young
2361468e23 x86_64: rewrite scalar shifts 2025-03-21 21:51:09 -04:00
Jacob Young
c5c1c8538d x86_64: rewrite wrapping multiplication 2025-03-21 21:51:08 -04:00
Jacob Young
ed284c1f98 big.int: fix yet another truncate bug
Too many bugs have been found with `truncate` at this point, so it was
rewritten from scratch.

Based on the doc comment, the utility of `convertToTwosComplement` over
`r.truncate(a, .unsigned, bit_count)` is unclear and it has a subtle
behavior difference that is almost certainly a bug, so it was deleted.
2025-03-21 21:51:08 -04:00
dan
07c04bcd83 spirv: Assemble OpTypeRuntimeArray. 2025-03-19 11:45:35 +08:00
Alex Rønne Petersen
03123916e5 compiler: Support more GCC code models and fix the mapping to LLVM code models.
Closes #22517.
2025-03-19 03:15:16 +01:00
Robin Voetter
5105c3c7fa
Merge pull request #23158 from alichraghi/ali_spirv
spirv: miscellaneous stuff #2
2025-03-18 22:31:57 +01:00
Alex Rønne Petersen
074dd4d083 mingw: Rename mingw32.lib to libmingw32.lib.
LLD expects the library file name (minus extension) to be exactly libmingw32. By
calling it mingw32 previously, we prevented it from being detected as being in
LLD's list of libraries that are excluded from the MinGW-specific auto-export
mechanism.

b9d27ac252/lld/COFF/MinGW.cpp (L30-L56)

As a result, a DLL built for *-windows-gnu with Zig would export a bunch of
internal MinGW symbols. This sometimes worked out fine, but it could break at
link or run time when linking an EXE with a DLL, where both are targeting
*-windows-gnu and thus linking separate copies of mingw32.lib. In #23204, this
manifested as the linker getting confused about _gnu_exception_handler() because
it was incorrectly exported by the DLL while also being defined in the
mingw32.lib that was being linked into the EXE.

Closes #23204.
2025-03-18 10:58:52 +01:00
Ali Cheraghi
ee06b2ce76 spirv: require int8/int16 capabilities 2025-03-18 07:05:50 +03:30
Ali Cheraghi
d18eaf8586 spirv: aligned load for physical storage variables
Resolves #23212
2025-03-18 07:05:50 +03:30
Ali Cheraghi
54c097f50d spirv: packed struct init + field val access 2025-03-18 07:05:48 +03:30
Ali Cheraghi
50539a2447 spirv/target: arbitrary_precision_integers feature support 2025-03-17 21:56:17 +03:30
Ali Cheraghi
e2e7577474 spirv: lower more types in assembler 2025-03-17 21:56:17 +03:30
Ali Cheraghi
78ad866dd1 target: split addresses and physical_storage_buffer features 2025-03-17 21:56:17 +03:30
Ali Cheraghi
c1977bf0fb Sema: error on illegal code when targeting spirv 2025-03-17 21:56:14 +03:30
Ali Cheraghi
2fc409a32f spirv: don't hardcode test error type alignment 2025-03-17 20:19:08 +03:30
mlugg
2a4e06bcb3 Sema: rewrite comptime arithmetic
This commit reworks how Sema handles arithmetic on comptime-known
values, fixing many bugs in the process.

The general pattern is that arithmetic on comptime-known values is now
handled by the new namespace `Sema.arith`. Functions handling comptime
arithmetic no longer live on `Value`; this is because some of them can
emit compile errors, so some *can't* go on `Value`. Only semantic
analysis should really be doing arithmetic on `Value`s anyway, so it
makes sense for it to integrate more tightly with `Sema`.

This commit also implements more coherent rules surrounding how
`undefined` interacts with comptime and mixed-comptime-runtime
arithmetic. The rules are as follows.

* If an operation cannot trigger Illegal Behavior, and any operand is
  `undefined`, the result is `undefined`. This includes operations like
  `0 *| undef`, where the LHS logically *could* be used to determine a
  defined result. This is partly to simplify the language, but mostly to
  permit codegen backends to represent `undefined` values as completely
  invalid states.

* If an operation *can* trigger Illegal Behvaior, and any operand is
  `undefined`, then Illegal Behavior results. This occurs even if the
  operand in question isn't the one that "decides" illegal behavior; for
  instance, `undef / 1` is undefined. This is for the same reasons as
  described above.

* An operation which would trigger Illegal Behavior, when evaluated at
  comptime, instead triggers a compile error. Additionally, if one
  operand is comptime-known undef, such that the other (runtime-known)
  operand isn't needed to determine that Illegal Behavior would occur,
  the compile error is triggered.

* The only situation in which an operation with one comptime-known
  operand has a comptime-known result is if that operand is undefined,
  in which case the result is either undefined or a compile error per
  the above rules. This could potentially be loosened in future (for
  instance, `0 * rt` could be comptime-known 0 with a runtime assertion
  that `rt` is not undefined), but at least for now, defining it more
  conservatively simplifies the language and allows us to easily change
  this in future if desired.

This commit fixes many bugs regarding the handling of `undefined`,
particularly in vectors. Along with a collection of smaller tests, two
very large test cases are added to check arithmetic on `undefined`.

The operations which have been rewritten in this PR are:

* `+`, `+%`, `+|`, `@addWithOverflow`
* `-`, `-%`, `-|`, `@subWithOverflow`
* `*`, `*%`, `*|`, `@mulWithOverflow`
* `/`, `@divFloor`, `@divTrunc`, `@divExact`
* `%`, `@rem`, `@mod`

Other arithmetic operations are currently unchanged.

Resolves: #22743
Resolves: #22745
Resolves: #22748
Resolves: #22749
Resolves: #22914
2025-03-16 08:17:50 +00:00
mlugg
aa3db7cc15 Sema: correctly handle empty by-ref initializers
Resolves: #23210
2025-03-16 03:05:33 +00:00
Rémy Mathieu
42160327dc
posix/write: catch MSGSIZE error (#23238) 2025-03-15 12:04:42 +01:00
Matthew Lugg
d0911786c9
Merge pull request #22397 from Techatrix/type-safe-ast
improve type safety of std.zig.Ast
2025-03-12 02:22:41 +00:00
mlugg
a0401cf3e4 Zcu: rename skip_analysis_errors to skip_analysis_this_update and respect it
On updates with failed files, we should refrain from doing any semantic
analysis, or even touching codegen/link. That way, incremental
compilation state is untouched for when the user fixes the AstGen
errors.

Resolves: #23205
2025-03-11 23:38:32 +00:00
Andrew Kelley
982c500be5
Merge pull request #23188 from jacobly0/fix-23143
x86_64: fix crashes with symbols
2025-03-11 16:11:09 -04:00
mlugg
423907c270 Sema: fix handling of @This() on opaques
Resolves: #22869
2025-03-11 13:13:52 +00:00
Mathias Lafeldt
7e751e8040
Merge pull request #23193 from mlafeldt/fix-macho-detection
Fetch: enhance Mach-O executable detection for modern Macs

closes #21044
2025-03-11 06:12:13 +00:00
Jacob Young
cff90e3ae0 x86_64: implement select of register mask 2025-03-10 10:38:33 -04:00
Jacob Young
0ef3250c34 x86_64: fix symbol bugs
Closes #23143
2025-03-10 10:38:30 -04:00
Jacob Young
e83607f52c Dwarf: remove comptime parameters from generic origin functions
Since generic instantiations are missing comptime arguments in Air, they
must be removed from the generic origins too.
2025-03-10 08:46:00 -04:00
Andrew Kelley
539f3effd3
Merge pull request #21933 from kcbanner/comptime_nan_comparison
Fix float vector comparisons with signed zero and NaN, add test coverage
2025-03-09 15:06:25 -04:00
Ian Johnson
0bce4a4e05 Sema: handle generated tag enums in union field order check
Fixes #23059

The "note: enum field here" now references the field in the base union type rather than crashing.
2025-03-08 14:29:20 -05:00
Andrew Kelley
61c588d726
Merge pull request #22998 from jacobly0/x86_64-rewrite
x86_64: rewrite aggregate init
2025-03-08 14:27:57 -05:00
Alex Rønne Petersen
3b3c18909d Compilation: Fix -fno-rtlib-defaultlib unused argument warning in ReleaseSafe.
Closes #23138.
2025-03-08 13:26:09 +01:00
Alex Rønne Petersen
5466a2f72d llvm: Replace DataLayoutBuilder with a simple target -> string switch.
This should be a lot easier to maintain. It's also a small step towards
eventually making the builder API parse the data layout string in order to
answer layout questions that we need to ask during code generation.
2025-03-08 12:16:13 +01:00
Jacob Young
5d115632d4 x86_64: reuse single register code during register write splitting 2025-03-07 23:59:38 -05:00
Jacob Young
54ed62755f x86_64: implement write register splitting 2025-03-07 23:59:31 -05:00
Jacob Young
f8f2a3ea6f x86_64: rewrite aggregate init 2025-03-07 23:59:09 -05:00
Alex Rønne Petersen
db77e46b49 zig cc: Don't pass -mabi for assembly files when targeting arm.
Clang's integrated Arm assembler doesn't understand -mabi yet, so this results
in "unused command line argument" warnings when building musl code and glibc
stubs, for example.
2025-03-08 03:52:28 +01:00
Techatrix
ca6fb30e99
std.zig.Ast: improve type safety
This commits adds the following distinct integer types to std.zig.Ast:
- OptionalTokenIndex
- TokenOffset
- OptionalTokenOffset
- Node.OptionalIndex
- Node.Offset
- Node.OptionalOffset

The `Node.Index` type has also been converted to a distinct type while
`TokenIndex` remains unchanged.

`Ast.Node.Data` has also been changed to a (untagged) union to provide
safety checks.
2025-03-07 22:22:01 +01:00
Techatrix
6dcd8f4f75
std.zig.Ast: add blockStatements and builtinCallParams 2025-03-07 22:20:35 +01:00
Techatrix
e6596cbbf0
add a reference to #21690 2025-03-07 22:20:35 +01:00
Linus Groh
79460d4a3e Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
Carl Åstholm
8363b95178 Fix "dependency path outside project" error for nested local path dependencies
Closes #23076
2025-03-04 17:27:21 -05:00
Carl Åstholm
711b0fef58 init: Substitute invalid package names with foo
Closes #23066
2025-03-04 02:42:00 -05:00
Matthew Lugg
c76f451abc
Merge pull request #22979 from mlugg/remove-legacy-coercions
Sema: remove legacy coercion
2025-03-03 22:18:28 +00:00
mlugg
501e84a96a incremental: invalidate namespace dependencies when a name changes visibility
We could have more fine-grained dependencies here, but I think this is
fine for now.
2025-03-03 22:18:02 +00:00