16408 Commits

Author SHA1 Message Date
Jakub Konka
a4e6291fbd
stage2: enable zig test on x86_64-macos (#10551)
* stage2: put decls in different MachO sections

Use `getDeclVAddrWithReloc` when targeting MachO backend rather than
`getDeclVAddr` - this fn returns a zero vaddr and instead creates a
relocation on the linker side which will get automatically updated
whenever the target decl is moved in memory. This fn also records
a rebase of the target pointer so that its value is correctly slid
in presence of ASLR.

This commit enables `zig test` on x86_64-macos.

* stage2: fix output section selection for type,val pairs
2022-01-10 16:02:07 +01:00
Andrew Kelley
42ef95d79d
Merge pull request #10554 from joachimschmidt557/stage2-arm
stage2 ARM: refactor and pass 1 more behavior test file
2022-01-10 01:48:49 -05:00
joachimschmidt557
b5f03b3b7a
stage2 codegen: fix airBlock bug in 3 backends 2022-01-09 19:09:57 +01:00
joachimschmidt557
a1526f069a
stage2 ARM: pass behavior/bool.zig 2022-01-09 19:03:45 +01:00
joachimschmidt557
77ca77cf14
stage2 ARM: make Mir.Inst.cond = .al default 2022-01-09 14:16:29 +01:00
Jakub Konka
d66c97d0ef
Merge pull request #10525 from g-w1/plan9-zig-test
Plan9 zig test
2022-01-09 13:27:56 +01:00
Luuk de Gram
2a39d8063d wasm: Implement arrays 2022-01-08 19:56:07 -05:00
Andrew Kelley
7651913fd2
Merge pull request #10542 from Hejsil/stage2-bit-offset-of
Stage2 bitOffsetOf and offsetOf builtin functions
2022-01-08 15:48:14 -05:00
Robin Voetter
cc5c25d48b stage2: implement @src 2022-01-08 14:32:40 -05:00
Robin Voetter
4931b8dc93 stage2: @errorName sema+llvm 2022-01-08 14:30:11 -05:00
Jimmi Holst Christensen
5cbb35abd0 Implement bitOffsetOf
This also refactors getting struct field offsets into two
iterators. This will be useful when implementing bitCast at comptime on
structs.
2022-01-08 14:01:28 +01:00
Jimmi Holst Christensen
d8d5e2d4b9 Implement offsetOf builtin function 2022-01-08 13:00:49 +01:00
Meghan Denny
3f586781b6 std: fix zig.Ast being called Tree internally 2022-01-08 01:01:09 -05:00
Andrew Kelley
c4ab8d9e12
Merge pull request #10532 from Hejsil/stage2-bit-shifting-passing
Stage2 bit_shifting.zig passing
2022-01-08 01:00:59 -05:00
Lee Cannon
1cdc51ec10 handle error.PathAlreadyExists in renameTmpIntoCache 2022-01-07 16:50:37 -05:00
Jimmi Holst Christensen
3871d5e55a bit_shifting.zig now passes stage2 llvm backend 2022-01-07 22:10:36 +01:00
Jimmi Holst Christensen
f48f687c05 Fix llvmFieldIndex for zero sized fields
It is possible for Zig to emit field ptr instructions to fields whos
type is zero sized. In this case llvm should return a pointer which
points to the next none zero sized parameter.
2022-01-07 22:10:36 +01:00
Jimmi Holst Christensen
f78d3b27ca Increment runtime_param_index for zero sized parameters
`runtime_param_index` is used to get the parameter type from `fn_type`,
but this variable was not incremented for zero sized parameters, causing
two zero sized parameters of different type to cause miss complication.
2022-01-07 22:10:36 +01:00
Jimmi Holst Christensen
9d6bef49a5 Add two more resolution status' to Struct and Union
resolveTypeForCodegen is called when we needed to resolve a type fully,
even through pointer. This commit fully implements this, even through
pointer fields on structs and unions.

The function has now also been renamed to resolveTypeFully
2022-01-07 22:10:36 +01:00
Jimmi Holst Christensen
d5093b6c13 Shift right is a noop if rhs is comptime known to be zero 2022-01-07 22:10:36 +01:00
r00ster
dd076d8cba Add missing package to the langref that's always available 2022-01-07 14:18:47 -05:00
Jimmi Holst Christensen
a68e6cd3d7 Return Value.zero when the result of shr requires zero bits 2022-01-07 19:50:00 +01:00
Meghan
c08b190c69
lint: duplicate import (#10519) 2022-01-07 00:06:06 -05:00
Jacob G-W
398c0b10e4 Plan9: fix amount to say included line count is
Not sure why this was working before...
2022-01-06 22:58:53 -05:00
Jimmi Holst Christensen
7f4fdcc4fc stage2: Implement validating switch on errors 2022-01-06 22:57:45 -05:00
Andrew Kelley
59315463f2 ci: add test coverage for self-hosted arm and x86_64 backends 2022-01-06 22:57:29 -05:00
Jacob G-W
ab400ad624 Plan9: implement getDeclVAddr 2022-01-06 22:47:27 -05:00
Jacob G-W
4d6849ceb8 plan9 debuginfo: fix case where pc change is > 64 * inst quanta 2022-01-06 22:46:55 -05:00
Andrew Kelley
77f230ebd8 C backend is passing test/behavior/undefined.zig
closes #10505
2022-01-06 13:07:38 -07:00
Jakub Konka
0772fb0518
Merge pull request #10518 from ziglang/stage2-x86_64-zig-test-fixes
stage2: fix x86_64 backend to actually correctly run Zig tests!
2022-01-06 15:31:39 +01:00
Jacob G-W
b47530b9fe plan9: fix .z symbol in debuginfo
This allows the `acid` debugger on
plan9 to be used to debug a zig source
file without patching `acid`!

The patch adds a second `z` symbol. This z
symbol has a value of 0, which means that it
pops the history stack. We put a very large
number for the value of the second symbol because
it has to be at least as large as the linecount of
the file. The debuginfo format is meant to be used
with c files, where the stack would look something
like this:
```
->  Line: 0x1 (1)  Name: 0x1/0x2/0x3/0xe/0x13/0x1b (/sys/src/libc/port/malloc.c)
->  Line: 0x2 (2)  Name: 0x1/0x6/0x7/0x8 (/amd64/include/u.h)
->  Line: 0x4f (79)  Name:  ()
->  Line: 0x50 (80)  Name: 0x1/0x2/0x7/0x9 (/sys/include/libc.h)
->  Line: 0x358 (856)  Name:  ()
->  Line: 0x359 (857)  Name: 0x1/0x2/0x7/0x1c (/sys/include/pool.h)
->  Line: 0x392 (914)  Name:  ()
->  Line: 0x393 (915)  Name: 0x1/0x2/0x7/0x1d (/sys/include/tos.h)
->  Line: 0x3ab (939)  Name:  ()
->  Line: 0x4eb (1259)  Name:  ()
```
however in zig, we do not use includes and .h files,
so we only need the first and last items in the stack:
the source file that the symbols belong to, and the pop
symbol with a null name and a value of the total linecount of the
preprocessed source. Since there is no preprocessing in zig, we
just make the linecount very large. There do not appear to be
any downsides to this approach. If this causes a bug in the future,
a simple fix would be to make the pop symbol just have the value
of how many newlines are in the source file.
2022-01-06 13:17:00 +01:00
Jakub Konka
97e76bf36c stage2: temporarily disable offending stage2 test on macOS
Another caveat, `zig test` doesn't currently work on stage2.
2022-01-06 12:57:34 +01:00
Jakub Konka
a124192fb0 stage2: implement basics of airWrapErrUnionErr
Enable more behavior tests for x86_64.
2022-01-06 10:12:01 +01:00
Jakub Konka
ee6e9b3c48 stage2: fix airStructFieldPtr and airStructFieldVal
This finally fixes `zig test`.
2022-01-06 09:54:33 +01:00
Jakub Konka
b215241ef2 stage2: fix airSliceElemVal
Refactor codegen and fix a bug in Isel.
2022-01-06 09:54:33 +01:00
Jakub Konka
f4aa276a0c stage2: fix inline memcpy 2022-01-06 09:54:33 +01:00
Jakub Konka
f01e6eec56 stage2: implement slice_ptr 2022-01-06 09:54:33 +01:00
Jakub Konka
2b77775cbb stage2: fix loading pointer value from register
Fix accessing optional payload.
2022-01-06 09:54:33 +01:00
Jakub Konka
b3f70db438 stage2: implement CMP stack value with immediate 2022-01-06 09:54:33 +01:00
Andrew Kelley
1d55e4cae1 zig fmt 2022-01-06 01:18:54 -07:00
Andrew Kelley
8c6175c134 Sema: const inferred alloc infers comptime-ness
const locals now detect if the value ends up being comptime known. In
such case, it replaces the runtime AIR instructions with a decl_ref
const.

In the backends, some more sophisticated logic for marking decls as
alive was needed to prevent Decls incorrectly being garbage collected
that were indirectly referenced in such manner.
2022-01-06 00:52:10 -07:00
Andrew Kelley
713d2a9b38 Sema: better code generated for struct literals
Add a variant of the `validate_struct_init` ZIR instruction:
`validate_struct_init_comptime` which is the same thing except it
indicates a comptime scope.

Sema code for this instruction now handles default struct field
values and detects when the struct initialization resulted in a
comptime value, replacing the already-emitted AIR instructions
to store each individual field with a single `store` instruction
with a comptime struct value as the operand.

In the case of a comptime scope, there is a simpler path that only
evals the implicit store instructions for default field values, avoiding
the mechanism for detecting comptime values.

This regressed one test case for the wasm backend, but it's just hitting
a different prong of `emitConstant` which currently has "TODO" in there,
so I think it's fine.
2022-01-04 23:49:49 -07:00
Andrew Kelley
4bc6b4925c std.builtin: remove deprecated globals 2022-01-04 18:28:42 -07:00
Andrew Kelley
1c24ef0d0b stage2: introduce std.builtin.CompilerBackend
This allows Zig code to perform conditional compilation based on a tag
by which a Zig compiler implementation identifies itself.

See the doc comment in this commit for more details.
2022-01-04 18:12:45 -07:00
Andrew Kelley
5087ec6f41
Merge pull request #10508 from Luukdegram/wasm-behavior-tests
Stage2: wasm - Pass more behavior tests
2022-01-04 14:54:50 -05:00
Luuk de Gram
89b1fdc443
wasm: Implement memset, and sret arguments.
We now detect if the return type will be set by passing the first argument
as a pointer to stack memory from the callee's frame. This way, we do not have to
worry about stack memory being overwritten.

Besides this, we implement memset by either using wasm's memory.fill instruction when available,
or lower it manually. In the future we can lower this to a compiler_rt call.
2022-01-04 17:59:05 +01:00
Luuk de Gram
5c21a45cf0
wasm: Implement 'slice' instruction
Emitting undefined ptr's also has been implemented.
This means we now pass the void.zig behavior tests.
2022-01-04 17:51:49 +01:00
Luuk de Gram
c888485f85
wasm: Fix lowering constant struct values to the stack
We now get the null.zig, this.zig and member_func.zig behavior tests passing.
2022-01-04 17:51:24 +01:00
Luuk de Gram
c519d9c80e
wasm: Implement (and fix) most optional instructions
Previously we were performing the wrapping and unwrapping operations incorrectly.
We now correctly create the type and set its values.
Besides this, we also set the null-byte to the incorrect value, which meant we were
doing the opposite action of a is_null check. This is now fixed as well.

While implementing this, I found a small bug in the wrapErrUnionPayload where we
would load a pointer value and save that, rather than store the pointer with the error.
This is now fixed as well, by copying the entire operand into the payload of the error union.
2022-01-04 17:46:58 +01:00
Andrew Kelley
5c228765f1
Merge pull request #10504 from ziglang/linker-plumbing
linker: fix build-obj and -fno-emit-bin
2022-01-04 04:54:30 -05:00