Commit Graph

4569 Commits

Author SHA1 Message Date
Travis Staloch
68050852fa sat-arithmetic: minor formatting changes 2021-09-28 17:03:43 -07:00
Travis Staloch
4870595352 sat-arithmetic: add additional tokenizer tests 2021-09-28 17:03:43 -07:00
Travis Staloch
dcbc52ec85 sat-arithmetic: correctly tokenize <<|, <<|=
- set state rather than result.tag in tokenizer.zig
- add test to tokenizer.zig for <<, <<|, <<|=
2021-09-28 17:03:43 -07:00
Travis Staloch
29f41896ed sat-arithmetic: add operator support
- adds initial support for the operators +|, -|, *|, <<|, +|=, -|=, *|=, <<|=
- uses operators in addition to builtins in behavior test
- adds binOpExt() and assignBinOpExt() to AstGen.zig. these need to be audited
2021-09-28 17:02:43 -07:00
Matthew Borkowski
1e805df81d deflate.zig: fix bits_left overflow at EndOfStream and @intCast truncation with empty Huffman table 2021-09-28 14:05:17 -04:00
rgreenblatt
754ea118bc improve panic hierarchy by always using builtin.panic 2021-09-28 13:10:10 -04:00
xackus
15f55b2805 os.flock: FreeBSD can return EOPNOTSUPP 2021-09-25 15:55:15 -04:00
Stephen Gregoratto
87fd502fb6 Initial bringup of the Solaris/Illumos port 2021-09-24 14:06:16 -04:00
Stephen Gregoratto
a032fd01e8 Resolve scope IDs using IPv6 sockets
On certain systems (Solaris), resolving the scope id from an interface
name can only be done on AF_INET-domain sockets. While we're here,
simplify the test while we're here, since there's only one address.

Also note that the loopback interface name is not stable across OSs.
BSDs and Solaris use `lo0` whilst Linux uses `l0`.
2021-09-24 13:50:18 -04:00
Andrew Kelley
418105589a stage2: prepare for building freestanding libc
Extracts lib/std/special/c_stage1.zig from lib/std/special/c.zig.

When the self-hosted compiler is further along, all the logic from c_stage1.zig will
be migrated back c.zig and then c_stage1.zig will be deleted. Until then we have a
simpler implementation of c.zig that only uses features already implemented in self-hosted.

So far it only contains memcpy and memset, with slightly different
(arguably more correct!) implementations that are compatible with
self-hosted.

Additionally, this commit improves the LLVM backend:
 * use the more efficient and convenient fnInfo() when lowering function
   type info.
 * fix incremental compilation not deleting all basic blocks of a
   function.
 * hook up calling conventions
 * hook up the following function attributes:
   - noredzone, nounwind, uwtable, minsize, optsize, sanitize_thread
2021-09-23 20:16:57 -07:00
Koakuma
bdbd060cc7 Linux/sparc64 bits: Add missing C type definitions 2021-09-23 13:57:55 -04:00
Andrew Kelley
dd81a2147d
Merge pull request #9825 from Snektron/big-int-signed-and-or
big ints: 2s complement signed and/or
2021-09-23 13:17:32 -04:00
Robin Voetter
cd3dcc225b big ints: only write xor overflow if required 2021-09-23 06:28:09 +02:00
Robin Voetter
351e4f07ce big ints: 2s complement signed and + or fixes 2021-09-23 06:19:08 +02:00
Robin Voetter
f5c27dd11a big ints: 2s complement signed or 2021-09-23 04:08:27 +02:00
Martin Wickham
4782bededa Remove reference to stage2_os 2021-09-22 14:14:03 -05:00
Martin Wickham
d6e87da47b Make stage2 start.zig work on Windows 2021-09-22 13:58:49 -05:00
Ryan Liptak
3b09262c12 tokenizer: Fix index-out-of-bounds on unfinished unicode escapes before EOF 2021-09-22 14:33:33 -04:00
Coleman Broaddus
e14fcd60cb
FIX resize() for non u8 element types. (#9806) 2021-09-22 12:09:16 +03:00
Robin Voetter
4afe4bdfe7 big ints: 2s complement signed xor 2021-09-22 02:21:55 -04:00
Andrew Kelley
aecebf38ac stage2: progress towards ability to compile compiler-rt
* prepare compiler-rt to support being compiled by stage2
   - put in a few minor workarounds that will be removed later, such as
     using `builtin.stage2_arch` rather than `builtin.cpu.arch`.
   - only try to export a few symbols for now - we'll move more symbols
     over to the "working in stage2" section as they become functional
     and gain test coverage.
   - use `inline fn` at function declarations rather than `@call` with an
     always_inline modifier at the callsites, to avoid depending on the
     anonymous array literal syntax language feature (for now).
 * AIR: replace floatcast instruction with fptrunc and fpext for
   shortening and widening floating point values, respectively.
 * Introduce a new ZIR instruction, `export_value`, which implements
   `@export` for the case when the thing to be exported is a local
   comptime value that points to a function.
   - AstGen: fix `@export` not properly reporting ambiguous decl
     references.
 * Sema: handle ExportOptions linkage. The value is now available to all
   backends.
   - Implement setting global linkage as appropriate in the LLVM
     backend. I did not yet inspect the LLVM IR, so this still needs to
     be audited. There is already a pending task to make sure the alias
     stuff is working as intended, and this is related.
   - Sema almost handles section, just a tiny bit more code is needed in
     `resolveExportOptions`.
 * Sema: implement float widening and shortening for both `@floatCast`
   and float coercion.
   - Implement the LLVM backend code for this as well.
2021-09-21 23:21:07 -07:00
Vincent Rischmann
01f20c7f48 io_uring: implement read_fixed/write_fixed 2021-09-22 00:47:45 -04:00
Isaac Freund
8c86043178 std.build: fix handling of -Dcpu
Currently -Dcpu is completely ignored if -Dtarget isn't passed as well.
Further, -Dcpu=baseline is ignored even if -Dtarget=native is passed.

This patch fixes these 2 issues, always respecting the -Dcpu option if
present.
2021-09-22 00:46:37 -04:00
Andrew Kelley
1ad905c71e
Merge pull request #9649 from Snektron/address-space
Address Spaces
2021-09-20 20:37:04 -04:00
Andrew Kelley
f8b914fcf3 Merge branch 'address-space' of Snektron/zig into Snektron-address-space
There were two things to resolve here:
 * Snektron's branch edited Zir printing, but in master branch
   I moved the printing code from Zir.zig to print_zir.zig. So that
   just had to be moved over.
 * In master branch I fleshed out coerceInMemory a bit more, which
   caused one of Snektron's test cases to fail, so I had to add
   addrspace awareness to that. Once I did that the tests passed again.
2021-09-20 17:32:52 -07:00
Ryan Liptak
2a728f6e5f tokenizer: Fix index-out-of-bounds on string_literal_backslash right before EOF 2021-09-20 20:16:14 -04:00
Andrew Kelley
4b2d7a9c67 stage2: implement comptime bitwise nand 2021-09-20 15:44:09 -07:00
Travis Martin
5dc251747b Fix compile error in WindowsCondition.wait() 2021-09-20 02:06:10 -04:00
HugoFlorentino
806aeab2a7 adding support for UTF-8 output 2021-09-20 02:05:52 -04:00
Ali Chraghi
db181b173f
Update hash & crypto benchmarks run comment (#9790)
* sync function arguments name with other same functions
2021-09-19 23:03:18 -07:00
Malcolm Still
1f61076ffb I'm working on a WebAssembly interpreter in zig. WebAssembly uses LEB128 encoding throughout its specification.
The WebAssembly spec requires signed LEB128 to be encoded up to a maximum number of bytes (max 5 bytes for i32, max 10 bytes for i64) and that "unused" bits are all 0 if the number is positive and all 1 if the number is negative. The Zig LEB128 implementation already enforces the max number of bytes and does check the unused bytes https://github.com/ziglang/zig/blob/master/lib/std/leb128.zig#L70-L79.

However, the WebAssembly test suite has a number of tests that were failing validation (expecting the wasm module to fail validation, but when running the tests, those examples were actually passing validation):

    https://github.com/malcolmstill/foxwren/blob/master/test/testsuite/binary-leb128.wast#L893-L902
    https://github.com/malcolmstill/foxwren/blob/master/test/testsuite/binary-leb128.wast#L934-L943

Notably the failures are both cases of negative numbers and the top 4 bits of the last byte are zero. And I believe this is the issue: we're only currently checking the "unused" / remaining_bits if we overflow, but in the case of 0x0_ no overflow happens and so the bits go unchecked.

In other words:

    \xff\xff\xff\xff\7f rightly successfully decodes (because it overflows and the remaining bits are 0b1111)
    \xff\xff\xff\xff\6f rightly errors with overflow (because it overflows and the remaining bits are 0b1110)
    \xff\xff\xff\xff\0f incorrectly decodes when it should error (because the top 4 bits are all 0, and so no overflow occurs and no check that the unused bits are 1 happens)

This PR adds a the remaining_bits check in an else branch of the @shlWithOverflow when we're looking at the last byte and the number being decoded is negative.

Note: this means a couple of the test cases in leb128.zig that are down as decoding shouldn't actually decode so I added the appropriate 1 bits.
2021-09-20 01:58:18 -04:00
Robin Voetter
619260d94d Address Spaces: Fix comments in Ast.zig 2021-09-20 02:34:53 +02:00
Robin Voetter
95e83afa98 Address Spaces: Yeet address space on function prototypes
This is a property which solely belongs to pointers to functions,
not to the functions themselves. This cannot be properly represented by
stage 2 at the moment, as type with zigTypeTag() == .Fn is overloaded for
for function pointers and function prototypes.
2021-09-20 02:29:04 +02:00
Robin Voetter
c5945467ac Address Spaces: Pointer and function info in @Type 2021-09-20 02:29:04 +02:00
Robin Voetter
68fcbb5c0d Address Spaces: fmt a bunch of stuff 2021-09-20 02:29:04 +02:00
Robin Voetter
8672f2696f Address Spaces: zig fmt + tests 2021-09-20 02:29:04 +02:00
Robin Voetter
6023108650 Address Spaces: x86 segment address spaces in builtin 2021-09-20 02:29:03 +02:00
Robin Voetter
805e1bffbd Address Spaces: Sema basics 2021-09-20 02:29:03 +02:00
Robin Voetter
7da9fa6fe2 Address spaces: AstGen
Adds AST generation for address spaces on pointers, function prototypes,
function declarations and variable declarations. In the latter two cases,
declaration properties were already stored more efficiently in a declaration
structure. To accomodate these for address spaces, the bit indicating presence
of a linksection attribute has been extended to include either linksection,
address space, or both.
2021-09-20 02:29:03 +02:00
Robin Voetter
ccc7f9987d Address spaces: addrspace(A) parsing
The grammar for function prototypes, (global) variable declarations, and
pointer types now accepts an optional addrspace(A) modifier.
2021-09-20 02:29:03 +02:00
Jakub Konka
2a0c44fff3 elf: add amd64 relocation types
I believe these are Linux specific so they will need to be os-gated
in `elf.zig` at some point, but I reckon it should be fine to have
them as-is right now since the ELF linker work will mainly be done
on x86-64 Linux at first.
2021-09-19 14:02:22 +02:00
Ryan Liptak
224d4de747 Improve ensureTotalCapacity call in ChildProcess.collectOutputWindows
Take current len and max_output_bytes into account instead of unconditionally using bump_amt
2021-09-19 13:52:56 +02:00
Ryan Liptak
59f5053bed Update all ensureCapacity calls to the relevant non-deprecated version 2021-09-19 13:52:56 +02:00
Ryan Liptak
feeb25908b std.PriorityDequeue: ensureUnusedCapacity and ensureTotalCapacity
Same as c8ae581fef, but for PriorityDequeue.
2021-09-19 13:52:56 +02:00
Ryan Liptak
2be3b1d2bf std.PriorityQueue: ensureUnusedCapacity and ensureTotalCapacity
Same as c8ae581fef, but for PriorityQueue.
2021-09-19 13:52:56 +02:00
Ryan Liptak
cfe71cb67a std.fifo.LinearFifo: ensureUnusedCapacity and ensureTotalCapacity
Same as c8ae581fef, but for LinearFifo.
2021-09-19 13:52:56 +02:00
Jens Goldberg
d2b5105f54
Add Linux ioctl creation utilities (#9748)
* Add Linux ioctl creation utilities

* Apply suggestions from code review

Co-authored-by: Veikka Tuominen <git@vexu.eu>

* Update lib/std/os/linux.zig

Co-authored-by: zigazeljko <ziga.zeljko@gmail.com>

Co-authored-by: Veikka Tuominen <git@vexu.eu>
Co-authored-by: zigazeljko <ziga.zeljko@gmail.com>
2021-09-18 09:56:11 +03:00
Jakub Konka
d8375696f6 elf: add a couple missing special section indexes SHN_ 2021-09-17 12:12:50 +02:00
Andrew Kelley
dbe9a5114e stage2: implement @setAlignStack and 128-bit cmpxchg
* test runner is improved to respect `error.SkipZigTest`
 * start code is improved to `@setAlignStack(16)` before calling main()
 * the newly passing behavior test has a workaround for the fact that
   stage2 cannot yet call `std.Target.x86.featureSetHas()` at comptime.
   This is blocking on comptime closures. The workaround is that there
   is a new decl `@import("builtin").stage2_x86_cx16` which is a `bool`.
 * Implement `@setAlignStack`. This language feature should be re-evaluated
   at some point - I'll file an issue for it.
 * LLVM backend: apply/remove the cold attribute and noinline attribute
   where appropriate.
 * LLVM backend: loads and stores are properly annotated with alignment
   and volatile attributes.
 * LLVM backend: allocas are properly annotated with alignment.
 * Type: fix integers reporting wrong alignment for 256-bit integers and
   beyond. Once you get to 16 byte aligned, there is no further
   alignment for larger integers.
2021-09-16 21:03:55 -07:00
Stephen Gutekanst
dc214e041e std/special: fix 'zig test --test-evented-io
Investigating hexops/zorex#4, I found that `--test-evented-io` is currently broken in
the latest Zig nightly. See #9779 for a small reproduction.

The issue is that allocation errors here are not correctly handled, as this function
returns `void` and all other error cases `@panic`, the allocation failure should also
use `@panic`.

Fixes #9779
Helps hexops/zorex#4

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2021-09-16 20:56:05 +03:00