7542 Commits

Author SHA1 Message Date
Andrew Kelley
abbcf40327 Sema: fix index type in AIR being u64 instead of usize 2022-01-31 16:41:14 -07:00
joachimschmidt557
2913950ca9 stage2 ARM: implement ptr_stack_offset function parameters 2022-01-31 23:52:32 +01:00
joachimschmidt557
66cf011aa9 stage2 ARM: Move to new regalloc freeze API 2022-01-30 19:41:51 -05:00
Andrew Kelley
227968d78c
Merge pull request #10723 from joachimschmidt557/stage2-riscv
stage2 RISCV64: Move to new regalloc freeze API
2022-01-30 19:41:35 -05:00
joachimschmidt557
b2338de7fd stage2 AArch64: Move to new regalloc freeze API 2022-01-30 19:41:11 -05:00
Andrew Kelley
fb7060d3c2 stage2: implement shl_exact and shr_exact
These produce an undefined value when one bits are shifted out.

New AIR instruction: shr_exact.
2022-01-30 16:23:31 -07:00
Andrew Kelley
0c30799d40 Sema: fix comptime shl for fixed-width integers 2022-01-30 15:23:40 -07:00
zseri
91ad96b88a ir.cpp: use is_tagged_union to DRY 2022-01-30 21:31:54 +02:00
PhaseMage
8a97807d68
Full response file (*.rsp) support
I hit the "quotes in an RSP file" issue when trying to compile gRPC using
"zig cc". As a fun exercise, I decided to see if I could fix it myself.
I'm fully open to this code being flat-out rejected. Or I can take feedback
to fix it up.

This modifies (and renames) _ArgIteratorWindows_ in process.zig such that
it works with arbitrary strings (or the contents of an RSP file).

In main.zig, this new _ArgIteratorGeneral_ is used to address the "TODO"
listed in _ClangArgIterator_.

This change closes #4833.

**Pros:**

- It has the nice attribute of handling "RSP file" arguments in the same way it
  handles "cmd_line" arguments.
- High Performance, minimal allocations
- Fixed bug in previous _ArgIteratorWindows_, where final trailing backslashes
  in a command line were entirely dropped
- Added a test case for the above bug
- Harmonized the _ArgIteratorXxxx._initWithAllocator()_ and _next()_ interface
  across Windows/Posix/Wasi (Moved Windows errors to _initWithAllocator()_
  rather than _next()_)
- Likely perf benefit on Windows by doing _utf16leToUtf8AllocZ()_ only once
  for the entire cmd_line

**Cons:**

- Breaking Change in std library on Windows: Call
  _ArgIterator.initWithAllocator()_ instead of _ArgIterator.init()_
- PhaseMage is new with contributions to Zig, might need a lot of hand-holding
- PhaseMage is a Windows person, non-Windows stuff will need to be double-checked

**Testing Done:**

- Wrote a few new test cases in process.zig
- zig.exe build test -Dskip-release (no new failures seen)
- zig cc now builds gRPC without error
2022-01-30 21:27:52 +02:00
Jonathan Marler
336aa3c332 remove __muloti4 from libc++
fixes https://github.com/ziglang/zig/issues/10719

compiler_rt already provides __muloti4 but libc++ is also providing it and when linking libc++ it causes a crash on my windows x86_64 machine.
2022-01-30 14:30:46 +01:00
Veikka Tuominen
924eb08b61 Merge branch 'fixcomptimesat'
Closes #10393
2022-01-30 11:40:03 +02:00
joachimschmidt557
1fd41af356
stage2 RISCV64: Move to new regalloc freeze API 2022-01-30 10:16:17 +01:00
joachimschmidt557
2a1727e93c
stage2 RISCV64: Merge Register and RawRegister enums 2022-01-30 10:16:13 +01:00
Andrew Kelley
f8e418c47d Sema: improved comptime % syntax
* comptime known 0 as a numerator returns comptime 0 independent of
   denominator.
 * negative numerator and denominator are allowed when the remainder is
   zero because that means the modulus would be also zero.
 * organize math behavior tests
2022-01-29 14:27:28 -07:00
riverbl
3c53667db8 stage2: fix bug where performing wrapping or saturating arithmetic or saturating left shift on type comptime_int executed unreachable code 2022-01-29 18:12:28 +02:00
riverbl
54634991a2 stage1: fix issue with bigint_add that caused incorrect results when adding a large and a small comptime_int of differing sign
stage1: fix issue with to_twos_complement that caused a compile error when performing wrapping addition on two signed ints, both of which have the minimum possible value
2022-01-29 18:12:28 +02:00
riverbl
aa29f4a803 stage1: fix saturating arithmetic producing incorrect results on type comptime_int, allow saturating left shift on type comptime int 2022-01-29 18:12:28 +02:00
Veikka Tuominen
9f16d9ed07
Merge pull request #10665 from Snektron/spirv-improvements
spir-v improvements
2022-01-29 15:59:42 +02:00
Sage Hane
e288148f60
fs: Use OpenMode enum instead of read/write flags. 2022-01-29 15:52:08 +02:00
Andrew Kelley
225910f934
Merge pull request #10639 from Vexu/f80
Add f80
2022-01-29 03:45:15 -05:00
John Schmidt
63ee6e6625 Rename mem.bswapAllFields to byteSwapAllFields
To match the renaming of `@bswap` to `@byteSwap` in
1fdb24827f.
2022-01-28 21:03:21 -05:00
joachimschmidt557
1a324a8ad6 stage2 regalloc: Fix bug where regs were not marked as allocated 2022-01-28 18:03:03 -05:00
Andrew Kelley
d7deffee8d link: ELF, COFF, WASM: honor the "must_link" flag of positionals
Previously only the MachO linker was honoring the flag.
2022-01-28 12:18:53 -07:00
Andrew Kelley
a0a71709bc stage1: lower const f80 a different way
this way passes the behavior tests
2022-01-28 11:45:04 -07:00
Andrew Kelley
3c827be876 fix invalid const bitcast of f80
LLVM bitcast wants integers that match the number of bits. So the const
bitcast has to use an i80, not an i128.

This commit makes the behavior tests fail for me, so it seems I did not
correctly construct the type. But it gets rid of the LLVM segfault.

I noticed that the strategy of memcpy the buf worked if I simply did an
LLVMConstTrunc() on the i128 to make it into an i80 before the
LLVMConstBitCast().

But is that correct in the face of different endianness? I'm not sure.
2022-01-28 11:45:04 -07:00
Veikka Tuominen
4411f9c019 add behavior tests for f80 2022-01-28 11:45:04 -07:00
Veikka Tuominen
f8b204bb18 stage1: call compiler-rt for math builtins on f80 on unsupported targets 2022-01-28 11:45:04 -07:00
Veikka Tuominen
0f3bd2afa3 stage1: handle compiler-rt calls on vectors of f80 2022-01-28 11:45:04 -07:00
Veikka Tuominen
8e9fd042b8 stage1: emit calls to compiler-rt for f80 on unsupported targets 2022-01-28 11:45:04 -07:00
Veikka Tuominen
a31a749c42 stage1: add f80 type 2022-01-28 11:45:04 -07:00
Robin Voetter
98ee39d1b0 spirv: spir-v dedicated type system 2022-01-28 14:45:23 +01:00
Robin Voetter
1b6ebce0da spirv: new module
This introduces a dedicated struct that handles module-wide information.
2022-01-28 14:38:58 +01:00
Robin Voetter
72e67aaf05 spirv: model spir-v section as separate type
The idea is that this type gains the relevant low-level instruction emitting
functions, and that higher-level checks and deduplications are performed
somewhere else.
2022-01-28 14:38:57 +01:00
Robin Voetter
462d8fd3ac spirv: keep track of air & liveness so that it can be used in flush() 2022-01-28 14:38:57 +01:00
Robin Voetter
94dd763936 spirv: regenerate spec
Regenerate the specification with the improvements previously made to the
spirv spec generator.
2022-01-28 14:38:57 +01:00
Andrew Kelley
0e6d2184ca stage2: .stub files are yet another c++ source file extension
however .cu files are a superset of c++.
2022-01-27 13:39:28 -07:00
Andrew Kelley
f589a66062 stage2: make cuda file extensions a separate enum tag than c++
follow-up to 2f41bd3be438dae2a188cfae3295dc28f4e9d434.
2022-01-27 13:29:32 -07:00
Daniel Saier
2f41bd3be4 zig cc: Treat cu files as C++ source files
First step towards #10634.

Treating stub files as C++ allows to use zig c++ as a host
compiler for nvcc.

Treating cu files as C++ allow using zig c++ as a host compiler in
CMake. CMake calls the host compiler with -E on a cu file to identify
the compiler.

Using zig c++ to directly compile CUDA code is untested.
2022-01-27 19:23:55 +02:00
Andrew Kelley
82bd0ac572 Sema: implement struct init is_ref=true
Takes advantage of the pattern already established with
array_init_anon. Also upgrades array_init (non-anon) to the pattern.

Implements comptime struct value equality and pointer value hashing.
2022-01-26 20:02:01 -07:00
Andrew Kelley
50accb757f stage2: fix crash on file-level struct field source locations 2022-01-26 20:02:01 -07:00
Andrew Kelley
b463924da2
Merge pull request #10699 from motiejus/arm64
[linux headers] rename arm64 to aarch64
2022-01-26 20:51:59 -05:00
Andrew Kelley
40c9ce2caf zig cc: add --hash-style linker parameter
This is only relevant for ELF files.

I also fixed a bug where passing a zig source file to `zig cc` would
incorrectly punt to clang because it thought there were no positional
arguments.
2022-01-26 15:01:59 -07:00
joachimschmidt557
35503b3d3f stage2 regalloc: Add freezeRegs/unfreezeRegs API
The freeze/unfreeze API replaces the exceptions API for hopefully
preventing bugs in codegen code using the RegisterManager. The
exceptions API is still available for backwards compatibility and will
be removed once all backends transition to the new freeze/unfreeze
API.
2022-01-26 18:23:27 +01:00
Jakub Konka
4192be8403 elf: implement slice types in debug info
Implements slice types including `[]const u8` for passing as
formal parameters in DWARF. Breaking on a function accepting
a slice in `gdb` will now yield the same behavior as stage1 and/or
LLVM backend:

```zig
fn sumArrayLens(a: []const u32, b: []const u8) usize {
  return a.len + b.len;
}
```

Both `a` and `b` can now be inspected in the debugger:

```
Breakpoint 1, sumArrayLens (a=..., b=...) at arr.zig:59
(gdb) p a
$1 = {ptr = 0x7fffffff685c, len = 5}
(gdb) p b
$2 = {ptr = 0x7fffffff683d "\252\252\252\\h\377\377\377\177", len = 3}
(gdb)
```
2022-01-26 17:28:58 +01:00
Jakub Konka
9f224ebd9a stage2: add zero- and sign-extend moves to x86_64
* remove `LoweringError` error set from `Emit.zig` - it actually
  was less than helpful; it's better to either not throw an error
  since there can be instructions with mismatching operand sizes
  such as `movsx` or assert on a by instruction-basis. Currently,
  let's just pass through and see how we fare.
* when moving integers into registers, check for signedness and move
  with zero- or sign-extension if source operand is smaller than 8
  bytes. The destination operand is always assumed to be full-width,
  i.e., 8 bytes.
* clean up `airTrunc` a little to match the rest of CodeGen inst
  implementations.
2022-01-26 16:14:57 +01:00
Jakub Konka
075e2eaaaf Merge branch 'x64-trunc' of git://github.com/mparadinha/zig into mparadinha-x64-trunc 2022-01-26 11:15:57 +01:00
Motiejus Jakštys
26e54d8a32 fix aarch64 include path 2022-01-26 09:10:12 +02:00
Andrew Kelley
f0ddc7f7a2 translate-c: update for new function pointer semantics
After #10656, function pointers are represented with e.g.
`*const fn()void` rather than `fn()void`.

This commit adds code to translate-c to emit different code
depending on whether the output zig source code is intended
to be compiled with stage1 or stage2.

Ideally we will have stage1 and stage2 support the exact same
Zig language, but for now they diverge because I would rather
focus on finishing and shipping stage2 than implementing the
features in stage1.
2022-01-25 22:04:01 -07:00
Andrew Kelley
618055db50 c backend: use an explicit map of reserved idents
rather than unconditionally prepending double underscore to all
identifiers. Also, use the prefix `zig_e_` instead of `__`. Also, avoid
triggering this escaping when rendering an identifier and there has
already been a prefix printed.
2022-01-25 20:49:43 -07:00
mparadinha
575d430f92 stage2: x64: implement airTrunc 2022-01-25 23:53:26 +00:00