aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
AgeCommit message (Collapse)Author
2023-10-03codegen: fix byte-aligned field offsets in unaligned nested packed structsXavier Bouchoux
2023-10-03codegen: fix field offsets in packed structsXavier Bouchoux
* 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-02union: skip failing tests on ppckcbanner
2023-10-02sema: handle big-endian when bitcasting between different-sized union fieldskcbanner
Updated the tests to also run at runtime, and moved them to union.zig
2023-10-02sema: support reinterpreting extern/packed unions at comptime via field accesskcbanner
My previous change for reading / writing to unions at comptime did not handle union field read/writes correctly in all cases. Previously, if a field was written to a union, it would overwrite the entire value. This is problematic when a field of a larger size is subsequently read, because the value would not be long enough, causing a panic. Additionally, the writing behaviour itself was incorrect. Writing to a field of a packed or extern union should only overwrite the bits corresponding to that field, allowing for memory reintepretation via field writes / reads. I addressed these problems as follows: Add the concept of a "backing type" for extern / packed unions (`Type.unionBackingType`). For extern unions, this is a `u8` array, for packed unions it's an integer matching the `bitSize` of the union. Whenever union memory is read at comptime, it's read as this type. When union memory is written at comptime, the tag may still be known. If so, the memory is written using the tagged type. If the tag is unknown (because this union had previously been read from memory), it's simply written back out as the backing type. I added `write_packed` to the `reinterpret` field of `ComptimePtrMutationKit`. This causes writes of the operand to be packed - which is necessary when writing to a field of a packed union. Without this, writing a value to a `u1` field would overwrite the entire byte it occupied. The final case to address was reading a different (potentially larger) field from a union when it was written with a known tag. To handle this, a new kind of bitcast was introduced (`bitCastUnionFieldVal`) which supports reading a larger field by using a backing buffer that has the unwritten bits set to undefined. The reason to support this (vs always just writing the union as it's backing type), is that no reads to larger fields ever occur at comptime, it would be strictly worse to have spent time writing the full backing type.
2023-10-01x86_64: implement float `@sqrt` builtinJacob Young
2023-10-01x86_64: implement float arithmetic builtinsJacob Young
2023-10-01x86_64: implement float round builtinsJacob Young
2023-10-01x86_64: implement float compare and cast builtinsJacob Young
2023-10-01behavior: cleanup floatop testsJacob Young
2023-10-01x86_64: implement and test unary float builtinsJacob Young
2023-10-01Sema: add `@errorCast` which works for both error sets and error unionsVeikka Tuominen
Closes #17343
2023-09-27Merge pull request #17248 from antlilja/absAndrew Kelley
Replace @fabs builtin with new @abs builtin
2023-09-27Value: fix assertion failure when mutating extern unionVeikka Tuominen
Closes #17292
2023-09-27Add behavior tests for `@abs` builtinantlilja
2023-09-27Replace `@fabs` with `@abs` in behavior testsantlilja
2023-09-26Merge pull request #17215 from kcbanner/read_from_memory_unionVeikka Tuominen
sema: add support for unions in readFromMemory and writeToMemory
2023-09-25type: handle the 0-length array case in abiSizeAdvancedkcbanner
This fixes a panic in `unionAbiSize` when a 0-length array of a union is used as a struct field. Because `resolveTypeLayout` does not resolve the `elem_ty` if `arrayLenIncludingSentinel` returns 0 for the array, the child union type is not guaranteed to have a resolved layout at this point. Fixed this case by just returning 0 here.
2023-09-24behavior: disable newly failing testsmlugg
2023-09-23compiler: preserve result type information through address-of operatormlugg
This commit introduces the new `ref_coerced_ty` result type into AstGen. This represents a expression which we want to treat as an lvalue, and the pointer will be coerced to a given type. This change gives known result types to many expressions, in particular struct and array initializations. This allows certain casts to work which previously required explicitly specifying types via `@as`. It also eliminates our dependence on anonymous struct types for expressions of the form `&.{ ... }` - this paves the way for #16865, and also results in less Sema magic happening for such initializations, also leading to potentially better runtime code. As part of these changes, this commit also implements #17194 by disallowing RLS on explicitly-typed struct and array initializations. Apologies for linking these changes - it seemed rather pointless to try and separate them, since they both make big changes to struct and array initializations in AstGen. The rationale for this change can be found in the proposal - in essence, performing RLS whilst maintaining the semantics of the intermediary type is a very difficult problem to solve. This allowed the problematic `coerce_result_ptr` ZIR instruction to be completely eliminated, which in turn also simplified the logic for inferred allocations in Sema - thanks to this, we almost break even on line count! In doing this, the ZIR instructions surrounding these initializations have been restructured - some have been added and removed, and others renamed for clarity (and their semantics changed slightly). In order to optimize ZIR tag count, the `struct_init_anon_ref` and `array_init_anon_ref` instructions have been removed in favour of using `ref` on a standard anonymous value initialization, since these instructions are now virtually never used. Lastly, it's worth noting that this commit introduces a slightly strange source of generic poison types: in the expression `@as(*anyopaque, &x)`, the sub-expression `x` has a generic poison result type, despite no generic code being involved. This turns out to be a logical choice, because we don't know the result type for `x`, and the generic poison type represents precisely this case, providing the semantics we need. Resolves: #16512 Resolves: #17194
2023-09-23spirv: fix blocks that return no valueRobin Voetter
2023-09-23spirv: enable passing testsRobin Voetter
2023-09-23spirv: constant elem ptrRobin Voetter
2023-09-23spirv: air wrap_errunion_payloadRobin Voetter
2023-09-23spirv: generate module initializerRobin Voetter
2023-09-23spirv: air array_elem_val using hackRobin Voetter
SPIR-V doesn't support true element indexing, so we probably need to switch over to isByRef like in llvm for this to work properly. Currently a temporary is used, which at least seems to work.
2023-09-23spirv: air array_to_sliceRobin Voetter
2023-09-23spirv: air sub_with_overflowRobin Voetter
2023-09-23spirv: air union_initRobin Voetter
2023-09-23spirv: air set_union_tag + improve load()/store()Robin Voetter
2023-09-23spirv: air struct_field_ptr for unionsRobin Voetter
2023-09-23spirv: air struct_field_val for unionsRobin Voetter
2023-09-23spirv: disable failing testsRobin Voetter
2023-09-23sema: rework the comptime representation of comptime unionskcbanner
When the tag is not known, it's set to `.none`. In this case, the value is either an array of bytes (for extern unions) or an integer (for packed unions).
2023-09-23sema: add support for unions in readFromMemory and writeToMemorykcbanner
2023-09-23Sema: refactor detection of comptime-known constsmlugg
This was previously implemented by analyzing the AIR prior to the ZIR `make_ptr_const` instruction. This solution was highly delicate, and in particular broke down whenever there was a second `alloc` between the `store` and `alloc` instructions, which is especially common in destructure statements. Sema now uses a different strategy to detect whether a `const` is comptime-known. When the `alloc` is created, Sema begins tracking all pointers and stores which refer to that allocation in temporary local state. If any store is not comptime-known or has a higher runtime index than the allocation, the allocation is marked as being runtime-known. When we reach the `make_ptr_const` instruction, if the allocation is not marked as runtime-known, it must be comptime-known. Sema will use the set of `store` instructions to re-initialize the value in comptime memory. We optimize for the common case of a single `store` instruction by not creating a comptime alloc in this case, instead directly plucking the result value from the instruction. Resolves: #16083
2023-09-21InternPool,Sema,type,llvm: alignment fixesmlugg
This changeset fixes the handling of alignment in several places. The new rules are: * `@alignOf(T)` where `T` is a runtime zero-bit type is at least 1, maybe greater. * Zero-bit fields in `extern` structs *do* force alignment, potentially offsetting following fields. * Zero-bit fields *do* have addresses within structs which can be observed and are consistent with `@offsetOf`. These are not necessarily all implemented correctly yet (see disabled test), but this commit fixes all regressions compared to master, and makes one new test pass.
2023-09-19langref: disable var args example on aarch64-windowsAndrew Kelley
See tracking issues #14096 and #16961. Also, any time a test is skipped it should link to the open bug report for it.
2023-09-19re-enable passing behavior testAndrew Kelley
See #16797 - it was fixed in the most recent LLVM 17 release candidate.
2023-09-19behavior: disable another test regressed by LLVM 17 for mipsJacob Young
Tracked by #16846
2023-09-19compiler_rt: fix arm hard-float f16 abiJacob Young
Closes #16848
2023-09-19compiler_rt: fix fp sub being optimized to call itselfJacob Young
Closes #16844 Reduces #16846
2023-09-19disable behavior tests regressed by LLVM 17Andrew Kelley
See #16844 See #16845 See #16846 See #16848
2023-09-19behavior: disable test that regressed with LLVM 17Jacob Young
Tracking issue #16797
2023-09-19write function types consistently with a space before `fn` keywordr00ster91
Currently, the compiler (like @typeName) writes it `fn(...) Type` but zig fmt writes it `fn (...) Type` (notice the space after `fn`). This inconsistency is now resolved and function types are consistently written the zig fmt way. Before this there were more `fn (...) Type` occurrences than `fn(...) Type` already.
2023-09-19x86 backend: don't read bogus safety flagAndrew Kelley
Safety is not a global flag that should be enabled or disabled for all stores - it's lowered by the frontend directly into AIR instruction semantics. The flag for this is communicated via the `store` vs `store_safe` AIR instructions, and whether to write 0xaa bytes or not should be decided in `airStore` and passed down via function parameters. This commit is a step backwards since it removes functionality but it aims our feet towards a better mountain to climb.
2023-09-18std.zig.c_translation.zig: fix L suffix with sized intsBanacial
Closes #15066
2023-09-17AstGen: allow closure over known-runtime values within @TypeOfmlugg
AstGen emits an error when a closure over a known-runtime value crosses a namespace boundary. This usually makes sense: however, this usage is actually valid if the capture is within a `@TypeOf` operand. Sema already has a special case to allow such closure within `@TypeOf` when AstGen could not determine a value to be runtime-known. This commit simply introduces analagous logic to AstGen to allow `var`s to cross namespace boundaries within `@TypeOf`.
2023-09-15Sema: mark pointers to inline functions as comptime-onlymlugg
This is supposed to be the case, similar to how pointers to generic functions are comptime-only (several pieces of logic already assumed this). These types being considered runtime was causing `dbg_var_val` AIR instructions to be wrongly emitted for such values, causing codegen backends to create a runtime reference to the inline function, which (at least on the LLVM backend) triggers an error. Resolves: #38
2023-09-15compiler: implement destructuring syntaxmlugg
This change implements the following syntax into the compiler: ```zig const x: u32, var y, foo.bar = .{ 1, 2, 3 }; ``` A destructure expression may only appear within a block (i.e. not at comtainer scope). The LHS consists of a sequence of comma-separated var decls and/or lvalue expressions. The RHS is a normal expression. A new result location type, `destructure`, is used, which contains result pointers for each component of the destructure. This means that when the RHS is a more complicated expression, peer type resolution is not used: each result value is individually destructured and written to the result pointers. RLS is always used for destructure expressions, meaning every `const` on the LHS of such an expression creates a true stack allocation. Aside from anonymous array literals, Sema is capable of destructuring the following types: * Tuples * Arrays * Vectors A destructure may be prefixed with the `comptime` keyword, in which case the entire destructure is evaluated at comptime: this means all `var`s in the LHS are `comptime var`s, every lvalue expression is evaluated at comptime, and the RHS is evaluated at comptime. If every LHS is a `const`, this is not allowed: as with single declarations, the user should instead mark the RHS as `comptime`. There are a few subtleties in the grammar changes here. For one thing, if every LHS is an lvalue expression (rather than a var decl), a destructure is considered an expression. This makes, for instance, `if (cond) x, y = .{ 1, 2 };` valid Zig code. A destructure is allowed in almost every context where a standard assignment expression is permitted. The exception is `switch` prongs, which cannot be destructures as the comma is ambiguous with the end of the prong. A follow-up commit will begin utilizing this syntax in the Zig compiler. Resolves: #498