24254 Commits

Author SHA1 Message Date
Luuk de Gram
832330094c
wasm: aggregate_init - ensure zeroed result local
When initializing a packed struct, we must ensure the result local
is zero'd. Previously we would do this by ensuring a new local is
allocated. Although a local is always zero by default, it meant that
if such an initialization was being done inside a loop, it would re-
use that very same local that could potentially still hold a different
value. Because this value is `or`'d with the value, it would result
in a miscompilation. By manually setting this result to 0, we guarantee
the correct behavior.
2023-05-19 20:22:48 +02:00
Luuk de Gram
ca870aa005
wasm: fix div_trunc for floats
For floats we would previously only do the division, but not
the truncation for floats. This would result in incorrect values
being returned.
2023-05-19 20:22:47 +02:00
Luuk de Gram
4a33aa922e
wasm: support memset for elem abi size > 1
Previously we incorrectly assumed all memset's to have its element
abi-size be 1 byte. This would set the region of memory incorrectly.
We now have a more efficient loop, as well as support any element
type by re-using the `store` function for each element and moving
the pointer by 1 element.
2023-05-19 20:22:45 +02:00
Luuk de Gram
55a260c968
wasm: implement shl for big integers 2023-05-19 20:20:29 +02:00
Luuk de Gram
b93fa9833e
wasm: memset - correctly load the ptr for slices
Previously we would use the address of the slice itself, which would
result in miscompilations and accidently setting the memory region
of the slice itself, rather than based on the `ptr` field.
2023-05-19 20:20:29 +02:00
Luuk de Gram
061d99285d
wasm: correctly use elem type when lowering
Previously when lowering a value of `elem_ptr` we would multiply the
abisize of the parent type by the index, rather than the element type.
This would result in an invalid pointer way beyond the correct pointer.

We now also pass the current offset to each recursive call to ensure
we do not miss inner offsets.
2023-05-19 20:20:26 +02:00
Luuk de Gram
6c06944b59
wasm: fix return ret_load with zero-size type
When we have a `ret_load` instruction with a zero-sized type which was
not an error, we would not emit any instruction. This resulted in
no `return` instruction and also not correctly resetting the global
stack_pointer.

This commit also enables the regular test runner for the WebAssembly
backend.
2023-05-19 20:19:00 +02:00
Luuk de Gram
43e89026ac
wasm: fix double free of locals
A copy was being made of a WValue variable, which meant the call
to `free` would insert the local that was being held by said WValue
was appended to the free list twice. This led to the same local being
reused even though it wasn't free and would lead to it being over-
written by a new value.
2023-05-19 20:19:00 +02:00
Luuk de Gram
8be69f4132
wasm: simplify merging of branches
Rather than adding all values that were generated in the child branch,
we simply discard them as outer branches cannot refer to values
produced from an inner branch.
2023-05-19 20:19:00 +02:00
Luuk de Gram
99422cb528
wasm: add dead tag to WValue
This new tag is used for freed locals that are not allowed to have any
remaining references pointing to it. This new tag allows us to easily
identify liveness bugs. Previously we would set the entire region to
`undefined` which would incorrectly set the tag to `function_index`,
making codegen think it was a valid `WValue` while it wasn't.
2023-05-19 20:19:00 +02:00
Luuk de Gram
f2860bb4f4
wasm: more liveness fixes 2023-05-19 20:18:59 +02:00
Luuk de Gram
67d27dbe63
wasm: fix liveness bugs
Make sure to increase the reference count for `intcast` when the
operand doesn't require any casting of the respective WebAssembly type.

Function arguments have a reserved slot, and therefore cannot be
re-used arbitrarily
2023-05-19 20:18:59 +02:00
Luuk de Gram
e20976b7f2
wasm: fix miscompilation for shifting
This fix ensures that when we are shifting left or right,
both operands have the same WebAssembly type. e.g. it's not possible
to shift a 64 bit integer and 32 bit integer together and will fail
WebAssembly's validator. By first coercing the values to the same
type, we ensure we satisfy the validator.
2023-05-19 20:18:59 +02:00
Luuk de Gram
d353d208e2
wasm: implement @mulWithOverflow for big ints
Currently we only support exact 128 bit *unsigned* integers
2023-05-19 20:18:59 +02:00
Luuk de Gram
992de8e617
wasm: implement @addWithOverflow for 64bit ints 2023-05-19 20:18:59 +02:00
Luuk de Gram
8236a26c60
wasm: implement mul, shl and xor for big ints
Uses compiler-rt for multiplication and shifting left, while lowers
it down using regular instructions for xor.
2023-05-19 20:18:59 +02:00
Luuk de Gram
eb77e3381f
wasm: implement @frameAddress 2023-05-19 20:18:58 +02:00
Andrew Kelley
447a302990 Sema: eliminate Type.Tag.var_args_param
This was a special type tag used for hacky stuff in Semantic Analysis.
Move the hacky stuff to use a dedicated `Air.Inst.Ref` instead.

This way, `var_args_param` is not involved in the type system or intern
pool.
2023-05-19 11:05:05 -07:00
Motiejus Jakštys
b61d0debd6 multi-writer: test with a non-comptime stream
Since #14819 this test failed with:

    $ ../../../build/stage3/bin/zig test multi_writer.zig
    multi_writer.zig:26:57: error: unable to evaluate comptime expression
                var batch = std.event.Batch(Error!void, self.streams.len, .auto_async).init();
                                                        ~~~~^~~~~~~~
    referenced by:
        Writer: multi_writer.zig:19:52
        writer: multi_writer.zig:21:36
        remaining reference traces hidden; use '-freference-trace' to see all reference traces

Thanks @jacobly for hints how to fix this on IRC.
2023-05-19 09:13:49 -07:00
Andrew Kelley
b873ce1e0e
Merge pull request #15727 from jacobly0/x86_64-behavior
x86_64: behavior
2023-05-19 00:56:59 -07:00
Andrew Kelley
503302ceef Sema: simplify "duplicate test name" error message
* Avoid redundant words ("found")
   - All compile errors are found by the compiler
 * Avoid unnecessary prepositions ("with")
   - There is a grammatically correct alternate word order without the
     preposition.
2023-05-18 19:17:04 -07:00
Jacob Young
47405b1a1c x86_64: fix @bitCast when the operand dies 2023-05-18 21:02:29 -04:00
Jacob Young
79bdd2bd63 x86_64: implement saturating add/sub for weird types 2023-05-18 20:42:38 -04:00
Jacob Young
60e69fdaa1 codegen: emit global vector padding 2023-05-18 20:42:38 -04:00
Jacob Young
35da95fe87 x86_64: implement integer vector @truncate 2023-05-18 20:42:38 -04:00
Jacob Young
28c445addd x86_64: fix 128-bit atomics on non-linux 2023-05-18 20:42:38 -04:00
Jacob Young
01b63cd081 x86_64: delete some incorrect code 2023-05-18 20:42:38 -04:00
Jacob Young
36ddab03fa x86_64: fix multi-limb compare 2023-05-18 20:42:38 -04:00
Jacob Young
80df8da82f x86_64: initialize array sentinels 2023-05-18 20:42:38 -04:00
Jacob Young
729daed591 x86_64: rewrite casts 2023-05-18 20:42:38 -04:00
Jacob Young
403c2d91be x86_64: fix float min/max behavior 2023-05-18 20:42:38 -04:00
David CARLIER
b9d2e0e308 std.os: add linux timer api 2023-05-19 03:41:10 +03:00
Andrew Kelley
ad391ad399 Revert "Sema: handle recursive inferred errors better in analyzeIsNonErrComptimeOnly"
This reverts commit 5aa9628de3c6637f45b9d8cf8cbd19c422a74f6f.

This is a breaking language change and I do not agree with it. Please go
through the proposal process on this one.
2023-05-18 16:24:07 -07:00
zooster
3d64ed0353
make @trap return unreachable/noreturn (#15749)
`@trap` is a special function that we know never returns so it should
behave just like `@panic` and `@compileError` do currently and cause the
"unreachable code" + "control flow is diverted here" compile error.
Currently, `@trap(); @trap();` does not cause this error. Now it does.
2023-05-18 17:00:35 -04:00
Andrew Kelley
7cf2cbb33e std.crypto.tls.Client.readvAdvanced: fix bugs
* When there is buffered cleartext, return it without calling the
   underlying read function. This prevents buffer overflow due to space
   used up by cleartext.
 * Avoid clearing the buffer when the buffered cleartext could not be
   completely given to the result read buffer, and there is some
   buffered ciphertext left.
 * Instead of rounding up the amount of bytes to ask for to the nearest
   TLS record size, round down, with a minimum of 1. This prevents the
   code path from being taken which requires extra memory copies.
 * Avoid calling `@memcpy` with overlapping arguments.

closes #15590
2023-05-18 03:26:16 -07:00
mlugg
db7496d6ef Only add build.zig module dependencies once 2023-05-18 00:27:21 -07:00
mlugg
f65e8c7862 Deduplicate uses of the same package across dependencies 2023-05-18 00:27:21 -07:00
Andrew Kelley
378264d404
Merge pull request #15750 from ziglang/zig2.c
zig2.c: omit non-essential subcommands
2023-05-17 23:28:35 -07:00
IntegratedQuantum
6e05620117 Document the sorting order in std.sort. 2023-05-17 18:26:49 -07:00
Andrew Kelley
f52189834c rename omit_pkg_fetching_code to only_core_functionality
No functional changes. This renames an internal build option to better
reflect how it is used.
2023-05-17 16:00:24 -07:00
Andrew Kelley
fea6157102 zig2.c: omit non-essential subcommands
When producing zig2.c, don't waste time emitting C code for subcommands
that won't be used, such as objcopy.

This takes zig2.c down from 111M to 109M, and sidesteps some unfortunate
warnings that are currently emitted by GCC.
2023-05-17 15:43:15 -07:00
Andrew Kelley
ad20236e97
Merge pull request #15573 from motiejus/resolv_dn
glibc hacks: also add a few dn_* functions
2023-05-17 10:42:32 -07:00
Andrew Kelley
c1add1e19e
Merge pull request #15459 from motiejus/build-id-full
stage2: implement `--build-id` styles
2023-05-17 07:19:15 -07:00
Andrew Kelley
5b06daf52b zig cc: implement -### (dry run)
closes #7170
2023-05-17 05:18:51 -07:00
Andrew Kelley
fd213accb8
Merge pull request #14462 from motiejus/infile_stdin
zig cc: support reading from stdin via "-x LANG -"
2023-05-17 02:54:51 -07:00
Andrew Kelley
728ce2d7c1 tweaks to --build-id
* build.zig: the result of b.option() can be assigned directly in many
   cases thanks to the return type being an optional
 * std.Build: make the build system aware of the
   std.Build.Step.Compile.BuildId type when used as an option.
   - remove extraneous newlines in error logs
 * simplify caching logic
 * simplify hexstring parsing tests and use a doc test
 * simplify hashing logic. don't use an optional when the `none` tag
   already provides this meaning.
 * CLI: fix incorrect linker arg parsing
2023-05-16 20:39:01 -07:00
Motiejus Jakštys
df5085bde0 stage2: implement --build-id styles 2023-05-16 20:38:39 -07:00
David CARLIER
40e8c2243c std.c: darwin's *copyfile api update. 2023-05-17 06:06:41 +03:00
Frank Denis
c6966486e3
crypto.AegisMac: fix a regression from s/mem.copy/@memcpy/ (#15733)
In an update whose size is not a multiple of the block size,
we would end up calling @memcpy() with arguments of different sizes.
2023-05-16 23:51:47 +00:00
Andrew Kelley
233a0d3991 CLI: remove cleanup logic for stdin temp file
In one of the happy paths, execve() is used to switch to clang in which
case any cleanup logic that exists for this temporary file will not run
and this temp file will be leaked. Oh well. It's a minor punishment for
using `-x c` which nobody should be doing. Therefore, we make no effort
to clean up. Using `-` for stdin as a source file always leaks a temp
file.

Note that the standard `zig build-exe` CLI does not support stdin as an
input file. This is only for `zig cc` C compiler compatibility.
2023-05-16 16:41:22 -07:00