16859 Commits

Author SHA1 Message Date
Andrew Kelley
b92e1ab8cc stage1: override f80 alignment for i386-windows
Comment reproduced here:

Note the following u64 alignments:
  x86-linux:   4
  x86-windows: 8
LLVM makes x86_fp80 have the following alignment and sizes regardless
of operating system:
  x86_64: size=16, align=16
  x86:    size=12, align=4
However in Zig we override x86-windows to have size=16, align=16
in order for the property to hold that u80 and f80 have the same ABI size.

Fixes "error: destination type 'f80' has size 12 but source type 'u80'
has size 16" when trying to bitcast between f80 and u80 on i386-windows.
2022-02-12 11:18:23 +01:00
Andrew Kelley
d72f832b1e LLVM backend: call constPtrToInt instead of constBitCast
when appropriate. Avoids tripping an LLVM assertion.
2022-02-12 11:18:23 +01:00
Andrew Kelley
335c680cde LLVM backend: fix union with only 1 tag tripping llvm assertion 2022-02-12 11:18:23 +01:00
Andrew Kelley
1a8987fe7c CI: additionally test stage2 LLVM backend targeting aarch64-linux 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
Andrew Kelley
1c23321d03 stage1: fix softfloat not getting correct endianness
needed to include platform.h in more places so that LITTLEENDIAN will be
defined appropriately.

closes #10860
2022-02-12 11:18:23 +01:00
Andrew Kelley
166db1a3ed stage1: fix f80 size and alignment on x86 and arm
* F80Repr extern struct needs no explicit padding; let's match the
   target padding.
 * stage2: fix lowering of f80 constants.
 * stage1: decide ABI size and alignment of f80 based on alignment of
   u64. x86 has alignof u64 equal to 4 but arm has it as 8.
 * stage2: fix Value.floatReadFromMemory to use F80Repr
2022-02-12 11:18:23 +01:00
Andrew Kelley
f293fbbeaf stage2: LLVM backend: adjust replaceAllUsesWith usage
replaceAllUsesWith requires the type to be unchanged. So we bitcast
the new global to the old type and use that as the thing to replace
old uses.

Fixes an LLVM assertion found while troubleshooting #10837.
2022-02-12 11:18:23 +01:00
Jakub Konka
beb275b371 Revert "CI: upgrade both host and target tarballs to llvm 13.0.1 x86_64-macos"
This reverts commit 1072d8a0658d76415124ef6aac6842283316f243.
2022-02-12 11:17:41 +01:00
Jakub Konka
1072d8a065 CI: upgrade both host and target tarballs to llvm 13.0.1 x86_64-macos 2022-02-12 11:01:10 +01:00
Andrew Kelley
3fdbc3bba8 CI: upgrade x86_64-macos tarball to llvm 13.0.1 2022-02-12 01:09:13 -07: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
Andrew Kelley
a5a7f0ff00 CI: upgrade x86_64-macos tarball to llvm 13.0.1 2022-02-11 15:57:44 -07:00
Jakub Konka
e1a535360f
Merge pull request #10862 from ziglang/elf-lower-slices
stage2: native backends: lower const slices
2022-02-11 15:02:17 +01:00
Jakub Konka
cad3e3e63a x64: enable more behavior tests 2022-02-11 12:49:06 +01:00
Jakub Konka
066758b1a2 macho: correctly lower slices incl reloc and rebase tracking
Match changes required to `Elf` linker, which enable lowering
of const slices on `MachO` targets.

Expand `Mir` instructions requiring the knowledge of the containing
atom - pass the symbol index into the linker's table from codegen
via mir to emitter, to then utilise it in the linker.
2022-02-11 12:16:32 +01:00
Jakub Konka
b9b1ab0240 elf: store pointer relocations indexed by containing atom
In `getDeclVAddr`, it may happen that the target `Decl` has not
been allocated space in virtual memory. In this case, we store a
relocation in the linker-global table which we will iterate over
when flushing the module, and fill in any missing address in the
final binary. Note that for optimisation, if the address was resolved
at the time of a call to `getDeclVAddr`, we skip relocating this
atom.

This commit also adds the glue code for lowering const slices in
the ARM backend.
2022-02-11 10:52:13 +01:00
Jakub Konka
08e2f5d083 codegen: handle lowering of const slice pointers 2022-02-11 10:52:13 +01:00
Andrew Kelley
f0400ad93e
Merge pull request #10857 from Luukdegram/wasm-tests
stage2: Wasm - implement field_ptr
2022-02-10 19:22:23 -05: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
Luuk de Gram
0e2fcab334
wasm: Implement 'field_ptr' constants
This implements the `field_ptr` value for pointers. As the value only provides us with the index,
we must calculate the offset from the container type using said index. (i.e. the offset from a struct field at index 2).

Besides this, small miscellaneous fixes/updates were done to get remaining behavior tests passing:
 - We start the function table index at 1, so unresolved function pointers don't can be null-checked properly.
 - Implement genTypedValue for floats up to f64.
 - Fix zero-sized arguments by only creating `args` for non-zero-sized types.
 - lowerConstant now works for all decl_ref's.
 - lowerConstant properly lowers optional pointers, so `null` pointers are lowered to `0`.
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
Jakub Konka
57357c43e3 elf: pad out file to the required size when init data
We need to pad out the file to the required maximum size equal the
final section's offset plus the section's size. We only need to
this when populating initial metadata and only when section header
was updated.
2022-02-10 08:12:02 +01:00
Andrew Kelley
65c812842d freestanding libc: fix missing functions
In the previous commit I got mixed up and cut-pasted instead of
copy-pasting. In this commit I made c_stage1.zig additionally included
for stage1 and everything else included for both. So moving forward we
move stuff over from c_stage1.zig to c.zig instead of copying.
2022-02-09 19:13:53 -07:00
Andrew Kelley
f2f1c63daf stage2: add log and logf to freestanding libc 2022-02-09 18:52:32 -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
44b5fdf326 Revert "ci: azure: split build-and-test step"
This reverts commit 846eb701821a3f2af514bbad770478e3276b2d89.

This did not properly translate the upload portion of the CI script to
powershell which broke our CI pipeline.
2022-02-09 18:26:56 -07:00
Andrew Kelley
274b9d5c1d ci: work around azure networking issue 2022-02-09 16:42:15 -07:00
Andrew Kelley
2836cd5fbd CLI: ignore -lgcc_s when it is redundant with compiler-rt
For some projects, they can't help themselves, -lgcc_s ends up on the
compiler command line even though it does not belong there. In Zig we
know what -lgcc_s does. It's an alternative to compiler-rt. With this
commit we emit a warning telling that it is unnecessary to put such
thing on the command line, and happily ignore it, since we will fulfill
the dependency with compiler-rt.
2022-02-09 11:38:33 -07: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
Andrew Kelley
92cb17a331 CI: windows: update env var names 2022-02-09 10:41:12 -07:00
Jakub Konka
2d39142133
Merge pull request #10843 from ziglang/fix-1914
stage2: handle decl ref to void types
2022-02-09 18:12:37 +01:00
Jakub Konka
ec3e638b97 elf: fix unaligned file offset of moved phdr containing GOT section 2022-02-09 13:22:50 +01:00
Jakub Konka
e588e3873c stage2: export trunc, truncf and truncl 2022-02-09 10:28:48 +01:00
Jakub Konka
b28e9e42e0 stage2: resolve struct type when lowering struct_field_* 2022-02-09 10:28:48 +01: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
97019bc56d Sema: handle inferred error set tail call
When Sema sees a store_node instruction, it now checks for
the possibility of this pattern:
  %a = ret_ptr
  %b = store(%a, %c)
Where %c is an error union. In such case we need to add to the
current function's inferred error set, if any.

Coercion from error union to error union will be handled ideally if the
operand is comptime known. In such case it does the appropriate
unwrapping, then wraps again.

In the future, coercion from error union to error union should do the
same thing for a runtime value; emitting a runtime branch to check if
the value is an error or not.

`Value.arrayLen` for structs returns the number of fields. This is so
that Liveness can use it for the `vector_init` instruction (soon to be
renamed to `aggregate_init`).
2022-02-09 00:10:53 -07: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
billzez
470c8ca48c
update RwLock to use static initialization (#10838) 2022-02-08 23:35:48 -05: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
a67893b0e1 stage1: fix x86_64-windows C ABI classification logic
16 bytes vectors are special cased because compiler-rt currently relies
on this.
2022-02-08 21:11:53 -07:00
Andrew Kelley
e06ac9537e stage2: fix x86_64-windows C ABI
It didn't return integer status for pointers and also it incorrectly
returned memory for optionals sometimes.
2022-02-08 21:10:29 -07:00