aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/struct.zig
AgeCommit message (Collapse)Author
2022-09-20Sema: check pointer qualifiers before implicit castVeikka Tuominen
Closes #12881
2022-09-14stage2: sparc64: Skip compile-failing tests for nowKoakuma
2022-09-09stage2 ARM: implement struct_field_val for registersjoachimschmidt557
2022-09-09stage2 ARM: amend implementation of various AIR instructionsjoachimschmidt557
- 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-08-22Sema: fix parameter of type 'T' must be comptime errorVeikka Tuominen
Closes #12519 Closes #12505
2022-08-07remove 'builtin.stage2_arch', Sema is smart enough nowMeghan Denny
2022-08-01Sema: validate packed struct field typesVeikka Tuominen
2022-07-23Sema: bad union field access safetyVeikka Tuominen
2022-07-21LLVM: fix lowering of structs with underaligned fieldsAndrew Kelley
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-13stage2: lower each struct field type, align, init separatelyAndrew Kelley
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-06-06Sema: validate equality on store to comptime fieldVeikka Tuominen
2022-05-27stage2 AArch64: complete genTypedValuejoachimschmidt557
2022-05-25stage2: packed struct fields do not have a byte offsetVeikka Tuominen
2022-05-18wasm: enable 128bit integer behavior testsLuuk de Gram
2022-05-04stage2: fix `@sizeOf` for structs with comptime fieldsAndrew Kelley
2022-05-04stage2: improve `@sizeOf` and `@alignOf` integersAndrew Kelley
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-02behavior tests: fix wrong packed struct test caseAndrew Kelley
Packed structs are defined to have the same alignment and size as their backing integer.
2022-04-28CBE: fix renderValue() for struct fields with no runtime bitsDaniele Cocca
These shouldn't count towards the total emitted, or the stray comma separators would cause compilation errors.
2022-04-22Merge pull request #11279 from igor84/s1_packed_structAndrew Kelley
stage1: Fix packed structs (#2627, #10104)
2022-03-27stage1: disable failing testAndrew Kelley
The new behavior test introduced in the previous commit is not passing for stage1 on mips.
2022-03-27LLVM: handle aggregate_init for packed structsAndrew Kelley
2022-03-26stage1: Fix packed structs (#2627, #10104)Igor Stojkovic
Fixed formatting in packed-struct-zig Skipped packed_structs tests in stage2 simplified packed struct tests
2022-03-24pass more behaviour testsJakub Konka
2022-03-23wasm: Enable all passing testsLuuk de Gram
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-19AstGen: always add dbg_block_end before last instructionVeikka Tuominen
2022-03-18stage2 ARM: implement slice_elem_ptr, ptr_elem_ptrjoachimschmidt557
2022-03-17Sema: change how undefined is handled in coerceAndrew Kelley
Instead of doing it before the switch tower, do it afterwards, so that special handling may be done before undefined gets casted to the destination type. In this case the special handling we want to do is *[N]T to []T setting the slice length based on the array length, even when the array value is undefined.
2022-03-16stage2 ARM: genSetStack for stack_argument_offsetjoachimschmidt557
2022-03-16LLVM: make the load function copy isByRef=true typesAndrew Kelley
2022-03-15Sema: only do store_ptr tuple optimization for arraysAndrew Kelley
Check the big comment in the diff for more details. Fixes default-initialization of structs from empty struct literals.
2022-03-13stage2 AArch64: enable mul for ints with <= 64 bitsjoachimschmidt557
2022-03-09Sema: implement pointer to tuple to pointer to array coercionAndrew Kelley
This involved an LLVM backend fix for the aggregate_init instruction.
2022-03-09Sema: implement pointer-to-tuple coercion to slice and structAndrew Kelley
2022-03-08Sema: implement coercion of tuples to structsAndrew Kelley
2022-03-08Sema: implement comptime struct fieldsAndrew Kelley
2022-03-08stage2 ARM: implement ret_loadjoachimschmidt557
2022-03-06Merge pull request #11070 from Luukdegram/wasm-unifyJakub Konka
stage2: wasm - unify codegen with other backends
2022-03-06stage2: Fix wasm linker for llvm backendLuuk de Gram
This fixes 2 entrypoints within the self-hosted wasm linker that would be called for the llvm backend, whereas we should simply call into the llvm backend to perform such action. i.e. not allocate a decl index when we have an llvm object, and when flushing a module, we should be calling it on llvm's object, rather than have the wasm linker perform the operation. Also, this fixes the wasm intrinsics for wasm.memory.size and wasm.memory.grow. Lastly, this commit ensures that when an extern function is being resolved, we tell LLVM how to import such function.
2022-03-06wasm: call into `generateSymbol` when loweringLuuk de Gram
This also unifies the wasm backend to use `generateSymbol` when lowering a constant that cannot be lowered to an immediate value. As both decls and constants are now refactored, the old `genTypedValue` is removed.
2022-03-05stage2 AArch64: add more slice supportjoachimschmidt557
* airSlice * airArrayToSlice * and initial support for airSlicePtr and co
2022-03-04stage2: fix tuple assigned to variableAndrew Kelley
Before this we would see ZIR code like this: ``` %69 = alloc_inferred_mut() %70 = array_base_ptr(%69) %71 = elem_ptr_imm(%70, 0) ``` This would crash the compiler because it expects to see a `coerce_result_ptr` instruction after `alloc_inferred_mut`, but that does not happen in this case because there is no type to coerce the result pointer to. In this commit I modified AstGen so that it has similar codegen as when using a const instead of a var: ``` %69 = alloc_inferred_mut() %76 = array_init_anon(.{%71, %73, %75}) %77 = store_to_inferred_ptr(%69, %76) ``` This does not obey result locations, meaning if you call a function inside the initializer, it will end up doing a copy into the LHS. Solving this problem, or changing the language to make this legal, will be left for my future self to deal with. Hi future self! I see you reading this commit log. Hope you're doing OK buddy. Sema for `store_ptr` of a tuple where the pointer is in fact the same element type as the operand had an issue where the comptime fields would get incorrectly lowered to runtime stores to bogus addresses. This is solved with an exception to the optimization in Sema for storing pointers that handles tuples element-wise. In the case that we are storing a tuple to itself, it skips the optimization. This results in better code and avoids the problem. However this caused a regression in GeneralPurposeAllocator from the standard library. I regressed the test runner code back to the simpler path. It's too hard to debug standard library code in the LLVM backend right now since we don't have debug info hooked up. Also, we didn't have any behavior test coverage of whatever was regressed, so let's try to get that coverage added as a stepping stone to getting the standard library working.
2022-03-02Sema: detect comptime-known union initializationsAndrew Kelley
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-02Merge pull request #11026 from ziglang/codegen-field-ptrJakub Konka
codegen: lower field_ptr to memory across linking backends
2022-03-01stage2: introduce anonymous struct literalsAndrew Kelley
2022-03-01LLVM: add extra padding to structs and tuples sometimesAndrew Kelley
* Sema: resolve type fully when emitting an alloc AIR instruction to avoid tripping assertion for checking struct field alignment. * LLVM backend: keep a reference to the LLVM target data alive during lowering so that we can ask LLVM what it thinks the ABI alignment and size of LLVM types are. We need this in order to lower tuples and structs so that we can put in extra padding bytes when Zig disagrees with LLVM about the size or alignment of something. * LLVM backend: make the LLVM struct type packed that contains the most aligned union field and the padding. This prevents the struct from being too big according to LLVM. In the future, we may want to consider instead emitting unions in a "flat" manner; putting the tag, most aligned union field, and padding all in the same struct field space. * LLVM backend: make structs with 2 or fewer fields return isByRef=false. This results in more efficient codegen. This required lowering of bitcast to sometimes store the struct into an alloca, ptrcast, and then load because LLVM does not allow bitcasting structs. * enable more passing behavior tests.
2022-03-01LLVM: fix tripping assertionsAndrew Kelley
Packed structs were tripping an LLVM assertion due to calling `LLVMConstZExt` from i16 to i16. Solved by using instead `LLVMConstZExtOrBitCast`. Unions were tripping an LLVM assertion due to a typo using the union llvm type to construct an integer value rather than the tag type.
2022-03-01LLVM: fix when sret and isByRef ret_ty disagreeAndrew Kelley
This can happen functions use the C ABI.
2022-03-01codegen: ensure we descend on nested field_ptrs when loweringJakub Konka
2022-03-01x64: impl airMemset using inline memsetJakub Konka
2022-03-01stage2 ARM: implement return types with abi size > 4joachimschmidt557