7724 Commits

Author SHA1 Message Date
Alex Rønne Petersen
8af82621d7
compiler: Improve the handling of unwind table levels.
The goal here is to support both levels of unwind tables (sync and async) in
zig cc and zig build. Previously, the LLVM backend always used async tables
while zig cc was partially influenced by whatever was Clang's default.
2024-12-11 00:10:15 +01:00
Andrew Kelley
7575f21212
Merge pull request #22157 from mlugg/astgen-error-lazy
compiler: allow semantic analysis of files with AstGen errors
2024-12-09 18:32:23 -05:00
Andrew Kelley
8245d7fac0
Merge pull request #22164 from mlugg/astgen-ref-dedup
AstGen: correctly deduplicate `ref` of `param` and `alloc_inferred`
2024-12-09 18:04:26 -05:00
wooster0
a221b2fbf2 Sema: fix use of Zcu.LazySrcLoc in error message
It currently prints as:

:3:18: error: untagged union 'Zcu.LazySrcLoc{ .base_node_inst = InternPool.TrackedInst.Index(104), .offset = Zcu.LazySrcLoc.Offset{ .node_offset = Zcu.LazySrcLoc.Offset.TracedOffset{ .x = -2, .trace = (value tracing disabled) } } }' cannot be converted to integer
2024-12-08 17:23:57 +00:00
Jacob Young
bd0ace5c4e
cbe: prevent tautological-compare warnings in generated code 2024-12-08 10:53:50 +00:00
mlugg
03f5b967f0
AstGen: correctly deduplicate ref of param and alloc_inferred
Both of these instructions were previously under a special case in
`rvalue` which resulted in every reference to such an instruction adding
a new `ref` instruction. This had the effect that, for instance,
`&a != &a` for parameters. Deduplicating these `ref` instructions was
problematic for different reasons.

For `alloc_inferred`, the problem was that it's not valid to `ref` the
alloc until the allocation has been resolved (`resolve_inferred_alloc`),
but `AstGen.appendBodyWithFixups` would place the `ref` directly after
the `alloc_inferred`. This is solved by bringing
`resolve_inferred_alloc` in line with `make_ptr_const` by having it
*return* the final pointer, rather than modifying `sema.inst_map` of the
original `alloc_inferred`. That way, the `ref` refers to the
`resolve_inferred_alloc` instruction, so is placed immediately after it,
avoiding this issue.

For `param`, the problem is a bit trickier: `param` instructions live in
a body which must contain only `param` instructions, then a
`func{,_inferred,_fancy}`, then a `break_inline`. Moreover, `param`
instructions may be referenced not only by the function body, but also
by other parameters, the return type expression, etc. Each of these
bodies requires separate `ref` instructions. This is solved by pulling
entries out of `ref_table` after evaluating each component of the
function declaration, and appending the refs later on when actually
putting the bodies together. This gives way to another issue: if you
write `fn f(x: T) @TypeOf(x.foo())`, then since `x.foo()` takes a
reference to `x`, this `ref` instruction is now in a comptime context
(outside of the `@TypeOf` ZIR body), so emits a compile error. This is
solved by loosening the rules around `ref` instructions; because they
are not side-effecting, it is okay to allow `ref` of runtime values at
comptime, resulting in a runtime-known value in a comptime scope. We
already apply this mechanism in some cases; for instance, it's why
`runtime_array.len` works in a `comptime` context. In future, we will
want to give similar treatment to many operations in Sema: in general,
it's fine to apply runtime operations at comptime provided they don't
have side effects!

Resolves: #22140
2024-12-08 10:53:50 +00:00
Alex Rønne Petersen
ba37a4369b std.zig.WindowsSdk: Support cross-arch SDK lookups.
This makes e.g. cross-compiling for x86-windows-msvc on a x86_64-windows-msvc
system work properly.

Closes #11926.
2024-12-08 04:53:28 +01:00
mlugg
4d7818a76a
compiler: allow files with AstGen errors to undergo semantic analysis
This commit enhances AstGen to introduce a form of error resilience
which allows valid ZIR to be emitted even when AstGen errors occur.

When a non-fatal AstGen error (e.g. `appendErrorNode`) occurs, ZIR
generation is not affected; the error is added to `astgen.errors` and
ultimately to the errors stored in `extra`, but that doesn't stop us
getting valid ZIR. Fatal AstGen errors (e.g. `failNode`) are a bit
trickier. These errors return `error.AnalysisFail`, which is propagated
up the stack. In theory, any parent expression can catch this error and
handle it, continuing ZIR generation whilst throwing away whatever was
lost. For now, we only do this in one place: when creating declarations.
If a call to `fnDecl`, `comptimeDecl`, `globalVarDecl`, etc, returns
`error.AnalysisFail`, the `declaration` instruction is still created,
but its body simply contains the new `extended(astgen_error())`
instruction, which instructs Sema to terminate semantic analysis with a
transitive error. This means that a fatal AstGen error causes the
innermost declaration containing the error to fail, but the rest of the
file remains intact.

If a source file contains parse errors, or an `error.AnalysisFail`
happens when lowering the top-level struct (e.g. there is an error in
one of its fields, or a name has multiple declarations), then lowering
for the entire file fails. Alongside the existing `Zir.hasCompileErrors`
query, this commit introduces `Zir.loweringFailed`, which returns `true`
only in this case.

The end result here is that files with AstGen failures will almost
always still emit valid ZIR, and hence can undergo semantic analysis on
the parts of the file which are (from AstGen's perspective) valid. This
is a noteworthy improvement to UX, but the main motivation here is
actually incremental compilation. Previously, AstGen failures caused
lots of semantic analysis work to be thrown out, because all `AnalUnit`s
in the file required re-analysis so as to trigger necessary transitive
failures and remove stored compile errors which would no longer make
sense (because a fresh compilation of this code would not emit those
errors, as the units those errors applied to would fail sooner due to
referencing a failed file). Now, this case only applies when a file has
severe top-level errors, which is far less common than something like
having an unused variable.

Lastly, this commit changes a few errors in `AstGen` to become fatal
when they were previously non-fatal and vice versa. If there is still a
reasonable way to continue AstGen and lower to ZIR after an error, it is
non-fatal; otherwise, it is fatal. For instance, `comptime const`, while
redundant syntax, has a clear meaning we can lower; on the other hand,
using an undeclared identifer has no sane lowering, so must trigger a
fatal error.
2024-12-05 19:58:38 +00:00
Alex Rønne Petersen
09b39f77b7
std.Target: Remove Os.Tag.bridgeos.
It doesn't appear that targeting bridgeOS is meaningfully supported by Apple.
Even LLVM/Clang appear to have incomplete support for it, suggesting that Apple
never bothered to upstream that support. So there's really no sense in us
pretending to support this.
2024-12-03 20:43:15 +01:00
Alex Rønne Petersen
1731510933
test: Add x86_64-linux-(gnux32,muslx32) to module tests. 2024-12-01 02:23:55 +01:00
Pat Tullmann
5e1a83ad29 defaultPanic: @trap on 'other' target
The freestanding and other OS targets by default need to just @trap in the
default Panic implementation.

And `isValidMemory` won't work with freestanding or other targets.

Update the unwind_freestanding.zig test case to also run on the 'other' OS
target, too.  This should keep the Zig's stacktrace generation from
regressing on the standalone targets.
2024-11-29 15:30:05 -05:00
Andrew Kelley
a47aa9dd9d
Merge pull request #22095 from alexrp/test-llvm-emit
Change `llvm_targets` tests to actually emit objects, and fix bugs found as a result
2024-11-29 15:28:54 -05:00
mlugg
c3821fe4ca compiler: use @Type instead of @TypeOf to print enum literal type 2024-11-29 15:26:58 -05:00
Andrew Kelley
cfdb001a8f
Merge pull request #22099 from Rexicon226/fix-cat-mul
change `++` and `**` to not return mutable pointers
2024-11-29 15:05:49 -05:00
David Rubin
77f16d457b
test: adjust behaviour test to new concat/mul semantics 2024-11-28 18:05:36 -08:00
Alex Rønne Petersen
78b8ce5095
test: Change llvm_targets to actually emit an object for each target.
Without doing this, we don't actually test whether the data layout string we
generate matches LLVM's.

A number of targets had to be commented out due to this change:

* Some are using a non-working experimental LLVM backend (arc, csky, ...).
* Some don't have working LLD support (lanai, sparc, ...).
* Some don't have working self-hosted linker support (nvptx).
* Some are using ABIs that haven't been standardized (loongarch32).

Finally, all non-x86 uefi targets are hopelessly broken and can't really be
fixed until we change our emit logic to lower *-uefi-* verbatim rather than to
*-windows-*. See: https://github.com/ziglang/zig/issues/21630
2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
0bf054f4c5
test: Remove aarch64(_be)-linux-gnuilp32 from llvm_targets.
LLVM doesn't handle this target correctly (pointer size, etc).
2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
abf3032ff1
test: Add m68k-linux-musl to llvm_targets. 2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
322013c648
test: Add aarch64(_be)-linux-musl to llvm_targets. 2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
11d51ea5a2
test: Remove aarch64-rtems-ilp32 from llvm_targets.
LLVM can't represent this target at the moment.
2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
4369d3b93d
test: Add *-windows-cygnus triples to llvm_targets. 2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
8594f179f9
Merge pull request #22067 from alexrp/pie-tests
Add PIC/PIE tests and fix some bugs + some improvements to the test harness
2024-11-28 14:07:28 +01:00
Jacob Young
c894ac09a3 dwarf: fix stepping through an inline loop containing one statement
Previously, stepping from the single statement within the loop would
always exit the loop because all of the code unrolled from the loop is
associated with the same line and treated by the debugger as one line.
2024-11-24 17:28:12 -05:00
Alex Rønne Petersen
5beb5f20d2
test: Set emit_bin=false for some safety tests.
This should hopefully be reverted soon with Andrew's work on the self-hosted
wasm linker.

error: thread 171731 panic: integer overflow
/home/alexrp/Source/ziglang/zig/src/link/Wasm.zig:2392:32: 0x22b709e in setupMemory (zig)
        break :index sym.index - wasm.imported_globals_count;
                               ^
/home/alexrp/Source/ziglang/zig/src/link/Wasm.zig:2678:25: 0x1ed1be6 in flushModule (zig)
    try wasm.setupMemory();
                        ^
/home/alexrp/Source/ziglang/zig/src/link/Wasm.zig:2619:28: 0x1c2e4d4 in flush (zig)
    return wasm.flushModule(arena, tid, prog_node);
                           ^
/home/alexrp/Source/ziglang/zig/src/link.zig:874:77: 0x1a55ad7 in flush (zig)
                return @as(*tag.Type(), @fieldParentPtr("base", base)).flush(arena, tid, prog_node);
                                                                            ^
/home/alexrp/Source/ziglang/zig/src/Compilation.zig:2411:17: 0x1a553f9 in flush (zig)
        lf.flush(arena, tid, prog_node) catch |err| switch (err) {
                ^
/home/alexrp/Source/ziglang/zig/src/Compilation.zig:2371:22: 0x1a58d60 in update (zig)
            try flush(comp, arena, .{
                     ^
/home/alexrp/Source/ziglang/zig/src/main.zig:4114:32: 0x1ae392b in serve (zig)
                try comp.update(main_progress_node);
                               ^
/home/alexrp/Source/ziglang/zig/src/main.zig:3555:22: 0x1b05322 in buildOutputType (zig)
            try serve(
                     ^
/home/alexrp/Source/ziglang/zig/src/main.zig:265:31: 0x195faca in mainArgs (zig)
        return buildOutputType(gpa, arena, args, .{ .build = .Obj });
                              ^
/home/alexrp/Source/ziglang/zig/src/main.zig:200:20: 0x195c995 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/home/alexrp/Source/ziglang/zig/lib/std/start.zig:617:37: 0x195c49e in main (zig)
            const result = root.main() catch |err| {
                                    ^
2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
1d1ca84854
test: Set emit_bin=false for spirv_mergable_pointers.zig.
/home/alexrp/.cache/zig/b/18236e302af25e3fb99bc6a232ddc447/builtin.zig:6:5: error: TODO (SPIR-V): Implement unsigned composite int type of 64 bits
pub const zig_backend = std.builtin.CompilerBackend.stage2_spirv64;
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
4b16d81318
test: Set emit_bin=false for all nvptx tests.
error: thread 165232 panic: TODO: rewrite the NvPtx.flushModule function
/home/alexrp/Source/ziglang/zig/src/link/NvPtx.zig:123:5: 0x1ed99ce in flushModule (zig)
    @panic("TODO: rewrite the NvPtx.flushModule function");
    ^
/home/alexrp/Source/ziglang/zig/src/link/NvPtx.zig:110:28: 0x1c2e7e6 in flush (zig)
    return self.flushModule(arena, tid, prog_node);
                           ^
/home/alexrp/Source/ziglang/zig/src/link.zig:874:77: 0x1a55bd3 in flush (zig)
                return @as(*tag.Type(), @fieldParentPtr("base", base)).flush(arena, tid, prog_node);
                                                                            ^
/home/alexrp/Source/ziglang/zig/src/Compilation.zig:2411:17: 0x1a553f9 in flush (zig)
        lf.flush(arena, tid, prog_node) catch |err| switch (err) {
                ^
/home/alexrp/Source/ziglang/zig/src/Compilation.zig:2348:22: 0x1a595ba in update (zig)
            try flush(comp, arena, .{
                     ^
/home/alexrp/Source/ziglang/zig/src/main.zig:4114:32: 0x1ae392b in serve (zig)
                try comp.update(main_progress_node);
                               ^
/home/alexrp/Source/ziglang/zig/src/main.zig:3555:22: 0x1b05322 in buildOutputType (zig)
            try serve(
                     ^
/home/alexrp/Source/ziglang/zig/src/main.zig:265:31: 0x195faca in mainArgs (zig)
        return buildOutputType(gpa, arena, args, .{ .build = .Obj });
                              ^
/home/alexrp/Source/ziglang/zig/src/main.zig:200:20: 0x195c995 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/home/alexrp/Source/ziglang/zig/lib/std/start.zig:617:37: 0x195c49e in main (zig)
            const result = root.main() catch |err| {
                                    ^
2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
2298108daf
test: Allow tests to set emit_bin=false. 2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
c4cd3c0541
test: Force compile test cases to be codegen'd if requested. 2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
ad2be71514
test: Add test cases for PIC/PIE on various supported platforms.
Closes #22052.
2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
fefcdc5673
test: Allow setting PIC/PIE in test cases. 2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
9d10246a80
test: Enable -Dtest-target-filter=... to work for test-debugger. 2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
2a29381117
test: Enable -Dtest-target-filter=... to work for test-cases and test-translate-c. 2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
9c7776a938
test: Enable -Dtest-target-filter=... to work for test-c-abi. 2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
24ecf45569
std.Target: Add Os.HurdVersionRange for Os.Tag.hurd.
This is necessary since isGnuLibC() is true for hurd, so we need to be able to
represent a glibc version for it.

Also add an Os.TaggedVersionRange.gnuLibCVersion() convenience function.
2024-11-24 22:11:16 +01:00
Jacob Young
70ad7dcd48 lldb: implement tuple types 2024-11-23 23:51:35 -05:00
Alex Rønne Petersen
aef5c75602 compiler: Disallow align(0) everywhere in the language.
Thus leaving the design space for this alignment value open, e.g. for packing.
2024-11-23 18:44:07 -05:00
xdBronch
5f3a70ed5f Fix peer type resolution with allowzero pointers 2024-11-20 02:09:50 +02:00
Jacob Young
a8ec306b49 Sema: fix peer resolution alignment between slice and empty struct
An empty struct that coerces to an empty array should not force
`align(1)` on the resulting slice type.
2024-11-16 21:22:57 -05:00
Jacob Young
11e54a3559 link: fix failing incremental test cases 2024-11-16 14:03:31 -05:00
mlugg
bbbc95afd0 AstGen: add missing rvalue call to labeledBlockExpr
...and fix a minor x86_64 backend bug exposed by this fix.

Resolves: #21974
2024-11-12 14:51:10 +00:00
mlugg
6e56bc1096
test: add new incremental case
This is similar to the old `llvm/shift_right_plus_left` case, which was
disabled by 1b1c78c. The case is not enabled on the LLVM backend, since
incremental compilation support for this backend is a work in progress
and is tracked by #21165. It passes on the x86_64-linux target with the
self-hosted backend.

Resolves: #12288
2024-11-11 12:22:55 +00:00
mlugg
ca12e4f33e
test: remove old-style incremental cases, add a few new incremental cases
These cases have been disabled for a while, and we have transitioned to
using a compact file format for incremental test cases.

I was originally planning to port all of these cases, but the vast
majority aren't testing anything interesting, so it wasn't worth the
effort. I did look through each one; anything interesting being tested
has been extracted into a new case in `test/incremental/`.

Two of the new tests are currently failing with the self-hosted ELF
linker, and thus are currently only enabled with the C backend.

Resolves: #12844
2024-11-11 12:22:48 +00:00
Wooster
35201e9d93 Sema: fix wording in error message
It's an FQN, not an actual file name.
2024-11-09 20:21:32 +00:00
Alex Rønne Petersen
f25ea264b7 Revert "test: Add aarch64_be-linux-(none,gnu,musl) to module tests."
This reverts commit 4049be90de6a557c1ab522363fddbb71d3ccdb18.

See: https://github.com/ziglang/zig/issues/21911
2024-11-05 07:15:53 +01:00
Alex Rønne Petersen
4049be90de
test: Add aarch64_be-linux-(none,gnu,musl) to module tests. 2024-11-04 08:29:42 +01:00
Alex Rønne Petersen
9d0bb7ada8
test: Disable 128-bit atomics behavior tests on aarch64_be.
See: https://github.com/ziglang/zig/issues/21892
2024-11-04 08:29:42 +01:00
Alex Rønne Petersen
2958a90515
test: Disable some vector behavior tests on aarch64_be.
See: https://github.com/ziglang/zig/issues/21893
2024-11-04 08:29:42 +01:00
Alex Rønne Petersen
b72b81292f
test: Remove some unsupported ohos triples from llvm_targets. 2024-11-04 08:29:42 +01:00
Alex Rønne Petersen
96ea7d3e1c
test: Disable reinterpret packed union on all big endian targets.
See: https://github.com/ziglang/zig/issues/21050
2024-11-04 08:29:42 +01:00
Alex Rønne Petersen
3054486d1d
Merge pull request #21843 from alexrp/callconv-followup
Some follow-up work for #21697
2024-11-03 14:27:09 +01:00