116 Commits

Author SHA1 Message Date
Jacob Young
81318e8704 llvm: add asserts and behavior tests for #14063
Closes #14063
2022-12-27 00:12:56 -05:00
Jacob Young
64865679cf Sema: add missing resolveLazyValue cases
Closes #14032
2022-12-26 04:39:32 -05:00
Jacob Young
f5b6019646 Sema: fix missing struct layout for llvm backend
Closes #14063
2022-12-25 20:18:15 -05:00
Jacob Young
0e3feebb04 codegen: fix taking the address of a zero-bit field in a zero-bit struct
Normally when we want a pointer to the end of a struct we just add 1 to
the struct pointer.  However, when it is a zero-bit struct, the pointer
type being used during lowering is often a dummy pointer type that
actually points to a non-zero-bit type, so we actually want to add 0
instead, since a zero-bit struct begins and ends at the same address.
2022-12-18 22:11:26 -05:00
Jacob Young
e96f65db77 llvm: fix lowering pointer to final zero-width field of a comptime value
* Handle a `null` return from `llvmFieldIndex`.
 * Add a behavior test to test this code path.
 * Reword this test name, which incorrectly described how pointers to
   zero-bit fields behave, and instead describe the actual test.
2022-12-18 22:11:26 -05:00
Andrew Kelley
6ed0910d6d Revert "llvm: fix lowering pointer to final zero-width field of a comptime value"
This reverts commit e0bc5f65b98d154b4318027d56f780b55605e33c.

Caused an assertion failure when running the behavior tests:

```
zig: llvm/lib/IR/Type.cpp:729: static llvm::PointerType* llvm::PointerType::get(llvm::Type*, unsigned int): Assertion `isValidElementType(EltTy) && "Invalid type for pointer element!"' failed.
Aborted (core dumped)
```
2022-12-18 13:51:15 -07:00
Jacob Young
e0bc5f65b9 llvm: fix lowering pointer to final zero-width field of a comptime value
* Handle a `null` return from `llvmFieldIndex`.
 * Add a behavior test to test this code path.
 * Reword this test name, which incorrectly described how pointers to
   zero-bit fields behave, and instead describe the actual test.
2022-12-18 02:17:11 -05: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
Jacob Young
ec3116f573 cbe: fix zero-bit struct field pointer 2022-12-03 08:40:08 -05:00
Andrew Kelley
610d604f5b
Merge pull request #13748 from jacobly0/c-unaligned
cbe: use memcpy for underaligned loads and stores
2022-12-03 02:18:07 -05:00
Jacob Young
fdedd62365 cbe: use memcpy for underaligned loads and stores 2022-12-02 22:21:24 -05:00
Veikka Tuominen
7f9e841f74 Sema: do not forcibly canonicalize unresolved pointer element type
Closes #13308
2022-12-03 00:09:23 +02:00
Luuk de Gram
090deae41d
wasm: enable behavior tests for packed structs 2022-11-30 21:01:09 +01:00
Veikka Tuominen
d2cc55109a llvm: correct calculation of index of zero-bit field
If the field comes before any non-zero-bit field then the index of
the next field should be returned.

Closes #13363
2022-11-11 17:59:53 +02:00
Ali Chraghi
f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
Jacob Young
ab468d57e3 cbe: implement packed structs
Sometimes you have to break a test to make progress :)
2022-10-25 05:11:29 -04:00
Jacob Young
4765294ca4 cbe: get enough things working to support basic programs
* Enable advanced start support.
 * Enable advanced test_runner support.
 * Zig Language Reference's Hello World now works.
2022-10-25 05:11:29 -04:00
Jacob Young
912b84bbad cbe: fix atomics 2022-10-25 05:11:29 -04:00
Jacob Young
87d432328e cbe: implement aggregate_init of struct 2022-10-25 05:11:29 -04:00
Jacob Young
5eafc10bf4 cbe: fix global access fix 2022-10-25 05:11:29 -04:00
Jacob Young
a12535f501 cbe: fix global access 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
r00ster91
51d9db8569 fix(text): hyphenate "comptime" adjectives 2022-10-05 21:19:30 +02:00
Veikka Tuominen
541b3e3a31 Sema: check pointer qualifiers before implicit cast
Closes #12881
2022-09-20 00:50:13 +03:00
Koakuma
0910cb6fcb stage2: sparc64: Skip compile-failing tests for now 2022-09-14 16:58:12 -07:00
joachimschmidt557
3794f2c493
stage2 ARM: implement struct_field_val for registers 2022-09-09 19:17:18 +02:00
joachimschmidt557
261fec8036
stage2 ARM: amend implementation of various AIR instructions
- unwrap_errunion_err for registers
- unwrap_errunion_payload for registers
- ptr_slice_len_ptr for all MCValues
- ptr_slice_ptr_ptr for all MCValues
2022-09-09 19:17:17 +02:00
Veikka Tuominen
b55a5007fa Sema: fix parameter of type 'T' must be comptime error
Closes #12519
Closes #12505
2022-08-22 11:16:36 +03:00
Meghan Denny
0879cbeed2 remove 'builtin.stage2_arch', Sema is smart enough now 2022-08-07 16:07:08 -07:00
Veikka Tuominen
e47706f344 Sema: validate packed struct field types 2022-08-01 23:59:40 +03:00
Veikka Tuominen
ff7ec4efb5 Sema: bad union field access safety 2022-07-23 15:40:11 +03:00
Andrew Kelley
f550c29c4e LLVM: fix lowering of structs with underaligned fields
When lowering a struct type to an LLVM struct type, keep track of
whether there are any underaligned fields. If so, then make it a packed
llvm struct. This works because we already insert manual padding bytes
regardless.

We could unconditionally use an LLVM packed struct; the reason we bother
checking for underaligned fields is that it is a conservative choice, in
case LLVM handles packed structs less optimally. A future improvement
could simplify this code by unconditionally using packed LLVM structs
and then make sure measure perf is unaffected.

closes #12190
2022-07-21 22:51:17 -07:00
Andrew Kelley
4a28c1d5c3 stage2: lower each struct field type, align, init separately
Previously, struct types, alignment values, and initialization
expressions were all lowered into the same ZIR body, which caused false
positive "depends on itself" errors when the initialization expression
depended on the size of the struct.

This also uses ResultLoc.coerced_ty for struct field alignment and
initialization values. The resulting ZIR encoding ends up being roughly
the same, neither smaller nor larger than previously.

Closes #12029
2022-07-13 02:38:13 -04:00
Veikka Tuominen
cb5d2b691a Sema: validate equality on store to comptime field 2022-06-06 13:11:50 -07:00
joachimschmidt557
ddd5b57045 stage2 AArch64: complete genTypedValue 2022-05-27 16:43:11 -04:00
Veikka Tuominen
d214b6bdf0 stage2: packed struct fields do not have a byte offset 2022-05-25 19:57:38 +03:00
Luuk de Gram
e252f92b99 wasm: enable 128bit integer behavior tests 2022-05-18 07:43:33 +02:00
Andrew Kelley
af7e945a7d stage2: fix @sizeOf for structs with comptime fields 2022-05-04 18:45:59 -07:00
Andrew Kelley
259f784241 stage2: improve @sizeOf and @alignOf integers
Prior to this commit, the logic for ABI size and ABI alignment for
integers was naive and incorrect. This results in wasted hardware as
well as undefined behavior in the LLVM backend when we memset an
incorrect number of bytes to 0xaa due to disagreeing with LLVM about the
ABI size of integers.

This commit introduces a "max int align" value which is different per
Target. This value is used to derive the ABI size and alignment of all
integers.

This commit makes an interesting change from stage1, which treats
128-bit integers as 16-bytes aligned for x86_64-linux. stage1 is
incorrect. The maximum integer alignment on this system is only 8 bytes.
This change breaks the behavior test called "128-bit cmpxchg" because on
that target, 128-bit cmpxchg does require a 16-bytes aligned pointer to
a 128 bit integer. However, this alignment property does not belong on
*all* 128 bit integers - only on the pointer type in the `@cmpxchg`
builtin function prototype. The user can then use an alignment override
annotation on a 128-bit integer variable or struct field to obtain such
a pointer.
2022-05-04 17:34:16 -07:00
Andrew Kelley
d98869da43 behavior tests: fix wrong packed struct test case
Packed structs are defined to have the same alignment and size as their
backing integer.
2022-05-02 22:06:02 -07:00
Daniele Cocca
fda143d5d8 CBE: fix renderValue() for struct fields with no runtime bits
These shouldn't count towards the total emitted, or the stray comma
separators would cause compilation errors.
2022-04-28 23:41:42 -04:00
Andrew Kelley
cf20b97b71
Merge pull request #11279 from igor84/s1_packed_struct
stage1: Fix packed structs (#2627, #10104)
2022-04-22 11:39:12 -04:00
Andrew Kelley
c8f8440271 stage1: disable failing test
The new behavior test introduced in the previous commit is not passing
for stage1 on mips.
2022-03-27 14:40:24 -07:00
Andrew Kelley
6d2ec7a4e3 LLVM: handle aggregate_init for packed structs 2022-03-27 14:22:47 -07:00
Igor Stojkovic
109e730c8c stage1: Fix packed structs (#2627, #10104)
Fixed formatting in packed-struct-zig

Skipped packed_structs tests in stage2

simplified packed struct tests
2022-03-26 09:03:37 +01:00
Jakub Konka
4ef26fc355 pass more behaviour tests 2022-03-24 17:04:50 +01:00
Luuk de Gram
5cb16dfa59
wasm: Enable all passing tests
All tests have been manually verified which are now passing. This means that any remaining
TODO is an actual to-be-fixed or to-be-implemented test case.
2022-03-23 21:40:33 +01:00
Veikka Tuominen
1e1f740347 AstGen: always add dbg_block_end before last instruction 2022-03-19 11:20:38 +02:00