Commit Graph

15243 Commits

Author SHA1 Message Date
Robin Voetter
497c0d3783 Allow x.y when x is a pointer 2021-09-20 02:29:03 +02:00
Robin Voetter
64c328a717 Address Spaces: Default align, linksection & addrspace for anon decls 2021-09-20 02:29:03 +02:00
Robin Voetter
e182c17187 Address Spaces: Disallow coercing pointers to different address spaces 2021-09-20 02:29:03 +02:00
Robin Voetter
0e6dc64a6f Address Spaces: Return proper address space for &x[y] 2021-09-20 02:29:03 +02:00
Robin Voetter
cd9f6001af Address Spaces: decl_ref, *?T => *T, and *(E!T) -> *T 2021-09-20 02:29:03 +02:00
Robin Voetter
6023108650 Address Spaces: x86 segment address spaces in builtin 2021-09-20 02:29:03 +02:00
Robin Voetter
cfbe9a6f61 Address spaces: Forbid addrspace and linksection for local variables 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
Andrew Kelley
9fa723ee50 stage2: implement @atomicStore 2021-09-19 15:08:38 -07: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
Andrew Kelley
f0b1eec809 ci: update to new sourcehut access token 2021-09-17 11:12:11 -07:00
Jakub Konka
d8375696f6 elf: add a couple missing special section indexes SHN_ 2021-09-17 12:12:50 +02:00
Andrew Kelley
b58d8aa05f stage2: improve LLVM backend for enums
* support lowering enum types and constants to LLVM IR
 * fix cmp instruction to support enum operands
2021-09-16 21:57:46 -07:00
Andrew Kelley
091a98f524 stage2: fix global variables with inferred type
Also, when a global variable does have a type, perform coercion on it.
2021-09-16 21:43:01 -07: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
Andrew Kelley
dc9d76b630 ci: go back to passing state for linux
This commit reverts 6d37ae95ed and
8f8294a809. I don't know why they caused a
failure but that investigation can happen while the CI is green.
2021-09-16 16:40:06 -07:00
Andrew Kelley
d11f42c2b2 zig cc: support -S and -emit-llvm CLI parameters
closes #6425
2021-09-16 16:39:04 -07:00
Andrew Kelley
6d37ae95ed build.zig: support -Duse-zig-libcxx
This supports the case when it is known that LLVM, Clang, LLD were built
with Clang (or `zig c++`). This commit updates the Linux CI script to
pass this since we build using a zig tarball.
2021-09-16 13:09:32 -07:00
Andrew Kelley
8f8294a809 ci: linux: enable LLVM stage2 tests 2021-09-16 11:21:56 -07:00
Andrew Kelley
2c8b201d05 build: make -Dskip-stage2-tests not build stage2
for the test-toolchain step
2021-09-16 11:21:56 -07:00
Andrew Kelley
ab84ba39d0 move behavior test to "passing for stage2" section 2021-09-16 11:21:56 -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
Žiga Željko
6f85a67987 stage2 Module: fix for 32 bit 2021-09-16 20:55:13 +03:00
Jakub Konka
983d6dcd9e macho: implement object relinking in stage2
* In watch mode, when changing the C source, we will trigger complete
  relinking of objects, dylibs and archives (atoms coming from the
  incremental updates stay put however). This means, we need to undo
  metadata populated when linking in objects, archives and dylibs.
* Remove unused splitting section into atoms bit. This optimisation
  will probably be best rewritten from scratch once self-hosted
  matures so parking the idea for now. Also, for easier management
  of atoms spawned from the Object file, keep the atoms subgraph as
  part of the Object file struct.
* Remove obsolete ref to static initializers in object struct.
* Implement handling of global symbol collision in updateDeclExports.
2021-09-16 12:38:47 +02:00
Stephen Gregoratto
506f24cac2 Set the Storage socket sizes to be system defined
Some systems (Solaris, OpenBSD, AIX) change their definitions of
sockaddr_storage to be larger than 128 bytes. This comment adds a new
constant in the `sockaddr` that defines the size for every system.

Fixes #9759
2021-09-16 13:32:55 +03:00
Ryan Liptak
db940a2c81 std.unicode: cleanup allocations on error in allocating functions
Fixes leaks when `utf16leToUtf8Alloc`/`utf16leToUtf8AllocZ`/`utf8ToUtf16LeWithNull` return an error and adds relevant test cases
2021-09-16 11:43:07 +02:00
Kirjastonhoitaja
e1bf350b4d net.Address: Fix writing 0-bytes when formatting Unix addresses
The entire 'path' array would get written to the formatting function,
when it should instead be treated as a regular zero-terminated string.

Note that this doesn't handle abstract paths on Linux, those paths
*start* with a \0 byte and are hence treated as empty strings instead.
But fixing that would require more adjustments than just formatting, in
particular to getOsSockLen().
2021-09-16 11:35:12 +02:00
Andrew Kelley
d5c1d24964 stage2: fix "cmpxchg with ptr" test case
* Sema: fix atomic operand checking to allow pointers.
 * LLVM backend: implement pointer-like optional constants.
 * LLVM backend: fix `is_non_null` and `optional_payload` instructions
   to support pointer-like optionals.
 * Type: introduce `isPtrAtRuntime` method.
 * Type: fix `isPtrLikeOptional` to get the correct answer for allowzero
   pointers and slices.
2021-09-15 19:55:57 -07:00
Andrew Kelley
b67d1810be stage2: implement @atomicRmw and @atomicLoad
* langref: add some more "see also" links for atomics
 * Add the following AIR instructions
   - atomic_load
   - atomic_store_unordered
   - atomic_store_monotonic
   - atomic_store_release
   - atomic_store_seq_cst
   - atomic_rmw
 * Implement those AIR instructions in LLVM and C backends.
 * AstGen: make the `ty` result locations for `@atomicRmw`, `@atomicLoad`,
   and `@atomicStore` be `coerced_ty` to avoid unnecessary ZIR
   instructions when Sema will be doing the coercions redundantly.
 * Sema for `@atomicLoad` and `@atomicRmw` is done, however Sema for
   `@atomicStore` is not yet implemented.
   - comptime eval for `@atomicRmw` is not yet implemented.
 * Sema: flesh out `coerceInMemoryAllowed` a little bit more. It can now
   handle pointers.
2021-09-15 19:00:35 -07:00
Jonathan Marler
f83a4b444c fix __chkstk on aarch64 2021-09-15 20:41:58 -04:00
Andrew Kelley
19691c0b17 stage2: implement @fence 2021-09-15 12:37:32 -07:00
Jonathan Marler
e5fd45003e azure pipeline fix removal of recently run exe
The following is an azure failure that occured Sep 13:

del : Cannot remove item D:\a\1\s\sfx.exe: The process cannot access the file 'D:\a\1\s\sfx.exe' because it is being used by another process.

Windows will keep a hold of recently run exeutables even after their process has exited.  To avoid this I've just removed the deletion of the exe file.  It's about 70 MB so it's probably OK.
2021-09-15 13:47:09 -04:00
Michal Ziulek
e06052f201
Added implementation for _fseeki64 and _ftelli64 from mingw-w64 9.0.0 (#9402). (#9766)
* Added fseeki64.c from mingw-w64 9.0.0. This file was missing in Zig distribution. This file contains implementation for _fseeki64 and _ftelli64 functions.
2021-09-15 13:38:00 -04:00
Andrew Kelley
2b90e2c284 ci: azure: update to newer msys2 release 2021-09-15 10:32:33 -07:00
Jakub Konka
25416d8121 macho: when adding extern fn, check if already resolved
This way, we will generate valid relocation info in the codegen.
2021-09-15 16:51:56 +02:00
Andrew Kelley
0395b35cee stage2: implement cmpxchg and improve comptime eval
* Implement Sema for `@cmpxchgWeak` and `@cmpxchgStrong`. Both runtime
   and comptime codepaths are implement.
 * Implement Codegen for LLVM backend and C backend.
 * Add LazySrcLoc.node_offset_builtin_call_argX 3...5
 * Sema: rework comptime control flow.
   - `error.ComptimeReturn` is used to signal that a comptime function
     call has returned a result (stored in the Inlining struct).
     `analyzeCall` notices this and handles the result.
   - The ZIR instructions `break_inline`, `block_inline`,
     `condbr_inline` are now redundant and can be deleted. `break`,
     `block`, and `condbr` function equivalently inside a comptime scope.
   - The ZIR instructions `loop` and `repeat` also are modified to
     directly perform comptime control flow inside a comptime scope,
     skipping an unnecessary mechanism for analysis of runtime code.
     This makes Zig perform closer to an interpreter when evaluating
     comptime code.
 * Sema: zirRetErrValue looks at Sema.ret_fn_ty rather than sema.func
   for adding to the inferred error set. This fixes a bug for
    inlined/comptime function calls.
 * Implement ZIR printing for cmpxchg.
 * stage1: make cmpxchg respect --single-threaded
   - Our LLVM C++ API wrapper failed to expose this boolean flag before.
 * Fix AIR printing for struct fields showing incorrect liveness data.
2021-09-14 21:58:22 -07:00
Travis Martin
5d14590ed1 Remove WIN16 version of WSAOVERLAPPED. Use LPWSAOVERLAPPED_COMPLETION_ROUTINE 2021-09-14 15:36:08 -04:00
Jacob G-W
370be12652 plan9 linker: fix for 32 bit 2021-09-14 19:04:09 +03:00
Jonathan Marler
010ca69864
add functions to decode an epoch timestamp (#9040)
* add functions to decode an epoch timestamp

The code added here is alternative to the libc gmtime function. This function takes a unix epoch timestamp and decodes it into things like the year/day/time/etc. I looked at various libc implementations to see how it was implemented and this appears to be correct. I reorganized it so that applications can choose which data they need rather than calcualting it all in a single function. The data structures layout the order of operations required to decode various things like the year/month or time of day.

* set Month.jan to 1 instead of 0 to avoid +1 in conversion to numeric

* add another test

* remove unnecessary comptimeMod
2021-09-14 19:02:23 +03:00
Jakub Konka
85f065a511
Merge pull request #9676 from ziglang/zld-incr
MachO: merges stage1 with self-hosted codepath
2021-09-14 14:20:11 +02:00
Philipp Lühmann
d1908c9f66
zig fmt: Keep callconv(.Inline) on function pointer types
Co-authored-by: Philipp Lühmann <mail@philipp.lu>
2021-09-14 11:36:26 +02:00
Jakub Konka
05763f43b3 macho: disable splitting sections into atoms in release
since we don't actually benefit from it just yet, and getting
it right for release and dead code stripping will require some more
thought put into it.
2021-09-14 10:28:58 +02:00