Commit Graph

16490 Commits

Author SHA1 Message Date
Andrew Kelley
84c2c47fae Sema: implement else capture value
The ZIR instructions `switch_capture_else` and `switch_capture_ref` are
removed because they are not needed. Instead, the prong index is set to
max int for the special prong.

Else prong with error sets is not handled yet.

Adds a new behavior test because there was not a prior on to cover only
the capture value of else on a switch.
2022-01-17 20:45:55 -07:00
Andrew Kelley
2600978a9d behavior tests: a couple more switch cases are passing 2022-01-17 19:52:24 -07:00
Jakub Konka
e69cb9105a
Merge pull request #10616 from ziglang/stage2-x86_64-array-to-slice
stage2: implement airArrayToSlice for x86_64
2022-01-18 01:25:48 +01:00
Andrew Kelley
f4e051e35d Sema: fix comptime break semantics
Previously, breaking from an outer block at comptime would result in
incorrect control flow. Now there is a mechanism, `error.ComptimeBreak`,
similar to `error.ComptimeReturn`, to send comptime control flow further
up the stack, to its matching block.

This commit also introduces a new log scope. To use it, pass
`--debug-log sema_zir` and you will see 1 line per ZIR instruction
semantically analyzed. This is useful when you want to understand what
comptime control flow is doing while debugging the compiler.

One more `switch` test case is passing.
2022-01-17 15:23:50 -07:00
Jakub Konka
3145fa97c2 stage2: separate ptr and stack offset codepaths in genSetStack 2022-01-17 21:52:15 +01:00
Jakub Konka
ab204f81b0 stage2: return error.SkipZigTest in unsupported behavior tests 2022-01-17 20:30:44 +01:00
Jakub Konka
9b715cb462 stage2: implement airArrayToSlice for x86_64
* implement `genSetStack` for `ptr_stack_offset`
* handle `ptr_add`
* implement storing from register into pointer in register
* split alignment and array tests into those that pass on x86_64 and
  those that do not
* pass more tests on x86_64
2022-01-17 20:24:14 +01:00
Jakub Konka
79628d48a4 stage2: implement airCondBr for immediate MCValue in x86_64
Pass more behavior tests.
2022-01-17 16:35:41 +01:00
fn ⌃ ⌥
d46973ee4f translate-c: improve error messages when expecting specific tokens
Old:
  unable to translate C expr: expected ')'
New:
  unable to translate C expr: expected ')' instead got '...'
2022-01-17 17:16:48 +02:00
Meghan
4a92f42ed7 std.c: add shm_open and shm_unlink
https://man7.org/linux/man-pages/man3/shm_open.3.html
2022-01-17 16:56:50 +02:00
riverbl
c71cf48cb5 stage2: do not interpret identifier containing underscores (eg: u3_2) as int primitive type 2022-01-17 16:54:48 +02:00
johnLate
4addb26bba Fix os.rusage when linking with c library on Linux
Fixes ziglang#10543 on Linux.
2022-01-17 16:52:36 +02:00
riverbl
aa5514fcf2 translate-c: Fix issues translating macro define of hex float constant
* Fix incorrect result when the first digit after the decimal point is not 0-9 - eg 0x0.ap0
* Fix compiler panic when the number starts with `0X` with a capital `X` - eg 0X0p0
* Fix compiler panic when the number has a decimal point immediately after `0x` - eg 0x.0p0
2022-01-17 16:49:46 +02:00
Meghan Denny
0d0f277954 std: add json.stringifyAlloc 2022-01-17 12:32:02 +01:00
Jakub Konka
f72a0a2907 Merge branch 'Jarred-Sumner-patch-1' 2022-01-17 12:29:11 +01:00
Jakub Konka
90343d1868 libstd: add smoke test for insert methods in MultiArrayList 2022-01-17 12:26:48 +01:00
Jarred Sumner
144e36770e
Fix missing !void in std.MultiArrayList
Calling `insert` on a `std.MultiArrayList` currently fails with a compiler error due to using a `try` without the `!` annotation on the return type

```zig
this.list.insert(allocator, 0, listener);
```

```zig
/Users/jarred/Build/zig/lib/std/multi_array_list.zig:192:13: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(std.multi_array_list.MultiArrayList(src.javascript.jsc.node.types.Listener).ensureUnusedCapacity)).Fn.return_type.?).ErrorUnion.error_set'
            try self.ensureUnusedCapacity(gpa, 1);
```
2022-01-16 17:26:49 -08:00
Andrew Kelley
97063efb69 stage2: fix 32-bit build
Regressed in 7c6f5d26ea.
2022-01-16 10:18:14 -07:00
Andrew Kelley
0f3938e498 behavior tests: move tests around 2022-01-16 10:14:57 -07:00
Jimmi Holst Christensen
f19b5ecf4b Slice function of BoundedArray now returns slice based on self pointer
If self pointer is const, the slice is const. Otherwise the slice is
mutable.
2022-01-16 01:37:37 -05:00
Andrew Kelley
7f41e20802 AstGen: emit as instructions for branching expressions
There is a mechanism to avoid redundant `as` ZIR instructions which is
to pass `ResultLoc.coerced_ty` instead of `ResultLoc.ty` when it is
known by AstGen that Sema will do the coercion.

This commit downgrades `coerced_ty` to `ty` when a result location
passes through an expression that branches, such as `if`, `switch`,
`while`, and `for`, causing the `as` ZIR instruction to be emitted.

This ensures that the type of a result location will be applied to, e.g.
a `comptime_int` on either side of a branch on a runtime condition.
2022-01-15 23:13:44 -07:00
Andrew Kelley
7c6f5d26ea Sema: populate the sentinel for comptime array inits 2022-01-15 22:46:39 -07:00
joachimschmidt557
0d2f4d0654 stage2 ARM: implement load for stack_offset + stack_argument_offset
1 more behavior test passing
2022-01-15 18:29:06 -05:00
Andrew Kelley
d48e4245b6 stage2: implement @prefetch 2022-01-15 15:18:25 -07:00
Jakub Konka
3901b6fb00
Merge pull request #10598 from ziglang/stage2-x86_64-imm-sizes
stage2: rename Isel back to Emit, and fix immediate casts in Emit for x86 64
2022-01-15 22:27:56 +01:00
Jakub Konka
3af4e28dda stage2: implement signed compare 2022-01-15 19:32:16 +01:00
joachimschmidt557
e23f7c01ee stage2 ARM: store all function parameters to stack for unspecified cc 2022-01-15 12:49:36 -05:00
Jakub Konka
6315bcb32a stage2: rename Isel to Emit for x86_64
Clean up generated errors in Emit.
2022-01-15 18:36:13 +01:00
Jakub Konka
4d4bbd7624 stage2: refactor handling of immediates in x86_64 backend
Fixes issues with incorrect operand sizes in a handful of cases
and allows for usage of differently sized integers in Zig sources.
2022-01-15 18:28:39 +01:00
Andrew Kelley
a5c7742ba6 stage2: fix Decl garbage collection not marking enough
It is the job of codegen backends to mark Decls that are referenced as
alive so that the frontend does not sweep them with the garbage. This
commit unifies the code between the backends with an added method on
Decl.

The implementation is more complete than before, switching on the Decl
val tag and recursing into sub-values.

As a result, two more array tests are passing.
2022-01-15 00:17:25 -07:00
Andrew Kelley
41f3799bf0 Sema: fix array_init with runtime element
Previously it emitted an invalid AIR encoding.
2022-01-14 23:08:11 -07:00
Jakub Konka
ba0f72363a
Merge pull request #10576 from schmee/macos-resolve-ip
Use libc if_nametoindex for macOS when parsing IPs
2022-01-15 00:47:12 +01:00
Jakub Konka
b3471ef300 macho: code signature needs to be 16 bytes aligned 2022-01-14 22:32:33 +01:00
Andrew Kelley
1e481dfef5
Merge pull request #10587 from xxxbxxx/master
restore compatibility with glibc<=2.33 for global initializers
2022-01-14 14:40:54 -05:00
Andrew Kelley
3ed0741718 glibc: clean up build logic
also use the common naming convention for glibc versions ("2.33" rather
than "2-33").

I also verified that these files are exactly identical to the previous
files from before zig updated to glibc 2.34.
2022-01-14 12:39:06 -07:00
xavier
3f52132a8f tests: include global initializers in c++ compiler test 2022-01-14 11:48:38 -07:00
xavier
f1b14b91f1 glibc: restore compatibility with glibc<=2.33 for global initializers
__libc_start_main() from glibc.2.33.so or older needs to have a __libc_csu_init function callback parameter.

glibc-2.34 on the other hand has a different __libc_start_main() that does not use it,
and the start.S file from glibc-2.34 no longer construct the init function and pass null when calling __libc_start_main.

So, When targetting an older glibc, use the start.s files as they were in glibc-2.33 and construct the __libc_csu_init function.

fixes #10386 #10512
2022-01-14 11:48:37 -07:00
Marc Tiehuis
a64989ee70 stage1: fix bigint_init_bigfloat for single-limb negative floats
Fixes #10592.
2022-01-14 13:29:58 -05:00
John Schmidt
c992164dc7 Check for isDarwin() instead of linked libc 2022-01-14 13:44:38 +01:00
Andrew Kelley
ec58ddf46c
Merge pull request #10582 from ziglang/stage2-arrays
stage2: detection of comptime array literals
2022-01-14 00:23:27 -05:00
bryfry
0d45c72d3e Use allocPrintZ to avoid needing assumeSentinel 2022-01-14 00:17:38 -05:00
Andrew Kelley
336d0c97fe stage2: detection of comptime array literals
Introduce `validate_array_init_comptime`, similar to
`validate_struct_init_comptime` introduced in
713d2a9b38.

`zirValidateArrayInit` is improved to detect comptime array literals and
emit AIR accordingly. This code is very similar to the changes
introduced in that same commit for `zirValidateStructInit`.

The C backend needed some improvements to continue passing the same set
of tests:
 * `resolveInst` for arrays now will add a local `static const` with the
   array value and so then `elem_val` instructions reference that local.
   It memoizes accesses using `value_map`, which is changed to use
   `Air.Inst.Ref` as the key rather than `Air.Inst.Index`.
 * This required a mechanism for writing to a "header" which is lines
   that appear at the beginning of a function body, before everything
   else.
 * dbg_stmt output comments rather than `#line` directives.
   TODO comment reproduced here:

We need to re-evaluate whether to emit these or not. If we naively emit
these directives, the output file will report bogus line numbers because
every newline after the #line directive adds one to the line.
We also don't print the filename yet, so the output is strictly unhelpful.
If we wanted to go this route, we would need to go all the way and not output
newlines until the next dbg_stmt occurs.
Perhaps an additional compilation option is in order?

`Value.elemValue` is improved to support `elem_ptr` values.
2022-01-13 22:13:44 -07:00
Andrew Kelley
b019a19b55 Sema: comptime loads and stores for elem_ptr
The index is checked against actual array lengths, and now handles
coerced or casted pointers to single items.
2022-01-13 22:13:44 -07:00
Andrew Kelley
75b6637d60
Merge pull request #10584 from ziglang/macho-rustc-fixes
zld: a couple of fixes which result in better rustc support
2022-01-13 22:09:42 -05:00
joachimschmidt557
7e76aab98a stage2 AArch64: split ldr/str into {ldr,str}_register and _immediate 2022-01-14 00:46:07 +01:00
Jakub Konka
e945619728 macho: remove todo from getMatchingSectionDecl 2022-01-13 21:15:17 +01:00
Jakub Konka
5cde5f947f Introduce LinkObject with must_link field 2022-01-13 20:02:11 +01:00
Jakub Konka
a8564df9ed zld: parse addend from BRANCH reloc on x86_64
As usual, MachO, full of surprises!
2022-01-13 20:02:11 +01:00
Jakub Konka
16c55b15cb zld: support -Wl,-force_load=archive_path flag
This actually enables using `zig cc` as a linker for `cargo test`
with `serde_derive`.
2022-01-13 20:02:11 +01:00
Jakub Konka
f9f792ab70 zld: fix num nlist calc when there's no dynsymtab
Handle `__DATA,.rustc` section containing `rustc` metadata - this
is required to get crates like `serde_derive` link properly.
Note to self: this special section has to be copied __verbatim__
from the relocatable object file - this includes preserving its size
even though unpadded according the section's required alignment.
2022-01-13 20:02:11 +01:00