Commit Graph

84 Commits

Author SHA1 Message Date
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
joachimschmidt557
d6e6162081
stage2 AArch64: unify callee-preserved regs on all targets
also enables many passing behavior tests
2022-12-27 21:17:52 +08:00
r00ster91
aac2d6b56f std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
Veikka Tuominen
e6588857df Sema: fix memory management of union enum tag int tag
This likely went unnoticed due to all power of two integer types being special cased.

Closes #13812
2022-12-14 14:08:21 +02:00
Koakuma
f9e9ba784f stage2: sparc64: Skip unimplemented tests 2022-12-10 21:51:46 +07:00
Andrew Kelley
c8aba15c22 remove references to stage1 in behavior tests
Good riddance.
2022-12-06 19:06:48 -07:00
Veikka Tuominen
2dcac348e5 cbe: implement packed unions 2022-11-30 15:14:33 +02:00
Veikka Tuominen
71937f75d8 Sema: correctly detect union target in zirSwitchBlock
Closes #13655
2022-11-26 18:05:27 +02:00
Veikka Tuominen
28cbe5e92a Sema+llvm: improve handling of namespace-like unions
Closes #13557
2022-11-16 01:13:35 +02:00
Veikka Tuominen
61842da9f7 llvm: implement packed unions
Closes #13340
2022-11-09 17:14:38 +02:00
Jacob Young
912b84bbad cbe: fix atomics 2022-10-25 05:11:29 -04:00
Jacob Young
962f33ee11 cbe: implement airUnionInit 2022-10-25 05:11:28 -04:00
Jacob Young
6a4266d62a cbe: fix infinite recursion on recursive types 2022-10-25 05:11:28 -04:00
Jacob Young
525dcaecba behavior: enable stage2_c tests that are currently passing
Also fix C warnings triggered by these tests.
2022-10-25 05:11:28 -04:00
joachimschmidt557
b976997e16
stage2 ARM: implement ptr_elem_val 2022-09-09 19:17:18 +02:00
Veikka Tuominen
f281f3d10e Sema: improve behavior of comptime_int backed enums 2022-09-02 17:57:11 +03:00
Veikka Tuominen
7a8d9af4a9 stage2 llvm: correct handling of zero-bit types in unionFieldPtr
Pointers to zero-bit types are not zero-bit types so the function should
return something.
Closes #12716
2022-09-02 17:57:10 +03:00
Veikka Tuominen
c558de6655 stage2 llvm: use tag value instead of field index in airUnionInit
Closes #12656
2022-08-30 12:22:07 -07:00
antlilja
ae8d26a6a0 Sema: add error for non-comptime param in comptime func
Adds error for taking a non comptime parameter in a function returning a
comptime-only type but not when that type is dependent on a parameter.

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-08-27 11:17:48 +03:00
Andrew Kelley
7453f56e67 stage2: explicitly tagged enums no longer have one possible value
Previously, Zig had inconsistent semantics for an enum like this:

`enum(u8){zero = 0}`

Although in theory this can only hold one possible value, the tag
`zero`, Zig no longer will treat the type this way. It will do loads and
stores, as if the type has runtime bits.

Closes #12619

Tests passed locally:
 * test-behavior
 * test-cases
2022-08-24 22:20:31 -07:00
Veikka Tuominen
d48af541c7 Sema: handle union and enum field order being different
Closes #12543
2022-08-21 12:51:40 +03:00
Veikka Tuominen
c3d5428cba Sema: properly handle noreturn fields in unions 2022-08-17 22:07:48 +03:00
Andrew Kelley
3ba7098a17 LLVM: fix returning extern union with C callconv 2022-07-27 17:56:15 -07:00
Veikka Tuominen
ff7ec4efb5 Sema: bad union field access safety 2022-07-23 15:40:11 +03:00
Veikka Tuominen
62120e3d0e Sema: fix non-exhaustive union switch checks 2022-07-21 12:21:30 -07:00
Veikka Tuominen
122c76a167 Sema: allow void as an extern union field & fix invalid extern unions 2022-07-11 20:30:16 +03:00
Andrew Kelley
c248af3bdc LLVM: fix lowering of untagged union types
The LLVM backend was calculating the amount of padding solely based
on the payload size. However, in the case where there is no union
tag, this fails to take into account alignment.

Closes #11857
2022-06-30 02:43:05 -04:00
joachimschmidt557
960c142060 stage2 ARM: implement basic intCast and error union wrapping 2022-06-25 21:16:51 +02:00
Veikka Tuominen
0a9d6956e7 Sema: add missing set_union_tag 2022-06-12 19:17:41 +03:00
joachimschmidt557
ddd5b57045 stage2 AArch64: complete genTypedValue 2022-05-27 16:43:11 -04:00
Jakub Konka
6d32498c55 x64: re-enable behavior tests 2022-05-19 19:39:34 +02:00
Andrew Kelley
99657dca1f Sema: fix comptime equality of extern unions with same tag 2022-04-12 11:36:26 -07:00
Veikka Tuominen
3c4ac47e00 stage2 llvm: fix union init of byRef values 2022-03-28 13:04:50 -07:00
Veikka Tuominen
17d214a249 Sema: implement zirStructInit for runtime-known union values 2022-03-25 22:32:15 +02:00
Cody Tapscott
a9a91a5d49 stage2 CBE: Improve support for unions and error sets
This includes various fixes/improvements to the C backend to improve
error/union support. It also fixes up our handling of decls, where some
decls were not correctly marked alive.
2022-03-23 16:29:38 -04:00
Luuk de Gram
2fc91a09a2
wasm: Enable passing tests
This enables the tests that now pass due to the changes to lower
parent pointers are lowered, as well as the additional features to unions.
2022-03-19 20:56:04 +01:00
Andrew Kelley
9a6fa67cbc Sema: only do store_ptr tuple optimization for arrays
Check the big comment in the diff for more details.
Fixes default-initialization of structs from empty struct literals.
2022-03-15 19:21:58 -07:00
Andrew Kelley
0bc9635490 stage2: add debug info for locals in the LLVM backend
Adds 2 new AIR instructions:
 * dbg_var_ptr
 * dbg_var_val

Sema no longer emits dbg_stmt AIR instructions when strip=true.

LLVM backend: fixed lowerPtrToVoid when calling ptrAlignment on
the element type is problematic.

LLVM backend: fixed alloca instructions improperly getting debug
location annotated, causing chaotic debug info behavior.

zig_llvm.cpp: fixed incorrect bindings for a function that should use
unsigned integers for line and column.

A bunch of C test cases regressed because the new dbg_var AIR
instructions caused their operands to be alive, exposing latent bugs.
Mostly it's just a problem that the C backend lowers mutable
and const slices to the same C type, so we need to represent that in the
C backend instead of printing two duplicate typedefs.
2022-03-13 03:41:31 -04:00
Luuk de Gram
90f08a69aa wasm: Enable passing behavior tests
This also adds some float-related instructions to MIR/Emit
2022-03-09 13:53:20 -07:00
Andrew Kelley
38c161afab Sema: fix @hasDecl for simple enums 2022-03-07 13:54:25 -07:00
Andrew Kelley
c467f6693e stage2: fix union layout returning non-zero for zero-sized tag 2022-03-07 13:36:58 -07:00
Andrew Kelley
06b1a88a15 Sema: implement cast from anon struct ptr to union ptr 2022-03-02 20:18:22 -07:00
Andrew Kelley
f5e2e301e9 Sema: add coercion from anon structs to unions 2022-03-02 19:22:31 -07:00
Andrew Kelley
1c8a86f063 Sema: detect comptime-known union initializations
Follow a similar pattern as we already do for validate_array_init and
validate_struct_init.

I threw in a bit of behavior test cleanup on top of it.
2022-03-02 17:28:39 -07:00
Jakub Konka
ec54ceee6d
Merge pull request #11016 from ziglang/x64-more-codegen 2022-03-01 09:14:23 +01:00
Andrew Kelley
157f66ec07 Sema: fix pointer type hash and equality functions
Several issues with pointer types are fixed:

Prior to this commit, Zig would not canonicalize a pointer type with
an explicit alignment to alignment=0 if it matched the pointee ABI
alignment. In order to fix this, `Type.ptr` now takes a Target
parameter. I also moved the host_size canonicalization to `Type.ptr`
since target is now available. Similarly, is_allowzero in the case of
C pointers is now treated as a canonicalization done by the function
rather than a precondition.

in-memory coercion for pointers now properly checks ABI alignment
of pointee types instead of incorrectly treating the 0 value as an
alignment.

Type equality is completely reworked based on the tag() rather than the
zigTypeTag(). It's still semantically based on zigTypeTag() but that
knowledge is implied rather than dictating the control flow of the
logic. Importantly, this fixes cases for opaques, structs, tuples,
enums, and unions, where type equality was incorrectly returning based
on whether the tag() values were equal.

Additionally, pointer type equality now takes into account alignment.
Because we canonicalize non-zero alignment which equals pointee type ABI
alignment to alignment=0, this now can be a simple integer comparison.

Type hashing is implemented for pointers and floats. Array types now
additionally hash their sentinels.

This regressed some behavior tests that were passing but only because
of bugs regarding type equality.

The C backend has a noticeable problem with lowering differently-aligned
pointers (particularly slices) as the same type, causing C compilation
errors due to duplicate declarations.
2022-02-28 19:22:16 -07:00
Jakub Konka
66d28d0f20 x64: implement get_union_tag for register 2022-02-28 23:20:05 +01:00
Jakub Konka
decc90e0e7 x64: clean up loadMemPtrIntoRegister abstraction 2022-02-28 23:20:05 +01:00
Jakub Konka
331cc810de
Merge pull request #11012 from ziglang/x64-union-tag
stage2,x64: basic (un)tagged unions
2022-02-28 17:42:59 +01:00