23805 Commits

Author SHA1 Message Date
Andrew Kelley
00b690540e llvm backend: fix lowering of memset
The bitcast of ABI size 1 elements was problematic for some types.
2023-04-28 13:24:42 -07:00
Andrew Kelley
fd6200eda6
Merge pull request #15431 from kcbanner/fix_decl_value_arena
sema: Rework Decl.value_arena to fix another memory corruption issue
2023-04-28 11:43:57 -07:00
Andrew Kelley
011bc59e8a
Merge pull request #15435 from jacobly0/x86_64-frame
x86_64: add frame indices
2023-04-27 15:45:01 -07:00
Andrew Kelley
aa3405aabc
Merge pull request #15474 from Luukdegram/wasm-atomics
wasm: implement atomic instructions
2023-04-27 08:26:35 -07:00
Jacob Young
8c52c6ec6c std: prevent the possibility of deadlocks in some threaded tests 2023-04-27 08:24:32 -07:00
Tw
131b328c10 translate-c: deduplicate global declaration
Fix #15456

Signed-off-by: Tw <weii.tan>
2023-04-27 11:13:16 +03:00
朕与将军解战袍
363269a2a9
fix incorrect struct definition 2023-04-27 11:10:38 +03:00
xEgoist
1a455b2dd8 test: Fix windows_spawn tmp directory cleanup
On Windows, a directory that's set as the current working directory is
not allowed to be removed. This can cause error on `deleteTree` if the
CWD is set to the file to be removed and will cause `error.FileBusy`.
However, due to `tmp.cleanup()` ignoring the errors, the folder removal error will
be ignored. The only test violating this is `windows_spawn`. As a
solution, setting the parent directory to be the CWD before deletion
will allow the cleanup to pass.
2023-04-27 11:01:02 +03:00
kcbanner
15dafd16e6 sema: add prev to ValueArena to allow freeing previous arenas when new ones are created during re-analysis
In semaDecl, it was possible for a new ArenaAllocators state to replace an existing one that
hadn't been freed yet. Instead of the ref_count (which was made redundant by adding
the allocator parameter to `release`), I now store a pointer to the previous arena, if one exists.

This allows a recursive deinit to happen when the last arena created is destroyed.
2023-04-27 01:11:57 -04:00
kcbanner
2b592d7e3c sema: Rework Decl.value_arena to fix another memory corruption issue
This fixes a bug where resolveStructLayout to was promoting from stale
value_arena state which was then overwrriten when another ArenaAllocator
higher in the call stack saved its state back. This resulted in the memory
for struct_obj.optmized_order overlapping existing allocations.

My initial fix in c7067ef wasn't sufficient, as it only checked if the struct being
resolved had the same owner as the current sema instance. However, it's
possible for resolveStructLayout to be called when the sema instance
has a different owner, but the struct decl's value_arena is currently in
use higher up in the callstack.

This change introduces ValueArena, which holds the arena state as well as tracks
if an arena has already been promoted from it. This allows callers to use the
value_arena storage without needing to be aware of another user of this same storage
higher up in the call stack.
2023-04-27 01:11:57 -04:00
Andrew Kelley
396bd51c48 enable debugging infrastructure when using C backend
Thanks to @jacobly0's recent enhancements to the C backend, this stuff
works now.
2023-04-26 20:56:21 -07:00
Andrew Kelley
afbcad9939
Merge pull request #15452 from mlugg/zig-cbe-opt
CBE: minor optimizations to output source
2023-04-26 17:09:04 -07:00
Jakub Konka
f56054d129 coff: invalidate GOT relocs after segment shift in memory 2023-04-26 19:08:38 -04:00
Jakub Konka
bc69d5a00f macho: invalidate GOT/stub relocs after segment shift in memory 2023-04-26 19:08:38 -04:00
Jacob Young
b5b0b55582 x86_64: fix tlv references 2023-04-26 19:05:17 -04:00
Jacob Young
eff0e6a726 x86_64: fix rem/mod behavior and hazards 2023-04-26 19:05:17 -04:00
Jacob Young
a8842b6cbf cases: disable broken backends
Disable backends that don't support the new liveness format.
2023-04-26 19:05:17 -04:00
Jacob Young
894406b9d3 behavior: update passing cbe tests 2023-04-26 19:05:17 -04:00
Jacob Young
1f18b53589 x86_64: fix some floating point encoding errors 2023-04-26 19:05:17 -04:00
Jacob Young
26d4f9b69e x86_64: add frame indices
This allows abstract references to the stack frame which enables:
 * deferred frame layout until after the function has been processed
 * frame compaction (sorting by alignment)
 * being able to overalign the stack
 * references that change based on an overaligned stack
 * moving callee saved spills to the usual part (smaller code size)
 * shared call frame (avoids stack adjustments before and after calls)
2023-04-26 19:05:17 -04:00
Jan Philipp Hafer
f618398b24 compiler_rt: document ARM status
This commit documents the status of Run-time ABI 2022Q3 for ARM excluding
C++ helper functions.
2023-04-26 15:32:05 -07:00
Meghan
66da64d77c
std.http: fix name of Status field to better match RFC name (#15455)
.header_fields_too_large -> .request_header_fields_too_large
2023-04-26 14:02:55 -04:00
Andrew Kelley
3c66850e42
Merge pull request #15278 from ziglang/memcpy-memset
change semantics of `@memcpy` and `@memset`
2023-04-26 10:01:54 -07:00
Loris Cro
d0311e28b3 autodoc: fix sidebar regression and other minor bugs 2023-04-26 18:20:41 +02:00
Loris Cro
b294bff1a8
Autodoc: new decl search system (#15475)
New search system is based on a Radix Tree. The Radix Tree contains a shallow list of all decl names (ie no paths), plus some suffixes, split by following the official style guide (eg "HashMapUnmanaged" also produces "MapUnmanaged" and "Unmanaged", same with snake_case and camelCase names).

Additionally, the search system uses the decl graph data to recognize hierarchical relationships between decls, allowing you to zero on a target namespace for search. As an example "fs create" will score highe all things related to the creation of files and directories inside of `std.fs`, while still showing (but with lower score) matches from `std.Bulild`. 

As another example "fs windows" will prioritize windows-related results in `std.fs`, while "windows fs" will prioritize fs-related results in `std.windows`.
2023-04-26 18:17:20 +02:00
kcbanner
b55b8e7745 add support for .field_ptr in elemValueAdvanced
This fixes a crash when @compileLog is passed a slice backed by an aggregate field at comptime.
2023-04-26 17:31:42 +03:00
Casey Banner
bc4d9f3aa9
translate-c: fix codegen when C source has variables named the same as mangling prefixes
If the C code had variables that were named the same as the prefixes used
for name mangling, such as "tmp" or "ref", then the codegen would generate
incorrect code in some cases. This was because these aliases were immediately
visible to expressions that actually needed to use the original name.

I introduced the concept of reserving aliases without enabling them. An alias
that isn't enabled isn't visible to expression translation, but is still
reserved so that sub-expressions generate aliases that don't overlap.

Add test cases to cover the cases that would break before this change.

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2023-04-26 17:30:46 +03:00
Luuk de Gram
1d97181703
wasm: enable atomics behavior tests 2023-04-26 16:28:41 +02:00
Luuk de Gram
b26a46d05b
wasm: support pointers in cmpxchg 2023-04-26 16:28:41 +02:00
Luuk de Gram
7c09e09457
wasm: implement atomic stores 2023-04-26 16:28:41 +02:00
Luuk de Gram
0e3303ccd9
wasm: implement @fence
Uses the `atomic.fence` instruction for multi-thread-enabled builds
where the `atomics` feature is enabled for the wasm32 target.
In all other cases, this lowers to a nop.
2023-04-26 16:28:41 +02:00
Luuk de Gram
b19c258f04
wasm: implement @atomicRmw
Implements the lowering of the `@atomicRmw` builtin. Uses the atomic
opcodes when the cpu feature `atomics` is enabled. Otherwise lowers
it to regular instructions. For the operations that do not lower to
a direct atomic opcode, we use a loop in combiantion with a cmpxchg
to ensure the swapping of values is doing atomically.
2023-04-26 16:28:40 +02:00
Luuk de Gram
fd47eddc86
wasm: implement @atomicLoad
Uses the atomic instructions when cpu feature is enabled, otherwise
lowers it down to a regular load.
2023-04-26 16:28:40 +02:00
Luuk de Gram
650976b226
wasm: use atomic feature for @cmpxchg when enabled
When the user passes the cpu feature `atomics` to the target triple,
the backend will lower the AIR instruction using opcodes from the
atomics feature instead of manually lowering it.
2023-04-26 16:28:40 +02:00
Luuk de Gram
5bbd482286
wasm: implement cmpxchg{weak/strong} 2023-04-26 16:28:37 +02:00
Nameless
7285eedcd2 std.http: do -> wait, fix redirects 2023-04-26 00:02:55 -07:00
Andrew Kelley
13101295b9
Merge pull request #15454 from jacobly0/cbe-extern
cbe: implement `@extern`
2023-04-25 23:48:03 -07:00
mlugg
3df2f356eb
Sema: avoid emitting sequential dbg_stmt instructions
Often, a `dbg_stmt` ends up being associated with no real code because
whatever it referred to was eliminated by semantic analysis. In these
cases, Sema can replace the last `dbg_stmt` with the new one to avoid
redundant AIR instructions which at best are nops and at worst cause
backends to emit useless info (e.g. CBE does this).
2023-04-26 01:46:09 +01:00
mlugg
2e23ddbe7b
CBE: minor optimizations to output source 2023-04-26 01:46:09 +01:00
kcbanner
295b8ca467 sema: add error for coercing a slice to an anyopaque pointer 2023-04-26 00:53:09 +03:00
Janne Hellsten
61236c2aa1
std: @Vector support for std.json.parse 2023-04-26 00:52:17 +03:00
Andrew Kelley
5b9e528bc5 CI: give aarch64-linux a maxrss parameter
to avoid getting OOM killed. We need to have a high number of GitHub
Actions runners simultaneously active, otherwise the hardware ends up
underutilized. But with zig build running in parallel now, this
sometimes results in memory usage spikes that have been causing the
runner to get killed.

This number is the total physical memory (251G) divided by the number of
runners we have active (11).

See related commit 2d41dac57d3afdd5fe3d03be08ff0a24833f61dd which did
the same but for our x86_64-linux machines.
2023-04-25 12:46:39 -07:00
Loris Cro
e0ee9d38cf
Merge pull request #15414 from der-teufel-programming/autodoc-pkg-mod
autodoc: Change package to module to better reflect the new names
2023-04-25 20:24:40 +02:00
Andrew Kelley
badad16f88 C backend: fix lowering comparison when array ptr meets ptr
Pointer comparisons were triggering `-Wcompare-distinct-pointer-types`
before this fix, which adds `(void*)` casts if the lhs type and rhs type
do not match pointer sizeness.
2023-04-25 11:23:41 -07:00
Andrew Kelley
401b7f6f53 zig fmt 2023-04-25 11:23:41 -07:00
Andrew Kelley
792bbfa301 Sema: fix memcpy alias safety incorrect math
Previously it was not multiplying by the element ABI size. Now, it uses
ptr_add instructions which do math based on the element type.
2023-04-25 11:23:41 -07:00
Andrew Kelley
5378fdffdc stage2: introduce store_safe AIR instruction
store:
The value to store may be undefined, in which case the destination
memory region has undefined bytes after this instruction is
evaluated. In such case ignoring this instruction is legal
lowering.

store_safe:
Same as `store`, except if the value to store is undefined, the
memory region should be filled with 0xaa bytes, and any other
safety metadata such as Valgrind integrations should be notified of
this memory region being undefined.
2023-04-25 11:23:41 -07:00
Andrew Kelley
d604553ee0 C backend: use ++ instead of += for airMemset
It does the same thing but has fewer bytes in the output.
2023-04-25 11:23:41 -07:00
Andrew Kelley
1ba72bcf9a update test cases for new memcpy/memset semantics 2023-04-25 11:23:41 -07:00
Andrew Kelley
747f58366a wasm backend: fix airMemset with slices 2023-04-25 11:23:41 -07:00