aboutsummaryrefslogtreecommitdiff
path: root/test/stage2/llvm.zig
AgeCommit message (Collapse)Author
2022-04-28test: migrate llvm incremental testsJakub Konka
2022-03-17stage2 test harness: ask for the backend explicitlyAndrew Kelley
Follow-up to 35d6ee08c468642969b594b711dd6448bbaefa89
2022-03-12stage2: add compiler test to ensure typed null doesn't coerce to anyMitchell Hashimoto
In stage1, this behavior was allowed (by accident?) and also accidentally exercised by the behavior test changed in this commit. In discussion on Discord, Andrew decided this should not be allowed in stage2 since there is currently on real world reason to allow this strange edge case. I've added the compiler test to solidify that this behavior should NOT occur and updated the behavior test to the new valid semantics.
2021-09-20Address Spaces: LLVM F segment address space testRobin Voetter
2021-09-20Address Spaces: Split out stage2 address llvm tests to individual casesRobin Voetter
This previously caused a test case to crash due to lingering llvm state.
2021-09-20Address Spaces: Chaining testsRobin Voetter
2021-09-20Address Spaces: Move stage 2 tests to stage2/llvm.zigRobin Voetter
2021-08-30stage2: add `@rem` tests to llvm and c backendsMeghan Denny
2021-08-20stage2: field type expressions support referencing localsAndrew Kelley
The big change in this commit is making `semaDecl` resolve the fields if the Decl ends up being a struct or union. It needs to do this while the `Sema` is still in scope, because it will have the resolved AIR instructions that the field type expressions possibly reference. We do this after the decl is populated and set to `complete` so that a `Decl` may reference itself. Everything else is fixes and improvements to make the test suite pass again after making this change. * New AIR instruction: `ptr_elem_ptr` - Implemented for LLVM backend * New Type tag: `type_info` which represents `std.builtin.TypeInfo`. It is used by AstGen for the operand type of `@Type`. * ZIR instruction `set_float_mode` uses `coerced_ty` to avoid superfluous `as` instruction on operand. * ZIR instruction `Type` uses `coerced_ty` to properly handle result location type of operand. * Fix two instances of `enum_nonexhaustive` Value Tag not handled properly - it should generally be handled the same as `enum_full`. * Fix struct and union field resolution not copying Type and Value objects into its Decl arena. * Fix enum tag value resolution discarding the ZIR=>AIR instruction map for the child Sema, when they still needed to be accessed. * Fix `zirResolveInferredAlloc` use-after-free in the AIR instructions data array. * Fix `elemPtrArray` not respecting const/mutable attribute of pointer in the result type. * Fix LLVM backend crashing when `updateDeclExports` is called before `updateDecl`/`updateFunc` (which is, according to the API, perfectly legal for the frontend to do). * Fix LLVM backend handling element pointer of pointer-to-array. It needed another index in the GEP otherwise LLVM saw the wrong type. * Fix LLVM test cases not returning 0 from main, causing test failures. Fixes a regression introduced in 6a5094872f10acc629543cc7f10533b438d0283a. * Implement comptime shift-right. * Implement `@Type` for integers and `@TypeInfo` for integers. * Implement union initialization syntax. * Implement `zirFieldType` for unions. * Implement `elemPtrArray` for a runtime-known operand. * Make `zirLog2IntType` support RHS of shift being `comptime_int`. In this case it returns `comptime_int`. The motivating test case for this commit was originally: ```zig test "example" { var l: List(10) = undefined; l.array[1] = 1; } fn List(comptime L: usize) type { var T = u8; return struct { array: [L]T, }; } ``` However I changed it to: ```zig test "example" { var l: List = undefined; l.array[1] = 1; } const List = blk: { const T = [10]u8; break :blk struct { array: T, }; }; ``` Which ended up being a similar, smaller problem. The former test case will require a similar solution in the implementation of comptime function calls - checking if the result of the function call is a struct or union, and using the child `Sema` before it is destroyed to resolve the fields.
2021-08-19stage2: implement shlJacob G-W
This is implemented in the llvm and cbe backends. x86_64 will take a bit more time.
2021-08-19stage2: implement shr and boilerplate for shlJacob G-W
This implements it in the llvm and c backends. x86_64 will have to be a little more work.
2021-05-12stage2: fix test cases to add `pub` on exported _start fnAndrew Kelley
This way the start code respects them.
2021-03-02stage2: improve orelse implementationAndrew Kelley
* Now it supports being an lvalue (see additional lines in the test case). * Properly handles a pointer result location (see additional lines in the test case that assign the result of the orelse to a variable rather than a const). * Properly sets the result location type when possible, so that type inference of an `orelse` operand expression knows its result type.
2021-03-02stage2: add a test for `for` loops in LLVM backendTimon Kruiper
2021-03-02stage2: add support for optionals in the LLVM backendTimon Kruiper
We can now codegen optionals! This includes the following instructions: - is_null - is_null_ptr - is_non_null - is_non_null_ptr - optional_payload - optional_payload_ptr - br_void Also includes a test for optionals.
2021-01-19astgen: eliminate rlWrapPtr and all its callsitesAndrew Kelley
The following AST avoids unnecessary derefs now: * error set decl * field access * array access * for loops: replace ensure_indexable and deref on the len_ptr with a special purpose ZIR instruction called indexable_ptr_len. Added an error note when for loop operand is the wrong type. I also accidentally implemented `@field`.
2021-01-10stage2: add support for loops in LLVM backendTimon Kruiper
A simple `while(true) {}` loop generates the following LLVMIR: ``` define i32 @main() { Entry: br label %Loop Loop: ; preds = %Loop, %Entry br label %Loop } ``` Also implement TZIR printing for loops and add a corresponding test.
2021-01-08stage2: add initial impl of control flow in LLVM backendTimon Kruiper
The following TZIR instrutions have been implemented in the backend: - all cmp operators (lt, lte, gt, gte, eq, neq) - block - br - condbr The following LLVMIR is generated for a simple assert function: ``` define void @assert(i1 %0) { Entry: %1 = alloca i1, align 1 store i1 %0, i1* %1, align 1 %2 = load i1, i1* %1, align 1 %3 = xor i1 %2, true br i1 %3, label %Then, label %Else Then: ; preds = %Entry call void @llvm.debugtrap() unreachable Else: ; preds = %Entry br label %Block Block: ; preds = %Else ret void } ``` See tests for more examples.
2021-01-06stage2: rename and move files related to LLVM backendTimon Kruiper