77 Commits

Author SHA1 Message Date
David Rubin
c457f35da5
riscv: arbitrary sized arrays 2024-06-13 02:19:40 -07:00
Robin Voetter
b9d738a5cf
spirv: disable tests that fail on pocl
Besides the Intel OpenCL CPU runtime, we can now run the
behavior tests using the Portable Computing Language. This
implementation is open-source, so it will be easier for us
to patch in updated versions of spirv-llvm-translator that
have bug fixes etc.
2024-06-10 20:32:34 +02:00
Veikka Tuominen
f776e70c39 llvm: fix lowering of packed structs with optional pointers
Closes #20022
2024-05-21 19:52:25 +03:00
David Rubin
ffb63a05a3 riscv: finally fix bug + airAggregateInit
i just hadn't realized that I placed the `riscv_start` branch in the non-simplified
starts
2024-05-11 02:17:24 -07:00
David Rubin
a30af172e8 riscv: math progress 2024-05-11 02:17:24 -07:00
David Rubin
d9e0cafe64 riscv: add stage2_riscv to test matrix and bypass failing tests 2024-05-11 02:17:24 -07:00
mlugg
d0e74ffe52
compiler: rework comptime pointer representation and access
We've got a big one here! This commit reworks how we represent pointers
in the InternPool, and rewrites the logic for loading and storing from
them at comptime.

Firstly, the pointer representation. Previously, pointers were
represented in a highly structured manner: pointers to fields, array
elements, etc, were explicitly represented. This works well for simple
cases, but is quite difficult to handle in the cases of unusual
reinterpretations, pointer casts, offsets, etc. Therefore, pointers are
now represented in a more "flat" manner. For types without well-defined
layouts -- such as comptime-only types, automatic-layout aggregates, and
so on -- we still use this "hierarchical" structure. However, for types
with well-defined layouts, we use a byte offset associated with the
pointer. This allows the comptime pointer access logic to deal with
reinterpreted pointers far more gracefully, because the "base address"
of a pointer -- for instance a `field` -- is a single value which
pointer accesses cannot exceed since the parent has undefined layout.
This strategy is also more useful to most backends -- see the updated
logic in `codegen.zig` and `codegen/llvm.zig`. For backends which do
prefer a chain of field and elements accesses for lowering pointer
values, such as SPIR-V, there is a helpful function in `Value` which
creates a strategy to derive a pointer value using ideally only field
and element accesses. This is actually more correct than the previous
logic, since it correctly handles pointer casts which, after the dust
has settled, end up referring exactly to an aggregate field or array
element.

In terms of the pointer access code, it has been rewritten from the
ground up. The old logic had become rather a mess of special cases being
added whenever bugs were hit, and was still riddled with bugs. The new
logic was written to handle the "difficult" cases correctly, the most
notable of which is restructuring of a comptime-only array (for
instance, converting a `[3][2]comptime_int` to a `[2][3]comptime_int`.
Currently, the logic for loading and storing work somewhat differently,
but a future change will likely improve the loading logic to bring it
more in line with the store strategy. As far as I can tell, the rewrite
has fixed all bugs exposed by #19414.

As a part of this, the comptime bitcast logic has also been rewritten.
Previously, bitcasts simply worked by serializing the entire value into
an in-memory buffer, then deserializing it. This strategy has two key
weaknesses: pointers, and undefined values. Representations of these
values at comptime cannot be easily serialized/deserialized whilst
preserving data, which means many bitcasts would become runtime-known if
pointers were involved, or would turn `undefined` values into `0xAA`.
The new logic works by "flattening" the datastructure to be cast into a
sequence of bit-packed atomic values, and then "unflattening" it; using
serialization when necessary, but with special handling for `undefined`
values and for pointers which align in virtual memory. The resulting
code is definitely slower -- more on this later -- but it is correct.

The pointer access and bitcast logic required some helper functions and
types which are not generally useful elsewhere, so I opted to split them
into separate files `Sema/comptime_ptr_access.zig` and
`Sema/bitcast.zig`, with simple re-exports in `Sema.zig` for their small
public APIs.

Whilst working on this branch, I caught various unrelated bugs with
transitive Sema errors, and with the handling of `undefined` values.
These bugs have been fixed, and corresponding behavior test added.

In terms of performance, I do anticipate that this commit will regress
performance somewhat, because the new pointer access and bitcast logic
is necessarily more complex. I have not yet taken performance
measurements, but will do shortly, and post the results in this PR. If
the performance regression is severe, I will do work to to optimize the
new logic before merge.

Resolves: #19452
Resolves: #19460
2024-04-17 13:41:25 +01:00
Jacob Young
f1c0f42cdd cbe: fix optional codegen
Also reduce ctype pool string memory usage, remove self assignments, and
enable more warnings.
2024-04-13 01:35:20 -04:00
Jacob Young
5a62f26579 x86_64: fix packed load 2024-02-12 05:25:07 +01:00
Andrew Kelley
616f74ba20 add behavior test for recently fixed wasm backend bug
Adds the corresponding behavior test for the fix in
320c4d68f5f40794ae31d5535de9c3a8ff5cb471.
2024-02-11 14:14:59 -07:00
Jakub Konka
52066bf8e4 x86_64+macho: pass more behavior tests 2024-02-06 19:01:17 +01:00
SuperAuguste
a479fd3132 Fix some comptime packed struct issues
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2024-01-29 13:09:17 -08:00
Veikka Tuominen
804cee3b93 categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
Carl Ã…stholm
d7b36503ca Remove some @as coercions from assertions
These are some spurious fixes to help illustrate the improved ergonomics of the `expectEqual` change. It is by no means complete.
2024-01-03 21:20:48 +01:00
Carl Ã…stholm
4c1da0912a Fix compile errors from the expectEqual change 2024-01-03 21:20:48 +01:00
Jacob Young
c70c333594 x86_64: fix packed struct field reuse 2023-12-04 13:31:54 -05:00
Jacob Young
bf5ab54510 test: test with -fstrip and fix failures
Closes #17513
2023-12-01 04:34:50 +00:00
mlugg
9c16b2370d
test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
Jacob Young
0ea7189c23 behavior: enable test passing with x86_64 backend 2023-11-05 11:54:29 -05:00
Andrew Kelley
3fc6fc6812 std.builtin.Endian: make the tags lower case
Let's take this breaking change opportunity to fix the style of this
enum.
2023-10-31 21:37:35 -04:00
Jacob Young
27fe945a00 Revert "Revert "Merge pull request #17637 from jacobly0/x86_64-test-std""
This reverts commit 6f0198cadbe29294f2bf3153a27beebd64377566.
2023-10-22 15:46:43 -04:00
Andrew Kelley
6f0198cadb Revert "Merge pull request #17637 from jacobly0/x86_64-test-std"
This reverts commit 0c99ba1eab63865592bb084feb271cd4e4b0357e, reversing
changes made to 5f92b070bf284f1493b1b5d433dd3adde2f46727.

This caused a CI failure when it landed in master branch due to a
128-bit `@byteSwap` in std.mem.
2023-10-22 12:16:35 -07:00
Jacob Young
2e6e39a700 x86_64: fix bugs and disable erroring tests 2023-10-21 10:55:41 -04:00
Robin Voetter
faad97edff
spirv: update failing / passing tests
Some tests are now failing due to debug info changes, some tests
now pass due to improved compiler functionality.
2023-10-15 20:08:18 +02:00
Xavier Bouchoux
703fe0f121 test: add a pair of cases from bug reports 2023-10-08 11:37:49 +02:00
Xavier Bouchoux
370662c565 codegen/llvm: truncate padding bits when loading a non-byte-sized value 2023-10-08 11:37:49 +02:00
Jacob Young
644d943861 x86_64: implement 128-bit integer comparisons 2023-10-04 16:26:56 -04:00
Xavier Bouchoux
405705cb76 codegen: fix byte-aligned field offsets in unaligned nested packed structs 2023-10-03 05:34:19 +00:00
Xavier Bouchoux
62d178e91a codegen: fix field offsets in packed structs
* add nested packed struct/union behavior tests
 * use ptr_info.packed_offset rather than trying to duplicate the logic from Sema.structFieldPtrByIndex()
 * use the container_ptr_info.packed_offset to account for non-aligned nested structs.
 * dedup type.packedStructFieldBitOffset() and module.structPackedFieldBitOffset()
2023-10-03 06:39:20 +02:00
Xavier Bouchoux
8c367ef99a codegen: fix access to byte-aligned nested packed struct elems
When acessing a packed struct member via a byte aligned ptr (from the optimisation in Sema.structFieldPtrByIndex())
the codegen must apply the parent ptr packed_offset in addition to the field offset itself.

resolves https://github.com/ziglang/zig/issues/16609
2023-07-29 18:16:13 +02:00
Xavier Bouchoux
46abf20454 llvm: partial fix of store undefined to packed result location
prefer marking too few undefined bits, rather than too many that may overwrite nearby values.
partially resolves https://github.com/ziglang/zig/issues/15337
2023-07-29 11:56:27 +02:00
Andrew Kelley
9d3363fee9 add behavior test for bitcast packed struct twice
closes #9914
2023-07-26 19:02:02 -07:00
Jacob Young
5b74278510 x86_64: fix global pointers to packed struct fields 2023-06-25 19:14:03 -04:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
Eric Joldasov
d884d7050e
all: replace comptime try with try comptime
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-13 23:46:58 +06:00
Robin Voetter
65157d30ab
spirv: ptr_elem_val
Implements the ptr_elem_val air tag. Implementation is unified
with ptr_elem_ptr.
2023-05-20 17:30:23 +02:00
Robin Voetter
37aa343079
spirv: more passing tests 2023-05-20 17:30:22 +02:00
Ali Chraghi
ccc490ef68
setup spirv backend in behavior tests 2023-05-11 20:31:52 +02:00
Koakuma
d339e86fb1 stage2: sparc64: Skip unimplemented tests 2023-04-28 16:45:37 -07:00
Jacob Young
894406b9d3 behavior: update passing cbe tests 2023-04-26 19:05:17 -04:00
Jacob Young
bf6fd9ae3f cbe: enable CI for std tests 2023-04-21 16:36:10 -04:00
Jacob Young
ac68d72d24 x86_64: implement aggregate init of a packed struct 2023-04-02 04:49:53 -04:00
Jacob Young
1e080e5056 x86_64: implement atomic loops 2023-03-25 16:23:55 -04:00
Jacob Young
8f385e77ca x86_64: implement struct_field_val for packed containers 2023-03-25 16:23:55 -04:00
Jacob Young
0cfc0d0d13 x86_64: implement struct_field_ptr for packed containers 2023-03-25 16:23:55 -04:00
Jacob Young
bdb1e014a0 CBE: cleanup field access
* Implement @fieldParentPtr on a union
 * Refactor field access to ensure that it is handled consistently
 * Remove `renderTypecast` as it is now behaves the same as `renderType`
2023-02-23 00:29:23 -05:00
Veikka Tuominen
6e067dc050 llvm: do not offset packed struct field pointers if they have a host size
Closes #14261
2023-01-17 20:28:42 +02:00
Veikka Tuominen
58c1d98c14 add tests for fixed stage1 bugs
Closes #4144
Closes #4255
Closes #4372
Closes #4375
Closes #4380
Closes #4417
Closes #4423
Closes #4476
Closes #4528
Closes #4562
Closes #4572
Closes #4597
Closes #4639
Closes #4672
Closes #4782
Closes #4955
Closes #4984
Closes #4997
Closes #5010
Closes #5114
Closes #5166
Closes #5173
Closes #5276
2022-12-31 20:49:02 -05:00
Veikka Tuominen
9a0c593a54 add tests for fixed stage1 bugs
Closes #1957
Closes #1994
Closes #2140
Closes #2746
Closes #2802
Closes #2855
Closes #2895
Closes #2981
Closes #3054
Closes #3158
Closes #3234
Closes #3259
Closes #3371
Closes #3376
Closes #3387
Closes #3529
Closes #3653
Closes #3750
Closes #3778
Closes #3882
Closes #3915
Closes #3929
Closes #3961
Closes #3988
Closes #4123
Closes #7448
2022-12-29 12:42:44 +02:00