12417 Commits

Author SHA1 Message Date
Robin Voetter
6e3770e970
spirv: implement pointer comparison in for air cmp
It turns out that the Khronos LLVM SPIRV translator does not support OpPtrEqual.
Therefore, this instruction is emitted using a series of conversions.

This commit breaks intToEnum, because enum was removed from the arithmetic type
info. The enum should be converted to an int before this function is called.
2023-05-20 17:30:21 +02:00
Ali Chraghi
fedc9a19e7 spirv: lower get_union_tag 2023-05-20 18:43:26 +03:30
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
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
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
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
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
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
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
Andrew Kelley
ae119a9a8d CLI: fix stdin dumping behavior
* no need to move `tmpFilePath` around
 * no need for calculating max length of `FileExt` tag name
 * provide a canonical file extension name for `FileExt` so that, e.g.
   the file will be named `stdin.S` instead of
   `stdin.assembly_with_cpp`.
 * move temp file cleanup to a function to reduce defer bloat in a large
   function.
 * fix bug caused by mixing relative and absolute paths in the cleanup
   logic.
 * remove commented out test and dead code
2023-05-16 16:41:22 -07:00
Motiejus Jakštys
2e692312f1 zig cc: support reading from non-files
echo 'some C program' | $CC -x c -

Is a common pattern to test for compiler or linker features. This patch
adds support for reading from non-regular files.

This will make at least one more Go test to pass.
2023-05-16 16:40:58 -07:00
Andrew Kelley
958fba0eb7
Merge pull request #15713 from alichraghi/ali-spirv
spirv: get more behavior tests passing
2023-05-16 16:09:22 -07:00
Michael Dusan
247b353609 netbsd: restrict PT_LOAD workaround to dlibs only
NetBSD supports executables with > 2 PT_LOAD segments but dynamic
libraries continue to expect exactly 2 PT_LOAD segments.
2023-05-16 16:45:10 -04:00
Veikka Tuominen
fdf1675c58 Sema: avoid safety slice safety check with comptime-known start and end
Oopsie
2023-05-16 11:33:38 +03:00
Veikka Tuominen
b91d6ff9e8 add runtime safety for noreturn function returning
Closes #15221
2023-05-16 11:33:38 +03:00