3984 Commits

Author SHA1 Message Date
Jakub Konka
d542a588c6 Skip @sqrt f80 test on freebsd 2022-02-12 21:24:18 +01:00
Andrew Kelley
16076964d6 disable NaN f80 behavior tests
Let's get all these other bug fixes in and figure out f80 NaN later.
Looks like it's not working at comptime in master branch anyway.
2022-02-12 11:18:23 +01:00
Andrew Kelley
774f9bdb79 LLVM backend: disable failing aarch64 behavior test 2022-02-12 11:18:23 +01:00
Andrew Kelley
a024aff932 make f80 less hacky; lower as u80 on non-x86
Get rid of `std.math.F80Repr`. Instead of trying to match the memory
layout of f80, we treat it as a value, same as the other floating point
types. The functions `make_f80` and `break_f80` are introduced to
compose an f80 value out of its parts, and the inverse operation.

stage2 LLVM backend: fix pointer to zero length array tripping LLVM
assertion. It now checks for when the element type is a zero-bit type
and lowers such thing the same way that pointers to other zero-bit types
are lowered.

Both stage1 and stage2 LLVM backends are adjusted so that f80 is lowered
as x86_fp80 on x86_64 and i386 architectures, and identical to a u80 on
others. LLVM constants are lowered in a less hacky way now that #10860
is fixed, by using the expression `(exp << 64) | fraction` using llvm
constants.

Sema is improved to handle c_longdouble by recursively handling it
correctly for whatever the float bit width is. In both stage1 and
stage2.
2022-02-12 11:18:23 +01:00
joachimschmidt557
2262640e8b stage2 ARM: lower const slices
Follow-up to e1a535360fb9ed08fc48018571b9702ab12a5876 for ARM

This also fixes some stack offset calculation bugs
2022-02-12 00:01:05 +01:00
Cody Tapscott
70d7f87be0 Fix up sign handling and add arbitrary-length integer support to @bitCast() 2022-02-11 08:49:19 -07:00
Jakub Konka
cad3e3e63a x64: enable more behavior tests 2022-02-11 12:49:06 +01:00
Luuk de Gram
9c6d416bec
Activate passing behavior tests
This moves the single bugs behavior tests to the outer branch and disables the test cases
for all non-passing backends.
For the larger files, we move it up a single branch and disable it for the c backend.
All test cases that do pass for the c backend however, are enabled.
2022-02-10 21:40:06 +01:00
Jakub Konka
e139c41fd8 stage2: handle truncate to signed non-pow-two integers 2022-02-10 15:05:12 +01:00
Andrew Kelley
c10fdde5a6 stage2: LLVM backend: make unnamed struct globals
LLVM union globals have to be lowered as unnamed structs if the
non-most-aligned field is the active tag. In this case it bubbles up so
that structs containing unions have the same restriction.

This fix needs to be applied to optionals and other callsites of
createNamedStruct.

The bug fixed in this commit was revealed in searching for
the cause of #10837.
2022-02-10 00:27:02 -07:00
Sebsatian Keller
f5471299d8
stage 1: improve error message if error union is cast to payload (#10770)
Also: Added special error message for for `?T` to `T` casting
2022-02-09 20:35:53 -05:00
Andrew Kelley
1e5a494603 Sema: implement comptime ptr store to optional payload
and error union payload
2022-02-09 18:29:51 -07:00
John Schmidt
7f0cf395aa stage2: implement all builtin floatops for f{16,32,64}
- Merge `floatop.zig` and `floatop_stage1.zig` since most tests now pass
  on stage2.
- Add more behavior tests for a bunch of functions.
2022-02-09 20:29:41 -05:00
Andrew Kelley
db56d74a3b
Merge pull request #10834 from ziglang/fix-x86-i128-c-abi
stage1: fix x86 i128 C ABI for extern structs
2022-02-09 13:23:20 -05:00
Jakub Konka
e5ce87f1b1 stage2: handle decl ref to void types
Fixes behavior test 1914
2022-02-09 10:28:48 +01:00
Jakub Konka
4d1e5ef730
Merge pull request #10846 from ziglang/x64-macho-bringup
stage2: handle direct and got load for stack args on x86_64-macos
2022-02-09 08:17:29 +01:00
Andrew Kelley
f4fa32a632 Sema: fix @typeInfo for pointers returning 0 alignment 2022-02-08 23:02:13 -07:00
Andrew Kelley
1678825c14 Sema: fix @ptrCast from slices
Also, fix allocations in comptime contexts with alignments.
2022-02-08 22:51:46 -07:00
Andrew Kelley
59418d1bf6 Sema: fix Value.intFitsInType for comptime int 2022-02-08 22:09:41 -07:00
Andrew Kelley
77a6031edb C ABI: these tests are not passing yet on Windows
I was too greedy
2022-02-08 21:15:00 -07:00
Andrew Kelley
08808701d2 C ABI tests: give a clue in addition to "test failure" 2022-02-08 21:12:50 -07:00
Andrew Kelley
a35eb9fe8a c_abi tests: allow passing standard target options 2022-02-08 21:12:32 -07:00
Andrew Kelley
61ed4fe07a stage1: fix x86 i128 C ABI for extern structs
closes #10445
2022-02-08 20:10:55 -07:00
Andrew Kelley
7c1061784b stage2: fix inferred comptime constant locals
`const` declarations inside comptime blocks were not getting properly
evaluated at compile-time. To accomplish this there is a new ZIR
instruction, `alloc_inferred_comptime`. Actually we already had one
named that, but it got renamed to `alloc_inferred_comptime_mut` to match
the naming convention with the other similar instructions.
2022-02-08 20:03:17 -07:00
Jakub Konka
c689df1215 stage2: disable some tests on x86_64-macos 2022-02-08 23:59:10 +01:00
Jakub Konka
e42b5e76ba stage2: handle void type in Elf DWARF gen
Enable more behavior tests on both x64 and arm
2022-02-08 23:43:25 +01:00
joachimschmidt557
8fe9d2f986
stage2 ARM: airStructFieldVal for more MCValues 2022-02-08 21:02:56 +01:00
joachimschmidt557
6b0c950cb8
stage2 ARM: support all integer types in genTypedValue 2022-02-08 21:02:50 +01:00
Jakub Konka
9981b3fd2f stage2: tiny improvements all over the place
* pass more x64 behavior tests
* return with a TODO error when lowering a decl with no runtime bits
* insert some debug logs for tracing recursive descent down the
type-value tree when lowering types
* print `Decl`'s name when print debugging `decl_ref` value
2022-02-08 21:00:07 +01:00
Luuk de Gram
f50203c836 wasm: update test runner
This updates the test runner for stage2 to emit to stdout with the passed, skipped and failed tests
similar to the LLVM backend.

Another change to this is the start function, as it's now more in line with stage1's.
The stage2 test infrastructure for wasm/wasi has been updated to reflect this as well.
2022-02-08 10:03:29 +01:00
Jakub Konka
2302ded951
Merge pull request #10832 from ziglang/x64-more-structs
stage2,x64: pass more tests with structs
2022-02-08 10:02:06 +01:00
John Schmidt
722d4a11bb stage2: implement @sqrt for f{16,32,64}
Support for f128, comptime_float, and c_longdouble require improvements
to compiler_rt and will implemented in a later PR. Some of the code in
this commit could be made more generic, for instance `llvm.airSqrt`
could probably be `llvm.airUnaryMath`, but let's cross that
bridge when we get to it.
2022-02-07 16:52:19 -07:00
Jakub Konka
785bccd4ce stage2: pass more struct tests 2022-02-07 20:48:31 +01:00
Jakub Konka
0a7801236c stage2,arm: add lowering of unnamed consts
* implement `struct_field_ptr` when `MCValue == .stack_argument_offset`
* enable simple `struct` test for ARM
2022-02-07 20:10:01 +01:00
Evan Haas
e382e7be2b std: Allow mem.zeroes to work at comptime with extern union
Fixes #10797
2022-02-07 11:34:20 +02:00
Jakub Konka
5944e89016 stage2: lower unnamed constants in Elf and MachO
* link: add a virtual function `lowerUnnamedConsts`, similar to
  `updateFunc` or `updateDecl` which needs to be implemented by the
  linker backend in order to be used with the `CodeGen` code
* elf: implement `lowerUnnamedConsts` specialization where we
  lower unnamed constants to `.rodata` section. We keep track of the
  atoms encompassing the lowered unnamed consts in a global table
  indexed by parent `Decl`. When the `Decl` is updated or destroyed,
  we clear the unnamed consts referenced within the `Decl`.
* macho: implement `lowerUnnamedConsts` specialization where we
  lower unnamed constants to `__TEXT,__const` section. We keep track of the
  atoms encompassing the lowered unnamed consts in a global table
  indexed by parent `Decl`. When the `Decl` is updated or destroyed,
  we clear the unnamed consts referenced within the `Decl`.
* x64: change `MCValue.linker_sym_index` into two `MCValue`s: `.got_load` and
  `.direct_load`. The former signifies to the emitter that it should
  emit a GOT load relocation, while the latter that it should emit
  a direct load (`SIGNED`) relocation.
* x64: lower `struct` instantiations
2022-02-07 08:39:00 +01:00
Cody Tapscott
c1cf158729 Replace argvCmd with std.mem.join 2022-02-06 22:21:46 -07:00
Cody Tapscott
5065830aa0 Avoid depending on child process execution when not supported by host OS
In accordance with the requesting issue (#10750):
- `zig test` skips any tests that it cannot spawn, returning success
- `zig run` and `zig build` exit with failure, reporting the command the cannot be run
- `zig clang`, `zig ar`, etc. already punt directly to the appropriate clang/lld main(), even before this change
- Native `libc` Detection is not supported

Additionally, `exec()` and related Builder functions error at run-time, reporting the command that cannot be run
2022-02-06 22:21:46 -07:00
Andrew Kelley
287ff4ab58 stage2: add more float arithmetic and f80 support
AstGen: Fixed bug where f80 types in source were triggering illegal
behavior.

Value: handle f80 in floating point arithmetic functions.

Value: implement floatRem and floatMod

This commit introduces dependencies on compiler-rt that are not
implemented. Those are a prerequisite to merging this branch.
2022-02-06 19:27:54 -07:00
John Schmidt
fd1284ebd0 stage2: apply type coercion in if expressions
When setting the break value in an if expression we must explicitly
check if a result location type coercion that needs to happen. This was
already done for switch expression, so let's just imitate that check
and fix for if expressions. To make this possible, we now also propagate
`rl_ty_inst` to sub scopes.
2022-02-06 21:26:26 -05:00
joachimschmidt557
4468abfc42 stage2 ARM: enable a handful of passing behavior tests 2022-02-06 02:23:31 -05:00
Andrew Kelley
95fbce2b95 Sema: fixes to fieldVal, resolveStructFully, Type.eql
fieldVal handles pointer to pointer to array. This can happen for
example, if a pointer to an array is used as the condition expression of
a for loop.

resolveStructFully handles tuples (by doing nothing).

fixed Type comparison for tuples to handle comptime fields properly.
2022-02-03 23:59:32 -07:00
Mateusz Radomski
1b6a1e691f
Sema: check for NaNs in cmp (#10760) 2022-02-04 00:58:27 -05:00
Andrew Kelley
0893326e0e Sema: slice improvements
* resolve_inferred_alloc now gives a proper mutability attribute to the
   corresponding alloc instruction. Previously, it would fail to mark
   things const.
 * slicing: fix the detection for when the end index equals the length
   of the underlying object. Previously it was using `end - start` but
   it should just use the end index directly. It also takes into account
   when slicing a comptime-known slice.
 * `Type.sentinel`: fix not handling all slice tags
2022-02-03 21:05:10 -07:00
Luuk de Gram
588b88b987
Move passing behavior tests
Singular tests (such as in the bug ones) are moved to top level with exclusions for non-passing backends.
The big behavior tests such as array_llvm and slice are moved to the inner scope with the C backend disabled.
They all pass for the wasm backend now
2022-02-03 22:31:29 +01:00
Jakub Konka
f4e0641450 x64: use freeze/unfreeze api; TODO for PIE 2022-02-03 14:31:16 +01:00
Jakub Konka
b77757fe39 elf: add basic handling of .data section 2022-02-03 08:47:06 +01:00
Jakub Konka
7694361832
Merge pull request #10769 from ziglang/link-lib-fixes
stage2: handle name-qualified imports in sema, add a zerofill sections workaround to incremental macho
2022-02-02 20:59:17 +01:00
Andrew Kelley
3eb8d01f52
Merge pull request #10766 from ziglang/yeet-anytype-fields
remove anytype fields from the language
2022-02-02 13:39:27 -05:00
Jakub Konka
8f3be0e04f stage2: update stage2 tests with qualified import lib names for externs
From

```zig
extern fn write(...);
```

to

```zig
extern "c" fn write(...);
```
2022-02-02 16:25:46 +01:00