Commit Graph

16683 Commits

Author SHA1 Message Date
Andrew Kelley
c46f7588ce std.fmt.parseHexFloat: clean up bitwise logic
* fold a couple separate operations into one
 * use const instead of var
 * naming conventions
2022-01-31 20:59:32 -07:00
Mateusz Radomski
7f024d6786 std: correct rounding in parse_hex_float.zig 2022-01-31 20:59:32 -07:00
Jakub Konka
627cf6ce48 astgen: clean up source line calculation and management
Clarify that `astgen.advanceSourceCursor` already increments absolute
values of the line and columns numbers; i.e., `GenZir.calcLine` is thus
not only obsolete but wrong by design.

Incidentally, this clean up allows for specifying the `FnDecl` line
numbers for DWARF use correctly as relative values with respect to
the start of the parent `Decl`. This `Decl` in turn has its line number
information specified relatively to its parent `Decl`, and so on, until
we reach the global scope.
2022-01-31 22:29:29 -05:00
Andrew Kelley
abbcf40327 Sema: fix index type in AIR being u64 instead of usize 2022-01-31 16:41:14 -07:00
John Schmidt
8e497eb32c debug: fix edge cases in macOS debug symbol lookup
This commit fixes two related things:

1. If the loop goes all the way through the slice without a match, on
   the last iteration `mid == symbols.len - 1` which causes
   `&symbols[mid + 1]` to be out of bounds. End one step before that
   instead.

2. If the address we're looking for is greater than the address of the
   last symbol in the slice, we now match it to that symbol. Previously,
   we would miss this case since we only matched if the address was _in
   between_ the address of two symbols.
2022-01-31 23:55:19 +01:00
joachimschmidt557
2913950ca9 stage2 ARM: implement ptr_stack_offset function parameters 2022-01-31 23:52:32 +01:00
Žiga Željko
5210b9074c os,wasi: use wasi-libc if available 2022-01-31 22:54:30 +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
Jakub Konka
dd7309bde4
Merge pull request #10404 from ominitay/iterator
std: Fix using `fs.Dir.Iterator` twice
2022-01-30 14:25:50 +01:00
Veikka Tuominen
9c36ae4626
Merge pull request #10728 from naeu/thread-tests
Add tests for std.Thread.Condition and std.Thread.Semaphore
2022-01-30 12:00:49 +02: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
naeu
bdd1a9e48c std: add test for Thread.Semaphore 2022-01-29 20:30:53 +00:00
naeu
4efd951801 std: add test for Thread.Condition 2022-01-29 20:30:53 +00:00
Meghan
5e60ee4127
std: define static error set for fs.Dir.copyFile 2022-01-29 20:48:36 +02:00
Jean Dao
fedff06079 fix argsAlloc buffer size
The buffer `buf` contains N (= `slice_sizes.len`) slices followed by the
N null-terminated arguments. The N null-terminated arguments are stored
in the `contents` array list. Thus, `buf` size should be:
    @sizeOf([]u8) * slice_sizes.len + contents_slice.len

Instead of:
    @sizeOf([]u8) * slice_sizes.len + contents_slice.len + slice_sizes.len

This bug was found thanks to the gpa allocator which checks if freed
size matches allocated sizes for large allocations.
2022-01-29 20:46:06 +02:00
Andrew Kelley
aa902c7042 ci: azure: update to newer msys2 release 2022-01-29 11:28:57 -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
Jonathan S
aca665cebd
Fix overflow in std.math.isNormal when applied to -Inf or a negative NaN 2022-01-29 18:11:49 +02:00
Jonathan Marler
ba445013c4
improve comptime windows GUID.parse performance
I found that after switching from my custom Guid parser to the one in std that it increased zigwin32 build times substantially (from 40 seconds to over 10 minutes).  More information can be found in the benchmark PR I created here: https://github.com/ziglang/gotta-go-fast/pull/21 .  This PR ports my GUID parser to std so all projects can leverage the faster comptime performance.
2022-01-29 18:10:22 +02:00
Veikka Tuominen
8d0c17f5e4 std: remove superfluous .read = true from deflate tests 2022-01-29 16:57:10 +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
Veikka Tuominen
88edde4edc
Merge pull request #9915 from zzyxyzz/indexOfMinMax
std.mem: add indexOfMin and indexOfMax
2022-01-29 15:49:47 +02:00
ominitay
8ca9452a82 Remove deprecation warnings and enable test
Also fixes previously broken code uncovered by this
2022-01-29 15:49:00 +02:00
John Schmidt
adea9a1765
std.fmt: fix out-of-bounds array write in float printing
This commit fixes an out of bounds write that can occur when
formatting certain float values. The write messes up the stack and
causes incorrect results, segfaults, or nothing at all, depending on the
optimization mode used.

The `errol` function writes the digits of the float into `buffer`
starting from index 1, leaving index 0 untouched, and returns `buffer[1..]`
and the exponent. This is because `roundToPrecision` relies on index 0 being
unused in case the rounding adds a digit (e.g rounding 999.99
to 1000.00). When this happens, pointer arithmetic is used
[here](0e6d2184ca/lib/std/fmt/errol.zig (L61-L65))
to access index 0 and put the ones digit in the right place.

However, `errol3u` contains two special cases: `errolInt` and `errolFixed`,
which return from the function early. For these two special cases
index 0 was never reserved, and the return value contains `buffer`
instead of `buffer[1..]`. This causes the pointer arithmetic in
`roundToPrecision` to write out of bounds, which in the case of
`std.fmt.formatFloatDecimal` messes up the stack and causes undefined behavior.

The fix is to move the slicing of `buffer` to `buffer[1..]` from `errol3u`
to `errol` so that both the default and the special cases operate on the sliced
buffer.
2022-01-29 12:25:25 +01:00
John Schmidt
e51a44b342 fmt: handle doc comments on struct members
Closes https://github.com/ziglang/zig/issues/10443.
2022-01-29 12:19:31 +01: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
Andrew Kelley
39083c31a5 glibc: version-gate _DYNAMIC_STACK_SIZE_SOURCE
This is a patch to glibc features.h which makes
_DYNAMIC_STACK_SIZE_SOURCE undefined unless the version is >= 2.34.

This feature was introduced with glibc 2.34 and without this patch, code
built against these headers but then run on an older glibc will end up
making a call to sysconf() that returns -1 for the value of SIGSTKSZ
and MINSIGSTKSZ.

Closes #10713
2022-01-28 18:36:23 -07:00
Andrew Kelley
cd5b25c5ae build.zig: fix single-threaded option
Instead of defaulting to false, just keep the option as optional to
communicate default to the build system.

Fixes one problem with building the compiler for single-threaded
targets.
2022-01-28 17:17:31 -07:00
Andrew Kelley
68fc26cd08 std: break up some long lines
This makes packaging Zig for Debian slightly easier since it will no
longer trigger a Lintian warning for long lines.
2022-01-28 16:23:47 -07: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