diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-10-11 11:00:32 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-11 11:39:12 -0700 |
| commit | 6d6cf598475ab8d2c3259002655ba04f1d056b2e (patch) | |
| tree | daf38d2c3c68de0411d9106668bde92cc7e0651b /test/behavior/array.zig | |
| parent | f42725c39bbbe5db13c1a1706db3f31aa0549307 (diff) | |
| download | zig-6d6cf598475ab8d2c3259002655ba04f1d056b2e.tar.gz zig-6d6cf598475ab8d2c3259002655ba04f1d056b2e.zip | |
stage2: support nested structs and arrays and sret
* Add AIR instructions: ret_ptr, ret_load
- This allows Sema to be blissfully unaware of the backend's decision
to implement by-val/by-ref semantics for struct/union/array types.
Backends can lower these simply as alloc, load, ret instructions,
or they can take advantage of them to use a result pointer.
* Add AIR instruction: array_elem_val
- Allows for better codegen for `Sema.elemVal`.
* Implement calculation of ABI alignment and ABI size for unions.
* Before appending the following AIR instructions to a block,
resolveTypeLayout is called on the type:
- call - return type
- ret - return type
- store_ptr - elem type
* Sema: fix memory leak in `zirArrayInit` and other cleanups to this
function.
* x86_64: implement the full x86_64 C ABI according to the spec
* Type: implement `intInfo` for error sets.
* Type: implement `intTagType` for tagged unions.
The Zig type tag `Fn` is now used exclusively for function bodies.
Function pointers are modeled as `*const T` where `T` is a `Fn` type.
* The `call` AIR instruction now allows a function pointer operand as
well as a function operand.
* Sema now has a coercion from function body to function pointer.
* Function type syntax, e.g. `fn()void`, now returns zig tag type of
Pointer with child Fn, rather than Fn directly.
- I think this should probably be reverted. Will discuss the lang
specs before doing this. Idea being that function pointers would
need to be specified as `*const fn()void` rather than `fn() void`.
LLVM backend:
* Enable calling the panic handler (previously this just
emitted `@breakpoint()` since the backend could not handle the panic
function).
* Implement sret
* Introduce `isByRef` and implement it for structs and arrays. Types
that are `isByRef` are now passed as pointers to functions, and e.g.
`elem_val` will return a pointer instead of doing a load.
* Move the function type creating code from `resolveLlvmFunction` to
`llvmType` where it belongs; now there is only 1 instance of this
logic instead of two.
* Add the `nonnull` attribute to non-optional pointer parameters.
* Fix `resolveGlobalDecl` not using fully-qualified names and not using
the `decl_map`.
* Implement `genTypedValue` for pointer-like optionals.
* Fix memory leak when lowering `block` instruction and OOM occurs.
* Implement volatile checks where relevant.
Diffstat (limited to 'test/behavior/array.zig')
| -rw-r--r-- | test/behavior/array.zig | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig index 5338421a27..c59a7e813a 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -50,3 +50,29 @@ test "array literal with inferred length" { try expect(hex_mult.len == 4); try expect(hex_mult[1] == 256); } + +test "array dot len const expr" { + try expect(comptime x: { + break :x some_array.len == 4; + }); +} + +const ArrayDotLenConstExpr = struct { + y: [some_array.len]u8, +}; +const some_array = [_]u8{ 0, 1, 2, 3 }; + +test "array literal with specified size" { + var array = [2]u8{ 1, 2 }; + try expect(array[0] == 1); + try expect(array[1] == 2); +} + +test "array len field" { + var arr = [4]u8{ 0, 0, 0, 0 }; + var ptr = &arr; + try expect(arr.len == 4); + comptime try expect(arr.len == 4); + try expect(ptr.len == 4); + comptime try expect(ptr.len == 4); +} |
