24254 Commits

Author SHA1 Message Date
Luuk de Gram
e36cc0ce8f
wasm: union_init support packed unions 2023-05-31 18:04:33 +02:00
Luuk de Gram
128814f9bf
wasm: aggregate_init store sentinel for arrays 2023-05-31 18:04:32 +02:00
Luuk de Gram
969f921162
wasm: ptr_elem_val use pointer type for local
When storing the address after calculating the element's address,
ensure it's stored in a local with the correct type. Previously it
would incorrectly use the element's type, which could be a float for
example and therefore generate invalid WebAssembly code.

This change also introduces a more robust `store` function.
2023-05-31 18:04:32 +02:00
Luuk de Gram
ffa89d3b83
wasm: UnwrapErrUnionPayloadPtr ensure ptr ret
When the paylaod is zero-sized we must ensure a valid pointer
is still returned for the ptr variation of the instruction. This,
because it's valid to have a pointer to a zero-sized value.
In such a case, we simply return the operand.
2023-05-31 18:04:32 +02:00
Luuk de Gram
3c72b4d25e
wasm: support and optimize for all packed unions
For packed unions where its abi size is less than or equal to 8 bytes
we store it directly and don't pass it by reference. This means that
when retrieving the field, we will perform shifts and bitcasts to ensure
the correct type is returned. For larger packed unions, we either allocate
a new stack value based on the field type when the field type is also passed
by reference, or load it directly into a local if it's not.
2023-05-31 18:04:32 +02:00
Luuk de Gram
7cfc44d86f
wasm: implement struct_field_val for packed unions
We currently have `isRef` return true for any type of union, including
packed unions. This means we can simply load it from the data section
to the exact type we want. In the future we can optimize it so it works
similarly to packed structs below 64 bits which do not get stored in
the data section and are not passed by ref.
2023-05-31 18:04:32 +02:00
Luuk de Gram
49fddbf4c1
wasm: union_init correctly store the tag
Previously we would only store the payload, but not the actual tag
that was set. This meant miscompilations where it would incorrectly
return the tag value.

This also adds a tiny optimization for payloads which are not `byRef`
by directly storing them based on offset, rather than first calculating
a pointer to an offset.
2023-05-31 18:04:32 +02:00
Luuk de Gram
00dedabc41
wasm: memcpy support elem abi-size > 1
Previously it was incorrectly assumed that all memcopy's generated by
the `memcpy` AIR instruction had an element size of 1 byte. However,
this would result in miscompilations for pointer's to arrays where
the element size of the array was larger than 1 byte. We now corectly
calculate this size.
2023-05-31 18:04:31 +02:00
yujiri8
cd1417dbdf
don't crash when can't evaluate comptime expression with inferred type
Closes #15911.
2023-05-31 11:15:52 +00:00
Bogdan Romanyuk
32e719e070
sema: add compile error for incorrect extern type 2023-05-31 04:38:32 +00:00
Jakub Konka
76aa1fffb7
Merge pull request #15905 from jacobly0/x86_64-hotfix
x86_64: hotfix for crash during in-memory coercion of large type
2023-05-30 13:22:13 +02:00
Frank Denis
1ab008d89d
RSA: remove usage of allocators (#15901)
Individual max buffer sizes are well known, now that arithmetic doesn't
require allocations any more.

Also bump `main_cert_pub_key_buf`, so that e.g. `nodejs.org` public
keys can fit.
2023-05-30 10:06:44 +00:00
kcbanner
9244e4fe2d cache: handle 0-length prefix paths in findPrefixResolved 2023-05-30 01:21:01 -07:00
Andrew Kelley
22b0457dd4
Merge pull request #15891 from mlugg/fix/dont-emit-fn-called-at-comptime
Prevent analysis of functions only referenced at comptime
2023-05-29 23:41:40 -07:00
Motiejus Jakštys
ac9f72d87e zig ld: handle --library :path/to/lib.so
`-l :path/to/lib.so` behavior on gcc/clang is:

- the path is recorded as-is: no paths, exact filename (`libX.so.Y`).
- no rpaths.

The previous version removed the `:` and pretended it's a positional
argument to the linker. That works in almost all cases, except in how
rules_go[1] does things (the Bazel wrapper for Go).

Test case in #15743, output:

    gcc rpath:
     0x0000000000000001 (NEEDED)     Shared library: [libversioned.so.2]
     0x000000000000001d (RUNPATH)    Library runpath: [$ORIGIN/x]
    gcc plain:
     0x0000000000000001 (NEEDED)     Shared library: [libversioned.so.2]
    zig cc rpath:
     0x0000000000000001 (NEEDED)     Shared library: [libversioned.so.2]
     0x000000000000001d (RUNPATH)    Library runpath: [$ORIGIN/x]
    zig cc plain:
     0x0000000000000001 (NEEDED)     Shared library: [libversioned.so.2]

Fixes #15743

[1]: https://github.com/bazelbuild/rules_go
2023-05-30 08:18:10 +02:00
Jacob Young
28df1d09dc Revert "Revert "Windows: Support UNC, rooted, drive relative, and namespaced/device paths""
This reverts commit b5fad3a40a86eb379903d6a803bdbe66dcaa5487.

The latent x86_64 backend bug has been fixed.
2023-05-29 22:09:13 -04:00
Jacob Young
0c438ab616 x86_64: hotfix for crash during in-memory coercion of large type
Unblocks #15768
Closes #15904
2023-05-29 22:03:27 -04:00
Andrew Kelley
706bdf6512 std.debug: disable sporadically failing test
This was observed to fail on aarch64-windows as well.

See tracking issue #13963
2023-05-29 16:29:19 -07:00
Andrew Kelley
82632aff2c build.zig: bump maxrss upper bound for std lib tests 2023-05-29 15:53:41 -07:00
mlugg
0f58d34ef7
tests: disable incremental cases for now
These were failing on the prior commit. Unfortunately, the fix would
have been relatively complicated, and ties into underlying issues with
the current incremental compilation logic. After discussing this with
Andrew, we agreed that the best course of action is to completely
disable incremental compilation tests for now until it's more mature, at
which point we can re-enable them.
2023-05-29 23:06:11 +01:00
mlugg
4976b58ab1
Prevent analysis of functions only referenced at comptime
The idea here is that there are two ways we can reference a function at runtime:

* Through a direct call, i.e. where the function is comptime-known
* Through a function pointer

This means we can easily perform a form of rudimentary escape analysis
on functions. If we ever see a `decl_ref` or `ref` of a function, we
have a function pointer, which could "leak" into runtime code, so we
emit the function; but for a plain `decl_val`, there's no need to.

This change means that `comptime { _ = f; }` no longer forces a function
to be emitted, which was used for some things (mainly tests). These use
sites have been replaced with `_ = &f;`, which still triggers analysis
of the function body, since you're taking a pointer to the function.

Resolves: #6256
Resolves: #15353
2023-05-29 23:06:08 +01:00
Andrew Kelley
b5fad3a40a Revert "Windows: Support UNC, rooted, drive relative, and namespaced/device paths"
This reverts commit 1697d44809151e4759f6b5f9447a908c30ac1e84.

Master branch started failing after this commit landed.
2023-05-29 15:01:24 -07:00
David CARLIER
138f1253de std.os: fix uname usage.
close #15839.
2023-05-29 22:08:43 +03:00
mlugg
e2837fd224 Sema: return comptime_int if all args to @min/@max are comptime_int
Resolves: #15776
2023-05-29 11:32:13 -07:00
mlugg
46e724ab28 std.dwarf: handle DWARF 5 compile unit DW_AT_ranges correctly
This data changed quite significantly between DWARF 4 and 5. Some
systems are shipping DWARF 5 libraries (Void Linux on musl libc seems to
use it for crt1 etc), which meant when printing stack traces, a random
compile unit might be incorrectly identified as containing an address,
resulting in incorrect location information.

I was consistently experiencing this issue with compiler stack traces,
and this change fixed it.
2023-05-29 11:28:39 -07:00
Ryan Liptak
1697d44809 Windows: Support UNC, rooted, drive relative, and namespaced/device paths
There are many different types of Windows paths, and there are a few different possible namespaces on top of that. Before this commit, NT namespaced paths were somewhat supported, and for Win32 paths (those without a namespace prefix), only relative and drive absolute paths were supported. After this commit, all of the following are supported:

- Device namespaced paths (`\\.\`)
- Verbatim paths (`\\?\`)
- NT-namespaced paths (`\??\`)
- Relative paths (`foo`)
- Drive-absolute paths (`C:\foo`)
- Drive-relative paths (`C:foo`)
- Rooted paths (`\foo`)
- UNC absolute paths (`\\server\share\foo`)
- Root local device paths (`\\.` or `\\?` exactly)

Plus:

- Any of the path types and namespace types can be mixed and matched together as appropriate.
- All of the `std.os.windows.*ToPrefixedFileW` functions will accept any path type, prefixed or not, and do the appropriate thing to convert them to an NT-prefixed path if necessary.

This is achieved by making the `std.os.windows.*ToPrefixedFileW` functions behave like `ntdll.RtlDosPathNameToNtPathName_U`, but with a few differences:

- Does not allocate on the heap (this is why we can't use `ntdll.RtlDosPathNameToNtPathName_U` directly, it does internal heap allocation).
- Relative paths are kept as relative unless they contain too many .. components, in which case they are treated as 'drive relative' and resolved against the CWD (this is how it behaved before this commit as well).
- Special case device names like COM1, NUL, etc are not handled specially (TODO)
- `.` and space are not stripped from the end of relative paths (potential TODO)

Most of the non-trivial conversion of non-relative paths is done via `ntdll.RtlGetFullPathName_U`, which AFAIK is used internally by `ntdll.RtlDosPathNameToNtPathName_U`.

Some relevant reading on Windows paths:

- https://googleprojectzero.blogspot.com/2016/02/the-definitive-guide-on-win32-to-nt.html
- https://chrisdenton.github.io/omnipath/Overview.html

Closes #8205
Might close (untested) #12729

Note:
- This removes checking for illegal characters in `std.os.windows.sliceToPrefixedFileW`, since the previous solution (iterate the whole string and error if any illegal characters were found) was naive and won't work for all path types. This is further complicated by things like file streams (where `:` is used as a delimiter, e.g. `file.ext:stream_name:$DATA`) and things in the device namespace (where a path like `\\.\GLOBALROOT\??\UNC\localhost\C$\foo` is valid despite the `?`s in the path and is effectively equivalent to `C:\foo`). Truly validating paths is complicated and would need to be tailored to each path type. The illegal character checking being removed may open up users to more instances of hitting `OBJECT_NAME_INVALID => unreachable` when using `fs` APIs.
  + This is related to https://github.com/ziglang/zig/issues/15607
2023-05-29 13:08:51 +03:00
Mizuochi Keita
ec58b475b7 std.math.big.int: Fix typo
- `bytes` -> `buffer`
- Correct naming consistency between
  1. fn argument and doc comment of `(read|write)PackedTwosComplement`
  2. fn arguments of `(read|write)PackedTwosComplement` and `(read|write)TwosComplement`
2023-05-29 13:04:55 +03:00
Mizuochi Keita
4422af8be9 std.math.big.int: Add Sqrt
Implemented with reference to Modern Computer Arithmetic, Algorithm 1.13.
https://members.loria.fr/PZimmermann/mca/pub226.html

The below optimization ideas are derived from Go's big package.

* Minimize initial loop value
* Reuse loop values

math/big/int.go: https://cs.opensource.google/go/go/+/refs/tags/go1.20.4:src/math/big/int.go;l=1286
2023-05-29 13:04:32 +03:00
Cortex
6e6a61a384
std.io.Writer: add support for non-power-of-two int sizes 2023-05-29 13:01:54 +03:00
Evin Yulo
235b776d61 fix #15778: Binary operations on empty vectors crash 2023-05-29 13:01:11 +03:00
Frank Denis
ab37ab33ce
poly1305: properly cast the mask from u1 to u64 (#15869)
Fixes #15855
2023-05-27 08:50:57 +00:00
Veikka Tuominen
ca16f1e8a7 std.Target adjustments
* move `ptrBitWidth` from Arch to Target since it needs to know about the abi
* double isn't always 8 bits
* AVR uses 1-byte alignment for everything in GCC
2023-05-26 21:42:19 -07:00
Andrew Kelley
dbd44658ff wasm backend: emit a TODO error rather than miscompile 2023-05-26 21:10:54 -07:00
Veikka Tuominen
8f5f8090c5
Merge pull request #15803 from linusg/std-snek-case-enums
std: Snake-case some public facing enums
2023-05-27 02:40:38 +03:00
David CARLIER
41502c6aa5
std.Thread: refining stack size from platform minimum, changes more targetted towards platform like Linux/musl (#15791) 2023-05-25 14:32:17 -05:00
Linus Groh
ba35eeb417 std.fs.file: Rename File.Lock enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
4159add4ab std.fs.file: Rename File.Kind enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
e96de1b636 std.event.loop: Rename Loop.Request.Finish enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
1f57043a21 std.event.loop: Rename Loop.ResumeNode.Id enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
9123377cdb std.fmt: Rename parseWithSign() sign parameter enum values to snake case 2023-05-25 20:17:07 +01:00
Linus Groh
7860cd734c std.fmt: Rename Alignment enum values to snake case 2023-05-25 20:17:07 +01:00
Veikka Tuominen
230ea411f7 disable test on C backend
This test was previously incorrect and was not testing the intended instruction.
2023-05-25 18:49:18 +03:00
Veikka Tuominen
4a3539e449 llvm: fix vector type in vector_store_elem
Closes #15848
2023-05-25 15:57:30 +03:00
DraagrenKirneh
34865d6938
Improve Content-Disposition filename detection (#15844) 2023-05-24 22:30:58 -07:00
Mason Remaley
5744ceedb8
Fixes WriteFile.getFileSource failure on Windows (#15730) 2023-05-24 14:26:07 -07:00
Loris Cro
c9dffc842e
Merge pull request #15810 from der-teufel-programming/autodoc-quickfixes
autodoc: Links to private decls now lead to source files
2023-05-24 18:32:00 +02:00
Veikka Tuominen
7cb2e653a2
Merge pull request #15806 from linusg/std-io-tty
std: Move TTY from std.debug to std.io and add missing colors
2023-05-24 16:03:44 +03:00
Veikka Tuominen
b2a514b3d2 Sema: @memcpy convert src slice to many ptr
Closes #15838
2023-05-24 14:29:15 +03:00
Linus Groh
93d9c9bf31 std.io.tty: Remove unused Config.writeDEC() function
For reference:
https://github.com/ziglang/zig/pull/15806#discussion_r1203377118
2023-05-24 10:15:47 +01:00
Linus Groh
5d3f3cae64 std.io.tty: Add missing colors to Color enum
Also make colors not bold by default, that's what .bold is for.
2023-05-24 10:15:02 +01:00