aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/align.zig
AgeCommit message (Collapse)Author
2022-08-18improved ABI alignment/size for >= 128-bit integersAndrew Kelley
* riscv64: adjust alignment and size of 128-bit integers. * take ofmt=c into account for ABI alignment of 128-bit integers and structs. * Type: make packed struct support intInfo * fix f80 alignment for i386-windows-msvc
2022-08-18stage2: agree with LLVM that `@alignOf(u128)` is 8Andrew Kelley
on x86_64 and similar targets.
2022-07-23Sema: don't add union field access safety check for single field unionsVeikka Tuominen
2022-07-21Sema: validate extern struct field types earlierVeikka Tuominen
`validateExternType` does not require the type to be resolved so we can check it earlier. Only doing it in `resolveTypeFully` lead to worse or missing compile errors.
2022-07-21Sema: validate function pointer alignmentVeikka Tuominen
2022-06-25stage2 ARM: implement basic intCast and error union wrappingjoachimschmidt557
2022-06-06behaviortest: Skip 'align(N) on functions' on sparc64 for nowKoakuma
2022-06-01Sema: fix compiler crash with comptime arithmetic involving `@ptrToInt`Andrew Kelley
2022-06-01Sema: fix alignment of element ptr result typeAndrew Kelley
2022-05-30Sema: implement functions generic across callconv() or align()Andrew Kelley
2022-05-27stage2 AArch64: complete genTypedValuejoachimschmidt557
2022-05-26fix alignment behavior test caseAndrew Kelley
As demonstrated by this new test case, stage1's functionality is incorrect since it does not handle slicing from len..len correctly. stage2 already has the correct behavior here.
2022-05-25mark some more behavior tests as passingAndrew Kelley
2022-05-17stage2: fix pointer arithmetic result typeAndrew Kelley
This makes it so the result of doing pointer arithmetic creates a new pointer type that has adjusted alignment.
2022-05-18wasm: enable 128bit integer behavior testsLuuk de Gram
2022-05-13target: Rename sparcv9 -> sparc64Koakuma
Rename all references of sparcv9 to sparc64, to make Zig align more with other projects. Also, added new function to convert glibc arch name to Zig arch name, since it refers to the architecture as sparcv9. This is based on the suggestion by @kubkon in PR 11847. (https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-05-07arm: lock dest register in shl_overflow so that we do not spill itJakub Konka
Nerf two tests - they will require further investigation, but arm now passes all tests with the safety PR.
2022-05-07regalloc: ensure we only freeze/unfreeze at the outermost scopeJakub Konka
This prevents a nasty type of bugs where we accidentally unfreeze a register that was frozen purposely in the outer scope, risking accidental realloc of a taken register. Fix CF flags spilling on aarch64 backend.
2022-05-04stage2: change max int align from 8 to 16 for more ISAsAndrew Kelley
These targets now have a similar disagreement with LLVM about the alignment of 128-bit integers as x86_64: * riscv64 * powerpc64 * powerpc64le * mips64 * mips64el * sparcv9 See #2987
2022-05-04stage2: fix `@sizeOf` for structs with comptime fieldsAndrew Kelley
2022-05-04stage2: change x86_64 max int alignment from 8 to 16Andrew Kelley
For x86_64, LLVMABIAlignmentOfType(i128) reports 8. However I think 16 is a better number for two reasons: 1. Better machine code when loading into SIMD register. 2. The C ABI wants 16 for extern structs.
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-03-19stage2: Correctly align decls for comptime allocsCody Tapscott
This updates WipAnonDecl to require an alignment provided by the caller, which is needed for explicitly aligned comptime allocs.
2022-03-18stage2 ARM: implement slice_elem_ptr, ptr_elem_ptrjoachimschmidt557
2022-03-13stage2 AArch64: enable mul for ints with <= 64 bitsjoachimschmidt557
2022-03-13stage2: add debug info for locals in the LLVM backendAndrew Kelley
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-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-09wasm: Enable passing behavior testsLuuk de Gram
This also adds some float-related instructions to MIR/Emit
2022-03-08stage2 ARM: implement ptr_add, ptr_sub for all element sizesjoachimschmidt557
Also reduces slice_elem_val to ptr_add, simplifying the implementation
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 ARM: generate less no-op branchesjoachimschmidt557
The checks detecting such no-op branches (essentially instructions that branch to the instruction immediately following the branch) were tightened to catch more of these occurrences.
2022-03-01Merge pull request #11016 from ziglang/x64-more-codegenJakub Konka
2022-02-28Sema: fix pointer type hash and equality functionsAndrew Kelley
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-28x64: pass more behavior testsJakub Konka
2022-02-27stage2 ARM: enable more behavior testsjoachimschmidt557
2022-02-25macho: redo selection of segment/section for decls and constsJakub Konka
* fix alignment issues for consts with natural ABI alignment not matching that of the `ldr` instruction in `aarch64` - solved by preceeding the `ldr` with an additional `add` instruction to form the full address before dereferencing the pointer. * redo selection of segment/section for decls and consts based on combined type and value
2022-02-23stage2 AArch64: more support for MCValue.got_load and direct_loadjoachimschmidt557
2022-02-22Port more behavior testsJakub Konka
2022-02-21stage2 AArch64: pass a few more behavior testsjoachimschmidt557
2022-02-21stage2 AArch64: implement genSetReg for ptr_stack_offsetjoachimschmidt557
2022-02-17x64: fix ptr_add and ptr_subJakub Konka
Add standalone implementation of operand reuse for ptr related arithmetic operations of add and sub.
2022-02-16x64: fix ptr_addJakub Konka
However, still missing is taking into account pointer alignment when performing arithmetic.
2022-02-14stage2 AArch64: Enable behavior testingjoachimschmidt557
2022-02-08stage2 ARM: support all integer types in genTypedValuejoachimschmidt557
2022-02-07stage2: lower unnamed constants in Elf and MachOJakub Konka
* link: add a virtual function `lowerUnnamedConsts`, similar to `updateFunc` or `updateDecl` which needs to be implemented by the linker backend in order to be used with the `CodeGen` code * elf: implement `lowerUnnamedConsts` specialization where we lower unnamed constants to `.rodata` section. We keep track of the atoms encompassing the lowered unnamed consts in a global table indexed by parent `Decl`. When the `Decl` is updated or destroyed, we clear the unnamed consts referenced within the `Decl`. * macho: implement `lowerUnnamedConsts` specialization where we lower unnamed constants to `__TEXT,__const` section. We keep track of the atoms encompassing the lowered unnamed consts in a global table indexed by parent `Decl`. When the `Decl` is updated or destroyed, we clear the unnamed consts referenced within the `Decl`. * x64: change `MCValue.linker_sym_index` into two `MCValue`s: `.got_load` and `.direct_load`. The former signifies to the emitter that it should emit a GOT load relocation, while the latter that it should emit a direct load (`SIGNED`) relocation. * x64: lower `struct` instantiations
2022-02-06stage2 ARM: enable a handful of passing behavior testsjoachimschmidt557
2022-01-26organize behavior testsAndrew Kelley
Every test that is moved in this commit has been checked to see if it is now passing.
2022-01-24behavior tests: prevent disabled tests from lowering std.TargetAndrew Kelley