aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/optional.zig
AgeCommit message (Collapse)Author
2022-08-25LLVM: fix missing alignment on wrapping instructionsAndrew Kelley
Previously, when lowering AIR instructions `wrap_errunion_payload`, `wrap_errunion_err`, and `wrap_optional`, the LLVM backend would create an alloca instruction to store the result, but did not set the alignment on it. This caused UB which went undetected for a long time until we started enabling the stack protector. Closes #12594 Unblocks #12508 Inspires #12634 Tests passed locally: * test-behavior * test-cases
2022-08-22Sema: make orelse with C pointers behave like stage1 for nowVeikka Tuominen
Closes #12537
2022-08-17Sema: make optional noreturn behave correctlyVeikka Tuominen
2022-05-27stage2 AArch64: complete genTypedValuejoachimschmidt557
2022-04-15stage2 llvm: fix optional pointers to zero bit payloadsVeikka Tuominen
2022-03-25stage2 AArch64: lower cmp to binOpjoachimschmidt557
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-22stage2 ARM: implement comparison of optional pointersjoachimschmidt557
2022-03-18stage2 ARM: implement slice_elem_ptr, ptr_elem_ptrjoachimschmidt557
2022-03-16stage2 ARM: genSetStack for stack_argument_offsetjoachimschmidt557
2022-03-03stage2 llvm: Lower 0-bit field-ptr as ptr-to-voidCody Tapscott
2022-03-02x64: rectify and add missing optionals bitsJakub Konka
Includes changes/additions to: * `wrap_optional` * `optional_payload` * `isNull` helper
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-02-28x64: pass more behavior testsJakub Konka
2022-02-24Sema: implement tupleFieldVal, fix comptime elem_ptrAndrew Kelley
2022-02-21Sema: fix comptime union initializationAndrew Kelley
The mechanism behind initializing a union's tag is a bit complicated, depending on whether the union is initialized at runtime, forced comptime, or implicit comptime. `coerce_result_ptr` now does not force a block to be a runtime context; instead of adding runtime instructions directly, it forwards analysis to the respective functions for initializing optionals and error unions. `validateUnionInit` now has logic to still emit a runtime `set_union_tag` instruction even if the union pointer is comptime-known, for the case of a pointer that is not comptime mutable, such as a variable or the result of `@intToPtr`. `validateStructInit` looks for a completely different pattern now; it now handles the possibility of the corresponding AIR instruction for the `field_ptr` to be missing or the corresponding `store` to be missing. See the new comment added to the function for more details. An equivalent change should probably be made to `validateArrayInit`. `analyzeOptionalPayloadPtr` and `analyzeErrUnionPayloadPtr` functions now emit a `optional_payload_ptr_set` or `errunion_payload_ptr_set` instruction respectively if `initializing` is true and the pointer value is not comptime-mutable. `storePtr2` now tries the comptime pointer store before checking if the element type has one possible value because the comptime pointer store can have side effects of setting a union tag, setting an optional payload non-null, or setting an error union to be non-error. The LLVM backend `lowerParentPtr` function is improved to take into account the differences in how the LLVM values are lowered depending on the Zig type. It now handles unions correctly as well as additionally handling optionals and error unions. In the LLVM backend, the instructions `optional_payload_ptr_set` and `errunion_payload_ptr_set` check liveness analysis and only do the side effects in the case the result of the instruction is unused. A few wasm and C backend test cases regressed, but they are due to TODOs in lowering of constants, so this is progress.
2022-02-21stage2 AArch64: implement genSetReg for ptr_stack_offsetjoachimschmidt557
2022-02-14stage2 AArch64: Enable behavior testingjoachimschmidt557
2022-02-09Sema: implement comptime ptr store to optional payloadAndrew Kelley
and error union payload
2021-11-26Sema: fix analyzeBlockBody logicAndrew Kelley
Previously, when a coercion needed to be inserted into a break instruction, the `br` AIR instruction would be rewritten so that the block operand was a sub-block that did the coercion. The problem is that the sub-block itself was never added to the parent block, resulting in the `br` instruction operand being a bad reference. Now, the `br` AIR instruction that needs to have coercion instructions added is replaced with the sub-block itself with type `noreturn`, and then the sub-block has the coercion instructions and a new `br` instruction that breaks from the original block. LLVM backend needed to be fixed to lower `noreturn` blocks without emitting an unused LLVM basic block.
2021-11-24stage2: fix unwrap function call with optional pointer return valueAndrew Kelley
2021-11-23C backend: errors and optionalsScibuild
* bitcast treats all pointers as pointers * correctly unwrapping error unions with pointers * equality operators for primitive optional types
2021-11-16stage2: equality compare optional with non-optionalAndrew Kelley
2021-11-09Sema: implement coerce_result_ptr for optionalsAndrew Kelley
New AIR instruction: `optional_payload_ptr_set` It's like `optional_payload_ptr` except it sets the non-null bit. When storing to the payload via a result location that is an optional, `optional_payload_ptr_set` is now emitted. There is a new algorithm in `zirCoerceResultPtr` which stores a dummy value through the result pointer into a temporary block, and then pops off the AIR instructions from the temporary block in order to determine how to transform the result location pointer in case any in-between coercions need to happen. Fixes a couple of behavior tests regarding optionals.
2021-10-15stage2: optional comparison and 0-bit payloadsAndrew Kelley
* Sema: implement peer type resolution for optionals and null. * Rename `Module.optionalType` to `Type.optional`. * LLVM backend: re-use anonymous values. This is especially useful when isByRef()=true because it means re-using the same generated LLVM globals. * LLVM backend: rework the implementation of is_null and is_non_null AIR instructions. Generate slightly better LLVM code, and also fix the behavior for optionals whose payload type is 0-bit. * LLVM backend: improve `cmp` AIR instruction lowering to support pointer-like optionals. * `Value`: implement support for equality-checking optionals.
2021-10-15stage2: make hasCodeGenBits() always true for pointersAndrew Kelley
* LLVM backend: The `alloc` AIR instruction as well as pointer constants which point to a 0-bit element type now call a common codepath to produce a `*const llvm.Value` which is a non-zero pointer with a bogus-but-properly-aligned address. * LLVM backend: improve the lowering of optional types. * Type: `hasCodeGenBits()` now returns `true` for pointers even when it returns `false` for their element types. Effectively, #6706 is now implemented in stage2 but not stage1.
2021-10-14stage2: LLVM backend: implement `wrap_optional` AIRAndrew Kelley
and move over some passing tests
2021-10-13move behavior tests that are passing for stage2Andrew Kelley
2021-06-21fix code broken from previous commitJacob G-W
2021-06-21std, src, doc, test: remove unused variablesJacob G-W
2021-05-08Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
Conflicts: * doc/langref.html.in * lib/std/enums.zig * lib/std/fmt.zig * lib/std/hash/auto_hash.zig * lib/std/math.zig * lib/std/mem.zig * lib/std/meta.zig * test/behavior/alignof.zig * test/behavior/bitcast.zig * test/behavior/bugs/1421.zig * test/behavior/cast.zig * test/behavior/ptrcast.zig * test/behavior/type_info.zig * test/behavior/vector.zig Master branch added `try` to a bunch of testing function calls, and some lines also had changed how to refer to the native architecture and other `@import("builtin")` stuff.
2021-04-29move behavior tests from test/stage1/ to test/Andrew Kelley
And fix test cases to make them pass. This is in preparation for starting to pass behavior tests with self-hosted.