2852 Commits
0.7.0 ... 0.8.1

Author SHA1 Message Date
Andrew Kelley
12828c09d6 Release 0.8.1 2021-09-06 19:41:54 -07:00
Sebastian Ullrich
c72f584218 libunwind: fix unwinding through libunwind stack frames
Fixes #9591
2021-09-03 10:19:01 -07:00
Andrew Kelley
3617615e2d CI: update Linux and macOS tarballs to LLVM 12.0.1 2021-09-03 10:18:53 -07:00
Philip Åkesson
b3a4074358 std: Use truncating cast in WIFSTOPPED for Linux, FreeBSD and DragonFly
The intermediate value can be larger than an u16, so @truncate is needed
to match the behavior of musl.
2021-09-03 10:18:28 -07:00
Andrew Kelley
46f93807aa fix merge conflicts for this branch 2021-09-01 17:01:35 -07:00
Philipp Lühmann
5356151172 fix typo 2021-08-31 13:45:04 -07:00
Andrew Kelley
f7e08ea780 re-enable all the MIPS tests
LLVM 12.0.1 fixed the regressions from LLVM 12.0.0.

Closes #8155
2021-08-31 13:44:57 -07:00
Frank Denis
a1d532752f Don't define valgrind_support on macOS (#9612)
Unfortunately, Valgrind for macOS has been broken for years,
and the Homebrew formula is only for Linux.
2021-08-31 13:44:23 -07:00
Zach Banks
2588451967 std/ArrayList: Allow ArrayList(u0) to be created
Enable creating ArrayList with zero-sized types.
This type still tracks length, but does not allocate
additional memory.
2021-08-31 13:41:05 -07:00
Meghan Denny
551971b5c3 stage1: add c_longdouble mapping for s390x 2021-08-31 13:40:01 -07:00
Takeshi Yoneda
5d08e2b5d8 Wasm,libc: fix wasm-ld failure in matching libc symbols.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-08-31 13:39:15 -07:00
fn ⌃ ⌥
d38bd443ef Use -isysroot on Mojave too 2021-08-31 13:38:52 -07:00
David May
c9ab6baf06 Docs fix array/pointer/slice type coercion section (#9392)
* removed deprecated coercion: [X]T => [] const T

* Fixed tests and added desc for first test

* Improved heading
2021-08-31 13:35:24 -07:00
Alex Rønne Petersen
a45c0c5033 zig: -rdynamic now implies -fdll-export-fns unless the latter is explicitly set.
Fixes #9340.
2021-08-31 13:32:27 -07:00
Michal Ziulek
7b9612a922 Fixed compile error: 'bMenu' needs to casted. (#9426) 2021-08-31 13:31:41 -07:00
Biolunar
1cddcf4484 linux stdlib: fix definition of RW flags (#9428) 2021-08-31 13:31:27 -07:00
Frank Denis
b8a77f3d59 std.crypto: handle the top bit in 25519.field.fromBytes64() (#9435)
The only known use case for this is the hash-to-curve operation where the top bit is always cleared.

But the function is public, so let's make it work as one would expect in the general case.

Also fix the comment by the way.
2021-08-31 13:31:06 -07:00
Tau
d4e22e3eb6 Correct hasUniqueRepresentation for vectors
Closes #9333.
2021-07-21 12:30:56 -07:00
Andrew Kelley
d99f55b7cf std.ArrayList: add missing assertion in appendSliceAssumeCapacity 2021-07-21 12:30:37 -07:00
Isaac Freund
2561b1eb67 langref: remove incorrect statement on c_void
c_void is *not* simply `const c_void = opaque{};`. It has unique
semantics as any pointer type may coerce to `*c_void` which is not true
for an arbitrary `*opaque{}`.
2021-07-21 12:27:21 -07:00
Adam C
c1e444b07c FIX typo in doc comment for std.math.hypot (#9413) 2021-07-21 12:25:52 -07:00
Ryan Liptak
84154b10a2 Add inotify_rm_watch definition to c/linux.zig
Also make inotify_add_watch's pathname marked as nul-terminated
2021-07-21 12:25:10 -07:00
Ryan Liptak
ba47e09373 Add NotDir as possible error for os.inotify_add_watch
Possible when "mask contains IN_ONLYDIR and pathname is not a directory."
2021-07-21 12:25:05 -07:00
leesongun
1063bf696e Fix bigint_shl (#9305) 2021-07-21 12:24:53 -07:00
Jonathan Marler
3b8c4f07a4 clarify @bitSizeOf behavior 2021-07-21 12:24:47 -07:00
Martin Wickham
3dcbd489eb Fix libc include directories for the MSVC target 2021-07-21 12:22:09 -07:00
Malcolm Still
5582d20f04 Add waitid syscall on linux (#9335) 2021-07-21 12:22:03 -07:00
Andrew Kelley
13aedf09d6 mingw-w64: add odbc32 and dbghelp def files
related: #9124
2021-07-21 12:21:58 -07:00
Martin Wickham
cd078c518f Fix argument forwarding to LLVM on Windows 2021-07-21 12:21:48 -07:00
leesongun
ceebcfa317 Fix unexpected truncation behavior with comptime_int larger than u64 range (#9303)
Closes #9299
2021-07-06 21:30:58 -07:00
Jacob G-W
b26ab39836 remove really weird debugging statement from stage1 2021-07-06 21:30:46 -07:00
Nulo
eac9bfaa01 Link to the GPA now that it's on upstream 2021-07-06 21:30:24 -07:00
Nulo
8a83143316 CODE_OF_CONDUCT: change Freenode to Libera.chat 2021-07-06 21:30:15 -07:00
Andrew Kelley
3ef9bd5879 stage2: add the zig version to AstGen cache hash
This solves the problem of different versions of Zig having different
binary representations of ZIR code.

closes #9290
2021-07-03 15:31:29 -07:00
Veikka Tuominen
f385522ab0 stage2: fix @asyncCall parameter count
Closes #9269
2021-07-03 15:29:52 -07:00
Nameless
de028d5130 std/os/uefi: fix packed struct bitfields 2021-07-03 15:28:57 -07:00
Andrew Kelley
390a4ded98 Merge pull request #9258 from ziglang/shared-cache-locking
Shared Cache Locking
2021-07-03 15:28:29 -07:00
Andrew Kelley
b0be0c77d8 Merge pull request #9148 from marler8997/windowsChildOutput
finish ChildProcess collectOutputWindows
2021-07-03 15:25:22 -07:00
xackus
440da6bfad mark tsan as linguist-vendored 2021-07-03 15:24:28 -07:00
Jacob G-W
b7fe0db9d2 langref: make @setRuntimeSafety more correct 2021-07-03 15:24:18 -07:00
Andrew Kelley
d59fc1ac04 stage1: @shuffle type and mask params in comptime scope 2021-07-03 15:22:53 -07:00
Roman Frołow
9349c9c4b1 Docs clarification: local static variable (#8381) 2021-07-03 15:22:21 -07:00
Jacob G-W
6caa77ea52 docs: top level global assembly -> container level 2021-07-03 15:22:17 -07:00
Andrew Kelley
caddd7eb18 std.crypto.p256: fix neg function compile error
There was a typo here and the neg function referenced a non-existent
variable.
2021-07-03 15:19:50 -07:00
Andrew Kelley
2b6727c98f std.os.linux.bpf: fix incorrect usage of unexpectedErrno 2021-07-03 15:19:50 -07:00
Andrew Kelley
5ef70b8b87 mips: fix syscall_pipe
Previously the fd parameter was ignored and so the result would not get
populated. Now it passes the fd pointer to the inline assembly so that
the results can be observed.
2021-07-03 15:19:50 -07:00
Isaac Freund
e75dfbcb3f std/build: add --sysroot general option 2021-06-26 12:51:49 +02:00
Isaac Freund
16228e87d6 stage2: add --sysroot link option
This feature is necessary for cross-compiling code that dynamically
links system libraries, at least with the current feature set of lld.
2021-06-26 12:49:08 +02:00
Isaac Freund
3e4f3a1924 zig build: add --libc general option
This new option sets a default libc paths file to be used for all
LibExeObjSteps. Setting LibExeObjStep.libc_file overrides this default.

This is required to allow users to cross compile projects linking system
libraries without needing to patch the build.zig.
2021-06-26 12:41:05 +02:00
mason1920
939408289c Bring your own MAX_PATH_BYTES
Previous to #7082, users could overwrite PATH_MAX in the root file to support std.os.toPosixPath, permitting the "bring your own operating system" layer to implement the POSIX API for opening files. Unfortunately that is no longer the case.

This commit intends to fix what is arguably a regression from 0.7 in a way that doesn't break any code targeting 0.8.0, making it suitable to be included in a 0.8 patch release.
However in a future release that permits breaking changes, I am of the opinion that it would be beneficial to overwrite the value, even for "supported" operating systems. Same for all the other POSIX/BYOOS functions and values. However this is beyond the scope of this commit. Further discussion of this will be made into an issue in due time.
2021-06-21 16:18:59 -07:00
Andrew Kelley
d0575310dc Merge pull request #9168 from LemonBoy/fix-pie
std: Fix PIE startup sequence
2021-06-20 17:03:50 -07:00
LemonBoy
b72d55ea5f std: Make copy_file_range checks run at compile-time
* Avoid emitting the copy_file_range symbol at all to prevent link-time
  errors.
* Fix a bug in the check logic, the has_copy_file_range_syscall was
  set to the wrong value in case of ENOSYS
* If link_libc is true don't fall-back to the raw syscall approach,
  there's no policy about what to do in this case but let's follow what
  the other impls do.

Fixes #9146
2021-06-20 16:54:39 -07:00
pithlessly
c7dd3cc535 stage2 sema: change impl of @setCold to use zirSetCold (typo?) 2021-06-20 16:37:55 -07:00
Michael Dusan
96b77e030f macho: LC_RPATH: reserve byte for null-terminator 2021-06-20 16:36:27 -07:00
hadroncfy
cf6e2d318a HashMap.getOrPutAssumeCapacityAdapted should set key to undefined (#9138)
* std.hash_map.HashMap: getOrPutAssumeCapacityAdapted should set key to undefined

* add test for std.hash_map.HashMap.getOrPutAdapted
2021-06-20 16:26:01 -07:00
Andrew Kelley
1fe0142d1f AstGen: properly generate errdefer expressions when returning
`return` statements use a new function `nodeMayEvalToError` which does
some basic checks on the AST node to return never, always, or maybe.

Depending on this result, AstGen skips the errdefers, always includes
the errdefers, or emits a conditional branch to check whether the return
value is an error that Sema will have to evaluate.

Closes #8821
Unblocks #9047
2021-06-20 16:25:52 -07:00
LemonBoy
76102ea41f stage1: Store the specified code model in the LLVM module
This is needed for LTO builds to pick up the correct module.

Closes #9132
2021-06-20 16:25:22 -07:00
Andrew Kelley
74ca811a66 Merge pull request #9117 from greenfork/unify-compiler-error-printing
stage2: Unify compiler error printing
2021-06-17 20:28:54 -07:00
Vincent Rischmann
721ec8fa53 zig cc: improve linker args parsing
Handle linker args joined with a = like -Wl,-rpath=foo

Update existing args --major-os-version, --minor-os-version,
--major-subsystem-version and --minor-subsytem-version to work with the
new parsing.

Also handle -Wl,--script in addition to -Wl,-T
2021-06-17 20:28:37 -07:00
Andrew Kelley
dc392f49f8 stage1: fix zig0 help message
closes #9140
2021-06-17 20:28:37 -07:00
d18g
71ec89383b Fix lakemont CpuModel (#9099)
Lakemont has no x86, no MMX, no SSE and no way of handling any fp-math. In theory LLVM is able to implicitly use the soft-float emulation library calls to legalize any such operation but, given Zig's use of many non-standard features, sometimes we hit a weak spot in the X86 codegen backend.

Consider this as a work-around for this LLVM problem, fixing the problem in LLVM is not so high in my todo list as the target is pretty niche and Intel axed it in '19.

(Commit message by @LemonBoy)
2021-06-17 20:28:37 -07:00
Michael Dusan
4adbdcb587 netbsd: add more std.os.bits 2021-06-17 20:28:37 -07:00
Michael Dusan
162b92c93e netbsd: add args to limit number of PT_LOAD segs
NetBSD expects 2 PT_LOAD segments in a shared object, otherwise
ld.elf_so fails to load, emitting a general "not found" error.

Workaround issue by adding args `--no-rosegment` and `-znorelro`.

see #9109
2021-06-17 20:28:37 -07:00
Andrew Kelley
8be29674a9 fix RISC-V assembly CPU features
Previously, Zig did not properly communicate the target CPU features for
RISC-V to clang assembler, because Clang has a different way to pass CPU
features for C code and for assembly code. This commit makes Zig pass a
RISC-V -march flag in order to communicate CPU features to Clang when
compiling assembly files.
2021-06-17 20:28:37 -07:00
Björn Linse
52ead255a2 std: don't reference non-existant ComptimeStringHashMap type 2021-06-15 13:32:14 -07:00
Andrew Kelley
6f180131a5 ci: azure: update to newer msys2 release 2021-06-14 12:16:54 -07:00
Isaac Freund
4453f6a5ce std: fix auto hash of tagged union with void field 2021-06-14 12:16:36 -07:00
viri
7f6e7e3e5d std.windows: fix OVERLAPPED, add OVERLAPPED_ENTRY 2021-06-14 12:14:46 -07:00
LemonBoy
5c9eb94a2b std: Fix complex ldexp implementation
Two bugs in the implementation ported from musl made all the complex
functions relying on ldexp return incorrect results in some cases.

Spotted in #9047
2021-06-14 12:13:53 -07:00
Andrew Kelley
9c1e7de6c6 zig cc: recognize more pie flags
This is a bug fix.
2021-06-14 12:13:03 -07:00
codic12
54229fec33 c.zig: fix waitpid() definition 2021-06-11 14:50:48 -07:00
Andrew Kelley
264969a8c3 better awareness of unwind tables
* stage1 backend allows configuring the uwtables function attr
   via a flag rather than its own logic.
 * stage2 defaults to enabling uwtable attr when
   linking libunwind, or always on windows
 * stage2 makes link_eh_frame_hdr true automatically if uwtable
   attr is set to be on for zig functions
 * CLI: add -funwind-tables and -fno-unwind-tables to allow the user to
   override the defaults.
 * hook it up to `zig cc`

closes #9046
2021-06-11 10:31:48 -07:00
Veikka Tuominen
e3a74697f0 Merge pull request #8330 from kivikakk/single-limb-bigint-overflow
bigint add failures with aliasing
2021-06-11 10:31:08 -07:00
LemonBoy
a913311f3c std: Fix tanh for negative inputs
It turns out the code was not ported correctly from C and produced wrong
results for negative input values. As a bonus fix the NaN codepath by
adding yet another missing piece of code.

Spotted in #9047
2021-06-11 10:30:07 -07:00
Andrew Kelley
ec4c60c481 zig fmt 2021-06-11 10:28:42 -07:00
LemonBoy
29386f0d30 stage1: Fix handling of C ABI parameters split in multiple regs
Take into account the increased number of parameters when flattening a
structure into one or more SSE registers.

Fixes #9061
2021-06-10 10:22:08 -07:00
Frank Denis
80e1797faf aes 128-bit key expansion test - properly test the inverse round keys (#9065) 2021-06-10 10:22:03 -07:00
Jakub Konka
f677c24740 Re-enable multiple wasm32 vector tests
Fixes #5339
2021-06-10 10:21:13 -07:00
Andrew Kelley
6afdc3cc79 CLI: remove --verbose-ast and --verbose-tokenize
closes #9034

These options were listed under the
"Debug Options (Zig Compiler Development)" heading. Anything in this
section should be considered unstable and can be modified at any time
at any developer's discretion.
2021-06-10 10:20:59 -07:00
Andrew Kelley
c230258d9b native libc detection: respect spaces in CC env var
Zig has detection for when it is accidentally being called recursively
when trying to find the native libc installation. However it was not
working, resulting in a cryptic failure, because zig tried to execute
a command which had spaces in it rather than tokenizing it.

This improves the user experience of `zig cc` for systems that Zig
does not support cross-compiling for.

Closes #8960
2021-06-10 10:20:52 -07:00
Andrew Kelley
2d0dff6498 langref: link to 0.7.1 not 0.7.0 for the previous docs 2021-06-10 10:20:27 -07:00
Andrew Kelley
060cb0f277 langref: remove paragraph that mentions IRC
I want the language reference to be divorced from any particular
community. Also remove the call to action since the docs are
known to be incomplete and are not the current focus of the project.

Closes #9055
2021-06-10 10:20:16 -07:00
Filippo Casarin
05380a11a4 std.math.sqrt_int: fixed odd size integers types 2021-06-10 10:20:09 -07:00
viri
4a3ac16711 std.Progress: use *W functions on windows
Closes #534.
See: https://source.winehq.org/git/wine.git/blob/refs/heads/stable:/dlls/kernelbase/console.c#l520
2021-06-10 10:19:37 -07:00
Jakub Konka
51076f4e1d libc,macos: update and add missing libc headers 2021-06-10 10:10:24 -07:00
Matthew Borkowski
503b85a1b0 stage1: make @truncate to an integer type of different sign an error at comptime too 2021-06-08 12:27:22 -07:00
Dustin Taylor
0c25ff81a3 Limit Fixed Buffer Stream seekTo (#9023) 2021-06-08 12:27:22 -07:00
Matthew Borkowski
39c80942e7 stage1: fix render_const_value for printing const optional pointers 2021-06-08 22:24:55 +03:00
Andrew Kelley
bfc85211bb link: windows: look for more DLL import lib path names
When linking with -lfoo syntax, this indicates to Zig that the
dependency should either be provided by Zig, or it should be dynamically
provided by the system.

For windows-gnu targets, the search path was "foo.lib". Now it
additionally looks for "libfoo.dll.a".

Closes #7799
2021-06-07 22:31:32 -07:00
LemonBoy
7ca86936ca std: Add helpers to safely align pointers
Add two helpers to ensure people won't ignore some edge cases such as
pointers overflowing the address space.

Also fix #8924 to some degree, the amount of unchecked alignForward is
still scary.

Revert "tests: disable i386-linux-gnu -lc target due to CI failures"

This reverts commit 97a2f4e7ae.
2021-06-06 18:07:47 -07:00
LemonBoy
5c765b2ec4 std: Fix some BPF fn definitions
Cros-checked with bpf.h of kernel 5.12.9.
2021-06-06 18:02:52 -07:00
LemonBoy
a745a17aa9 build: Avoid using undefined variables
Closes #9013
Closes #8928
Closes #7991
2021-06-06 18:01:52 -07:00
LemonBoy
2681e1ffe0 stage1: Apply the same set of fn attributes everywhere
Make sure to propagate the target-specific attributes to internal
functions too.

Closes #8965
2021-06-06 18:01:47 -07:00
Sebastien Marie
27f6db66e3 openbsd: adjust dynamic linker path (#9010)
the dynamic linker on OpenBSD is at /usr/libexec/ld.so (and not /libexec/ld.so)
2021-06-06 18:01:40 -07:00
Michael Dusan
6d6ba1e998 test: re-enable dragonfly tests
Tests with LLVM assertions enabled are no longer failing.

closes #3563
2021-06-05 19:54:45 -07:00
Nicolas
c8ee445c86 Add zig_llvm-ar.cpp in build.zig
This was added in 0afb5b2ec6 8 days ago, but it seems it was only added in the cmake files and not build.zig
2021-06-05 19:54:33 -07:00
LemonBoy
072c3202c3 std: Better handing of POLLHUP in ChildProcess (#8988)
* std: Better handing of POLLHUP in ChildProcess

Upon hitting the EOF condition there are two main differences between
how Linux and the *BSD-derived systems behave: the former sets POLLHUP
and POLLIN and, after reading any residual data, only POLLHUP remains
set. The latter signal the EOF condition by setting both flags thus
requiring some extra checks to determine if the stream is "done".

DragonFly workaround/hack for POLLHUP is no longer required.

Closes #8969
2021-06-05 19:54:26 -07:00
LemonBoy
07852a4bc8 compiler-rt: Fix __floatunsitf signature
The function transforms an unsigned integer into a f128.

Closes #8996
2021-06-05 10:35:05 -07:00
Andrew Kelley
ae1871a028 start the 0.8.1 release branch 2021-06-04 11:30:34 -07:00
Andrew Kelley
a642552faf Release 0.8.0 2021-06-04 11:21:32 -07:00
Andrew Kelley
2699232c4e Merge pull request #8990 from ziglang/mingw-w64-9.0.0
upgrade to mingw-w64 9.0.0
2021-06-04 14:17:40 -04:00
Felix (xq) Queißner
167754b31b Makes std.io.StreamSource usable with freestanding 2021-06-04 13:04:36 -04:00
Andrew Kelley
6f4339be3a update mingw-w64 crt files to v9.0.0 2021-06-04 09:49:36 -07:00
Andrew Kelley
d7f00c4389 update mingw-w64 headers to v9.0.0 2021-06-04 09:29:56 -07:00
Jacob G-W
5d94e754f4 fmt: fix #8974
also add a regression test
2021-06-04 10:49:05 +03:00
Min-Yih Hsu
83e0a49ba4 llvm: Add support for collecting time trace (#8546)
LLVM time profiler can collect time traces and present them in a
hierarchical view. Which breakdowns the time spent in each Pass or even
IR unit. The result is also exported into a format that can be easily
visualized by the Chrome browser.

Currently this features is controlled by the following environment
variables:
 - `ZIG_LLVM_TIME_TRACE_FILE` toggles this feature and specifies the
   output time trace file.
 - `ZIG_LLVM_TIME_TRACE_GRANULARITY` controls the time granularity in
   ms (default to 500).
2021-06-04 09:32:37 +02:00
Andrew Kelley
9c08a33b22 Merge pull request #8750 from lithdew/master
x/io, x/os: async i/o reactor, cross-platform socket syscalls and bits
2021-06-04 01:21:28 -04:00
Isaac Freund
05b677f0c4 langref: sync grammar with zig-spec repo 2021-06-04 01:18:45 -04:00
viri
ce072894a1 docs: minor spelling fix 2021-06-04 01:18:14 -04:00
Andrew Kelley
7d15a3ac71 Merge pull request #8975 from SpexGuy/hash-map-updates
Breaking hash map changes for 0.8.0
2021-06-04 01:12:38 -04:00
Martin Wickham
6953c8544b Fix return type of HashMap.getAdapted 2021-06-03 17:58:06 -05:00
Martin Wickham
fc9430f567 Breaking hash map changes for 0.8.0
- hash/eql functions moved into a Context object
- *Context functions pass an explicit context
- *Adapted functions pass specialized keys and contexts
- new getPtr() function returns a pointer to value
- remove functions renamed to fetchRemove
- new remove functions return bool
- removeAssertDiscard deleted, use assert(remove(...)) instead
- Keys and values are stored in separate arrays
- Entry is now {*K, *V}, the new KV is {K, V}
- BufSet/BufMap functions renamed to match other set/map types
- fixed iterating-while-modifying bug in src/link/C.zig
2021-06-03 17:02:16 -05:00
Andrew Kelley
87dae0ce98 Merge pull request #8932 from ziglang/llvm-needs-zlib
cmake: LLVM needs to link against zlib
2021-06-03 02:13:37 -04:00
Andrew Kelley
05cd8936c8 ci: drone: use zig-bootstrap tarball instead of system toolchain 2021-06-02 17:03:11 -07:00
Jakub Konka
d1f60a63bd zld: fix the linker for 32bit comp targets 2021-06-03 00:23:04 +02:00
Andrew Kelley
16c5cbab0c ci: update x86_64-freebsd tarball
to llvm 12.0.1-rc1, and -DLLVM_ENABLE_ZLIB=FORCE_ON
2021-06-01 23:26:53 -07:00
Evan Haas
a9dd8d7543 translate-c: Fix performance hazard in transPreprocessorEntities
Fixes O(N^2) behavior of `transPreprocessorEntities` due to repeated calls to
`mem.len`

Closes #8959
2021-06-02 09:12:45 +03:00
Veikka Tuominen
c6a0a4e728 translate-c: support designated initializers in macros 2021-06-01 23:40:43 -04:00
Jonathan Marler
99b6305aa8 handle LimitToBig error on setrlimit 2021-06-01 23:39:48 -04:00
Andrew Kelley
f693247295 Merge pull request #8917 from ifreund/fix-float-tokenize2
stage1, stage2: disallow 1.e9 and 0x1.p9 as float literals
2021-06-01 14:00:54 -04:00
Kenta Iwasaki
4909aa1da4 os/bits: remove duplicate sockaddr_storage for dragonfly 2021-06-01 18:35:13 +09:00
Kenta Iwasaki
aad8491dbd os: make msghdr, msghdr_const, and sockaddr_storage backwards-compatible
`msghdr` and `msghdr_const` definitions have been added back the way
they were in std.os. std.os.sendmsg has also been modified to accept a
msghdr_const again to ensure backwards-compatibility with this PR.
Underneath the hood, std.os.sendmsg will @ptrCast the provided
msghdr_const into a std.x.os.Socket.Message.

`sockaddr_storage` definitions have been added back the way they were in
std.os, except that it now simply aliases
std.x.os.Socket.Address.Native.Storage as all of
std.x.os.Socket.Address.Native.Storage's fields are equivalent to the
fields that were previously defined for std.x.os.bits.sockaddr_storage.

std.x.os.Socket.sendMessage now no longer is a stub that aliases
std.os.sendmsg, but instead calls and handles
errors from std.os.system.sendmsg directly.

Addresses feedback to urge backwards compatibility from @andrewrk.
2021-06-01 18:24:43 +09:00
Kenta Iwasaki
6950e4c294 x/os/net: remove unnecessary comptime prefix in resolveScopeID() 2021-06-01 18:24:43 +09:00
Kenta Iwasaki
278e5d398e x: replace std.builtin with std.Target.current 2021-06-01 18:24:43 +09:00
Kenta Iwasaki
21ec0158a1 os: sockaddr_storage -> std.x.os.Socket.Address.Native.Storage 2021-06-01 18:24:42 +09:00
Kenta Iwasaki
7b6ec3e354 x/os: {read, write}Vectorized() -> {read, write}Message() 2021-06-01 18:23:54 +09:00
lithdew
9ba65592d6 os: have sendmsg, recvmsg flags be c_int 2021-06-01 18:22:58 +09:00
lithdew
12650bcda4 x/os, x/tcp: fix Socket.Message init values and tcp test buf len 2021-06-01 18:22:58 +09:00
lithdew
494665e408 std/c: have sendmsg, recvmsg flags be u32 2021-06-01 18:22:58 +09:00
lithdew
d41575737e std/c: add recvmsg, sendmsg 2021-06-01 18:22:58 +09:00
lithdew
3600508fe1 x/io, x/os: async i/o reactor, cross-platform socket syscalls and bits
Cross-platform versions of msghdr, sendmsg, recvmsg, linger, and iovec
were provided based on findings from glibc, musl, and Microsoft's
documentation.

Implemented initial Reactor interface for epoll (linux) which wraps
around I/O reactor subsystems such as epoll, kqueue, select, etc. across
different platforms. The Reactor interface allows for driving async I/O
in Zig applications.

A test was added for the Reactor interface to drive a TCP
client/listener socket pair.

A greatest-common-subset of possible socket initialization flags (close
socket on exec syscalls, initialize socket to be non-blocking) were
implemented.

A test was added for using sendmsg/recvmsg syscalls across different
platforms for a TCP client/listener socket pair.
2021-06-01 18:22:57 +09:00
Frank Denis
d496400cff std.crypto.p256.scalar: fe struct member is not a function (#8954) 2021-06-01 11:02:48 +02:00
Andrew Kelley
a23fa896ef Tweak license in celebration of the upcoming 0.8.0 release :) 2021-05-31 14:12:20 -07:00
Isaac Freund
abd1c75c4a stage1: disallow 1.e9 and 0x1.p9 as float literals 2021-05-31 19:51:11 +00:00
Isaac Freund
608bc1cbd5 stage2: disallow 1.e9 and 0x1.p9 as float literals
Instead require `1e9` and `0x1p9`, disallowing the trailing dot.

This change to the grammar is consistent with forbidding `1.` and `0x1.`
as float literals and ensures there is only one way to do things here.
2021-05-31 19:51:11 +00:00
protty
eb6975f088 std.sync.atomic: extended atomic helper functions (#8866)
- deprecates `std.Thread.spinLoopHint` and moves it to `std.atomic.spinLoopHint`
- added an Atomic(T) generic wrapper type which replaces atomic.Bool and atomic.Int
- in Atomic(T), selectively expose member functions depending on T and include bitwise atomic methods when T is an Integer
- added fence() and compilerFence() to std.atomic
2021-05-31 11:11:30 -05:00
daurnimator
57cf9f7ea6 std: by default, disallow trailing data when parsing json 2021-05-31 14:09:59 +03:00
daurnimator
556d3e3d80 std: fix json.parse with 0 length arrays 2021-05-31 14:09:59 +03:00
Andrew Kelley
11ae6c42c1 Merge pull request #7918 from EthanGruffudd/json-ignore-fields
Add option to ignore unknown fields when parsing json
2021-05-30 14:59:02 -04:00
Andrew Kelley
32815914a4 std.json: update to new testing API 2021-05-30 11:57:44 -07:00
Ethan Gruffudd
781a21af2f std.json: option to ignore unknown fields
Closes #7906
2021-05-30 11:36:10 -07:00
Takeshi Yoneda
0ad1c04dd9 build: rename ast_render in build.zig.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-05-30 13:31:12 -04:00
Jakub Konka
0ad534b392 ci: update x86_64-macos and aarch64-macos tarballs
to llvm 12.0.1-rc1, and -DLLVM_ENABLE_ZLIB=FORCE_ON
2021-05-30 08:46:35 +02:00
Andrew Kelley
e46c55edbd ci: update x86_64-linux, aarch64-linux, and windows tarballs
to llvm 12.0.1-rc1, and -DLLVM_ENABLE_ZLIB=FORCE_ON
2021-05-29 20:18:02 -07:00
Andrew Kelley
f8bc5294f2 cmake: LLVM needs to link against zlib
For more details on why this dependency is needed, see
https://github.com/ziglang/zig-bootstrap/issues/57
2021-05-29 17:22:27 -07:00
Andrew Kelley
322215bf0a Merge pull request #8933 from ziglang/zig-ar
stage2: add `zig ar` subcommand
2021-05-29 19:31:30 -04:00
Andrew Kelley
e078b4f20e zig ar: workaround for LLVM bug
In this file is copy+pasted WindowsSupport.h from LLVM 12.0.1-rc1.
This is so that we can patch it. The upstream sources are incorrectly
including "llvm/Config/config.h" which is a private header and thus not
available in the include files distributed with LLVM.
The patch here changes it to include "llvm/Config/config.h" instead.
Patch submitted upstream: https://reviews.llvm.org/D103370
2021-05-29 13:54:31 -07:00
Andrew Kelley
0afb5b2ec6 stage2: add zig ar subcommand
The same entrypoint supports the following commands:

 * ar
 * ranlib
 * dlltool
 * lib

For now, our strategy is to bundle the (renamed) `main()` function of
llvm-ar, same as our strategy for `zig clang`. However, as Zig matures,
a goal will be to replace the dependency on LLVM  with our own
implementation of this tool, so that it is available in builds of zig
that do not have LLVM extensions enabled.

This commit also categorizes the subcommands into categories in the
--help menu.
2021-05-28 20:54:11 -07:00
Andrew Kelley
e248de93a0 add llvm-ar.cpp from llvm 12.0.1-rc1 2021-05-28 20:12:28 -07:00
Andrew Kelley
c12704a339 Merge pull request #8918 from ziglang/stage1-tokenizer
stage1: rework tokenizer to match stage2
2021-05-28 21:54:01 -04:00
Andrew Kelley
3f5ca3920a AstGen: properly restore previous state after temporary changes
Before this, if a compile error occurred, it would cause the previous
value for e.g. the function scope to not get reset. If the AstGen
process continued, it would result in a violation of the data
guarantees that it relies on.

This commit takes advantage of defer to ensure the previous value is
always reset, even in the case of an error.

Closes #8920
2021-05-28 17:29:56 -07:00
Matthew Borkowski
54f774f796 make writeIntSlice functions work for signed integers 2021-05-28 19:43:58 -04:00
Andrew Kelley
97a2f4e7ae tests: disable i386-linux-gnu -lc target due to CI failures
See #8930
2021-05-28 16:31:09 -07:00
LemonBoy
d3fb9f9532 stage1: Fix for atomicrmw xchg on fp types
Bitcast the pointer and operands to integer types having the same size,
working around LLVM inability to lower a LL/SC operation when the
operands have floating-point types (and are reasonably sized).

Closes #4457
2021-05-28 19:18:42 -04:00
Andrew Kelley
d888fa12a8 stage1 parser: fix the TODOs 2021-05-28 16:11:27 -07:00
Andrew Kelley
3483931d2a Merge pull request #8923 from Luukdegram/wasm-errors
stage2: wasm backend - Error sets and error unions
2021-05-28 18:45:36 -04:00
Andrew Kelley
f5d4fe3e17 stage1: memoize strings in the AST
Currently, stage1 runs astgen for every comptime function call,
resulting in identifier strings being allocated multiple times,
wasting memory. As a workaround until the code is adjusted to
make astgen run only once per source node, we memoize the
result into the AST.

 * Rename `ir_gen_*` to `astgen_*`
   - Oops, meant to do this in a separate commit. My bad.
 * tokenizer: avoid using designated initializer syntax.
   MSVC does not support it.
2021-05-28 15:22:03 -07:00
Andrew Kelley
52b3daa90e stage1: get test-compile-errors passing again 2021-05-28 14:19:08 -07:00
Andrew Kelley
9de2c1b76e stage1: tokenizer: backport recent stage2 changes
This backports ec10595b65 stage2 tokenizer
logic to stage1.
2021-05-28 13:26:16 -07:00
Andrew Kelley
33a779c7f6 start.zig: intentional silent failure when cannot increase stack size 2021-05-28 13:17:04 -07:00
Andrew Kelley
01e0a4b2f0 stage1: rename IrBasicBlockSrc to Stage1ZirBasicBlock 2021-05-28 12:58:40 -07:00
Andrew Kelley
548ef78070 stage1: remove source_node field from Stage1Zir
This field is unneeded because we always have the source node available
in the context that we have a Stage1Zir object.
2021-05-28 12:58:40 -07:00
Andrew Kelley
554dd52c36 stage1: remove c_import_buf from Stage1Zir
All we need is a boolean in Stage1AstGen. This is part of an effort to
make Stage1Zir immutable.
2021-05-28 12:58:40 -07:00
Andrew Kelley
4ea421f8cb stage1: move the ZigFn from Stage1Zir to Stage1AstGen
Part of an effort to make Stage1Zir immutable.
2021-05-28 12:58:40 -07:00
Andrew Kelley
42f4ee0aeb stage1: rename IrBuilderSrc to Stage1AstGen 2021-05-28 12:58:40 -07:00
Andrew Kelley
2440c08ab0 stage1: move next_debug_id from Stage1Zir to IrBuilderSrc
Part of an effort to make Stage1Zir immutable.
2021-05-28 12:58:40 -07:00
Andrew Kelley
b11ac9c5bf stage1: move some mutable state from Stage1Zir to IrAnalyze
This is progress towards making Stage1Zir immutable, so that we can
avoid generating it for every comptime function call.

Also rename IrExecutableGen to Stage1Air.
2021-05-28 12:58:40 -07:00
Andrew Kelley
e072ace436 stage1: rename IrExecutableSrc to Stage1Zir
and make IrBuilderSrc private to astgen.cpp
2021-05-28 12:58:40 -07:00
Andrew Kelley
eb37722d79 lol that's never going to happen in stage1 2021-05-28 12:58:40 -07:00
Andrew Kelley
2a990d6966 stage1: rework tokenizer to match stage2
* Extracts AstGen logic from ir.cpp into astgen.cpp. Reduces the
   largest file of stage1 from 33,551 lines to 25,510.
 * tokenizer: rework it completely to match the stage2 tokenizer logic.
   They can now be maintained together; when one is changed, the other
   can be changed in the same way.
   - Each token now takes up 13 bytes instead of 64 bytes. The tokenizer
     does not parse char literals, string literals, integer literals,
     etc into meaningful data. Instead, that happens during parsing or
     astgen.
   - no longer store line offsets. Error messages scan source
     files to find the line/column as needed (same as stage2).
   - main loop: instead of checking the loop, handle a null byte
     explicitly in the switch statements. This is a nice improvement
     that we may want to backport to stage2.
   - delete some dead tokens, artifacts of past syntax that no longer
     exists.
 * Parser: fix a TODO by parsing builtin functions as tokens rather than
   `@` as a separate token. This is how stage2 does it.
 * Remove some debugging infrastructure. These will need to be redone,
   if at all, as the code migrates to match stage2.
   - remove the ast_render code.
   - remove the IR debugging stuff
   - remove teh token printing code
2021-05-28 12:58:40 -07:00
Luuk de Gram
5cbe930e36 wasm: Add stage2 tests for error unions 2021-05-28 12:58:17 +02:00
Luuk de Gram
8a81dfc999 wasm: Reverse the order of error and payload
This will set us up to correctly retrieve the error local index and payload index
depending on that of the multi_value's index. As from now, the error will always use
the multi_value's index, and the payload will use the following locals.
2021-05-28 12:58:17 +02:00
Luuk de Gram
967a299c34 wasm: Add support for error union as return type
- This currently uses the multi-value feature to return both the possible error, and its payload.
- Also genAlloc and the logic to allocate the locals itself have been seperated, so we can create more locals
whenever needed, and not only when `genAlloc` is called.
2021-05-28 12:58:17 +02:00
Luuk de Gram
5481059232 wasm: Implement error unions and unwrapping
- Slightly refactored `Wvalue.multi_value` to also contain the amount of locals it contains,
this allows us to set all fields at once.
2021-05-28 12:58:17 +02:00
Luuk de Gram
a5b5a5532e wasm: Support error sets 2021-05-28 12:58:17 +02:00
Matthew Borkowski
673ae5b457 update comments to match changes to the formal grammar 2021-05-27 21:03:49 -04:00
Jakub Konka
c0aa9292ba build: allow specifying rpaths explicitly (#8912)
It currently looks like that if the user links in a dylib using
`lib_or_exe.linkSystemLibrary`, and the linked lib doesn't have
a hardcoded path in its description load command but rather it
allows for any runtime path via `@rpath`, then it is not possible
to specify the runtime path explicitly using the build system.
2021-05-27 21:01:32 -04:00
Isaac Freund
ec10595b65 stage2: disallow trailing dot on float literals
This disallows e.g. `1.` or `0x1.` as a float literal, which is
consistent with the grammar.
2021-05-27 21:00:44 -04:00
Andrew Kelley
4bf8ec9952 Merge pull request #8910 from mattbork/parser-small-allocs
Use shared scratch buffer to avoid allocating and freeing many small lists in parse.zig
2021-05-27 17:39:55 -04:00
Frank Denis
7674a8b43d p256: update to the last fiat-crypto code & share PC tables
fiat-crypto now generates proper types, so take advantage of that.

Add mixed subtraction and double base multiplication.

We will eventually leverage mixed addition/subtraction for fixed
base multiplication. The reason we don't right now is that
precomputing the tables at comptime would take forever.
We don't use combs for the same reason. Stage2 + less function
calls in the fiat-crypto generated code will eventually address
that.

Also make the edwards25519 code consistent with these changes.

No functional changes.
2021-05-27 16:35:10 -04:00
Matthew Borkowski
80c86ec960 keep temporary list from escaping parseParamDeclList, make SmallSpan.multi hold Node.SubRange instead of owned memory 2021-05-27 14:30:42 -04:00
Jakub Konka
d8d92dafe8 zld: search for .a before .dylib by default
Change default behaviour to search for static archives before searching
for dynamic libraries if no flag such as `-search_paths_first` is
specified. Also, fix a bug with early break from outer loop (label
in the wrong place).
2021-05-27 15:33:48 +02:00
Jakub Konka
ae15281c05 zld: dylib paths need nul terminator included 2021-05-27 11:36:13 +02:00
Matthew Borkowski
9ddd12ea14 parse.zig: use shared scratch buffer to avoid allocating and freeing many small lists 2021-05-26 22:01:04 -04:00
Matthew Borkowski
f750618846 stop tokenizer from recognizing lone @ or @ followed by a digit as a builtin 2021-05-26 04:13:04 -04:00
Andrew Kelley
44de884980 tokenizer: fix crash on multiline string with only 1 backslash
Closes #8904
2021-05-25 18:13:10 -07:00
LemonBoy
3ed6379192 stage1: Store target info in the LLVM module
This is needed to let LLVM (or, better, libLTO) produce code using the
target options specified by the user.

Fix #8803
2021-05-25 18:03:05 -04:00
Andrew Kelley
2f538f30fd Merge pull request #8894 from xxxbxxx/standalone_buildmodes
add standalone test for c compiler with build modes
2021-05-25 15:44:38 -04:00
Andrew Kelley
5c25160452 Merge pull request #8892 from mattbork/prec-doc
fix position of `orelse` and `catch` in precedence table documentation
2021-05-25 15:39:43 -04:00
joachimschmidt557
4c75f834e7 Re-enable building the self-hosted compiler for 32-bit targets 2021-05-25 15:38:32 -04:00
Matthew Borkowski
b01e5d9301 fix position of .* and .? in operator precedence table documentation 2021-05-25 00:09:28 -04:00
xavier
acaa0b8f08 remove reduntant new/delete implementation
The same code is provided by both libxx and libxxabi, and removed at linktime.
2021-05-25 00:42:39 +02:00
xavier
32154fbf0d add a standalone for zig as a c/c++ compiler 2021-05-25 00:42:31 +02:00
xavier
7e4f28fac9 standalone tests may now test cross targets and build modes. 2021-05-25 00:19:23 +02:00
Matthew Borkowski
46d8e010a0 fix position of orelse and catch in precedence table and remove misplaced error union operator 2021-05-24 16:58:20 -04:00
Andrew Kelley
8c5d4295e5 Merge pull request #8876 from xxxbxxx/cxx-lto
build libc++ with lto and function-sections
2021-05-24 13:58:02 -04:00
xavier
8275c771c8 zig cc: expose header files when linking libunwind 2021-05-24 13:48:49 -04:00
Jens Goldberg
1df993706a Fix socklen_t cast in win32 recvfrom
All other uses of `ws2_32.socklen_t` in windows.zig casts the value to an i32. `recvfrom` should do so as well; it currently errors out with `expected type '?*i32', found '?*u32'`.
2021-05-24 13:46:35 -04:00
Andrew Kelley
0a99898b98 Merge pull request #8862 from hoanga/haiku-support-linker
further haiku support    initial compile and link
2021-05-24 13:45:47 -04:00
Andrew Kelley
156b968ad8 stage2: remove dead code; rename crtbegin_dir to gcc_dir 2021-05-24 10:41:59 -07:00
Al Hoang
e8cf15236d add haiku case to csu 2021-05-24 10:39:02 -07:00
Al Hoang
5280ea5d22 update compilation and elf link for haiku case
* for some reason part of the linkable bits for the crt libraries
  are split in different locations for haiku. this changeset
  accomodates this situation (crtbegin_dir lookup)
2021-05-24 10:39:02 -07:00
Al Hoang
c4a4330cc7 haiku case for libc link flags 2021-05-24 10:39:01 -07:00
Al Hoang
2be2c983cb enable symbol lookup for haiku 2021-05-24 10:39:01 -07:00
Al Hoang
db8eae65de avoid usage of execv on Haiku 2021-05-24 10:39:01 -07:00
Michael Dusan
8cebbc352a housekeeping: builtin.arch → builtin.cpu.arch 2021-05-24 13:38:47 -04:00
Michael Dusan
1dc7764f2d clang driver: fix lost argv[0] 2021-05-24 13:26:52 -04:00
Ryan Liptak
6426519e32 zig fmt: Remove workaround for . and .. path handling on Windows
Added in #4655/#5187, obsoleted by #7664
2021-05-24 13:24:21 -04:00
Michael Dusan
75cd37b8f7 dragonfly: pass zig build test 2021-05-24 10:24:41 -04:00
Andrew Kelley
55811d8dac stage2: introduce clangAssemblerSupportsMcpuArg
Clang has a completely inconsistent CLI for its integrated assembler for
each target architecture. For x86_64, for example, it does not accept
an -mcpu parameter, and emits "warning: unused parameter". However, for
ARM, -mcpu is needed in order to properly lower assembly to machine code
instructions (see new standalone test case provided thanks to @g-w1).

This is a compromise between
b8f85a805b and
afb9f695b1.
2021-05-23 21:51:10 -07:00
Andrew Kelley
609207801a make "gnu" (mingw-w64) the default C ABI on Windows
Closes #6565
2021-05-24 00:13:54 -04:00
Andrew Kelley
8fa6ca6daa Merge pull request #8879 from squeek502/dot-and-dotdot-test
Add . and .. tests for std.fs functions
2021-05-23 23:26:05 -04:00
Michael Dusan
b3e4832240 housekeeping: remove pub from ccPrintFileName()
- this was inadvertently made public while iterating on #8730
2021-05-23 19:45:05 -04:00
Ryan Liptak
78019452f7 Add updateFile to . and .. fs tests 2021-05-23 16:35:31 -07:00
Andrew Kelley
b8f85a805b Revert "stage2: add support for zig cc assembler -mcpu option"
This reverts commit afb9f695b1.

I don't think this was ever actually verified to fix the thing it
purported to, and it started causing warnings for unused command line
parameters.
2021-05-23 16:32:22 -07:00
Ryan Liptak
1bc0df7250 Add . and .. tests for std.fs functions
These tests check that . and .. are able to be handled by the std.fs functions. Before #7664, these tests would have failed on Windows.

Closes #4659
2021-05-23 16:22:27 -07:00
Andrew Kelley
ae01c65a58 stage2: fix reference to musl arch name
Also rename musl.archMuslName to musl.archName.

Fixes a merge conflict from #8730 and #8837
2021-05-23 13:32:52 -07:00
Michael Dusan
0f26120377 overhaul elf csu (c-runtime startup) logic
- more support for linux, android, freebsd, netbsd, openbsd, dragonfly
- centralize musl utils; musl logic is no longer intertwined with csu
- fix musl compilation to build crti/crtn for full archs list
- fix openbsd to support `zig build-lib -dynamic`
- initial dragonfly linking success (with a warning)

ancillary:

- fix emutls (openbsd) tests to use `try`
2021-05-23 15:38:57 -04:00
Daniele Cocca
44e480aa2c translate_c: remove unused WriteFileStep import 2021-05-23 14:35:19 -04:00
xavier
a6e65f3a0e keep statically linked libc++ symbols hidden. 2021-05-23 19:58:38 +02:00
xavier
40d8518253 apply -flto and -ffunction-sections when compiling libc++ 2021-05-23 19:58:26 +02:00
Evan Haas
d321a4b765 translate-c: Translate FnDecl's that appear within functions 2021-05-23 15:42:36 +03:00
joachimschmidt557
e8236551ab stage2: Move BlockData out of ir.Inst.Block 2021-05-22 21:15:25 -04:00
Andrew Kelley
1c636e2564 Merge pull request #8844 from ifreund/inline
Support inline keyword as well as callconv(.Inline)
2021-05-22 20:56:30 -04:00
jacob gw
9baf891772 stage2: astgen error for return or try in defer block 2021-05-22 20:54:14 -04:00
Sébastien Marie
ceacb7d247 openbsd: complete kqueue(2) constant definitions 2021-05-22 20:52:44 -04:00
Isaac Freund
b2126d3345 stage2: only pass -lm -lc -ldl for android libc
The other libc components are not available on android.
2021-05-22 20:52:14 -04:00
Sobeston
742d588b3a std.os: munmap takes a const pointer 2021-05-22 20:51:53 -04:00
Matthew Borkowski
d7bf4f8070 fix Boyer-Moore-Horspool algorithm in indexOfPos and lastIndexOf when element type is larger than a byte 2021-05-22 20:51:17 -04:00
Jakub Konka
8c87a981f1 cc,wasi: force isysroot to / 2021-05-22 20:50:06 -04:00
Andrew Kelley
b750e074c6 stage2: rework astgen command into zig ast-check
This addresses the use case of quickly reporting AstGen compile errors
for a file, for use with an IDE for example.

 * Rename from `zig asgen` to `zig ast-check`
 * It is now a command always available; not only in debug builds.
 * Give it usage text and proper CLI parsing.
 * Support reading from stdin when no positional arg is provided.
 * `-t` flag makes it print textual ZIR. Without this flag, it only
   provides compile errors.
 * Support `--color` parameter to override the tty detection

closes #8871
2021-05-22 17:23:16 -07:00
Andrew Kelley
51701fb2da stage2: omit printing source lines in compile errors
when configured to not use tty awareness
2021-05-22 17:17:32 -07:00
Andrew Kelley
63aabbbba7 Merge pull request #8852 from Snektron/spirv
SPIR-V: More codegen
2021-05-22 18:20:20 -04:00
Andrew Kelley
7cd9b30e0a Merge pull request #7664 from marler8997/fixWindowsPaths
implement nt path conversion for windows
2021-05-22 17:58:59 -04:00
Andrew Kelley
79dee75b1c stage2: rename ir.zig to air.zig
We've settled on the nomenclature for the artifacts the compiler
pipeline produces:

1. Tokens
2. AST (Abstract Syntax Tree)
3. ZIR (Zig Intermediate Representation)
4. AIR (Analyzed Intermediate Representation)
5. Machine Code

Renaming `ir` identifiers to `air` will come with the inevitable
air-memory-layout branch that I plan to start after the 0.8.0 release.
2021-05-22 14:29:16 -07:00
Jakub Konka
9d311e9960 Merge pull request #8857 from ziglang/cc-wasm-ar
wasm: produce static lib by default and rename produced object files to simply .o from .o.wasm
2021-05-22 16:13:47 +02:00
Jakub Konka
2b0d322ea0 zld: permit system static libs
This commits permits passing in static archives using the system
lib flag `-la`. With this commit, `zig ld` will now look firstly for
a dynamic library (which always takes precedence), and will fall back
on `liba.a` if the dylib is not found. The static archive is searched
for in the system lib search dirs like the dylibs.
2021-05-22 16:12:45 +02:00
Robin Voetter
cba97e4773 SPIR-V: Make functions which always return a null result return void instead 2021-05-22 16:11:56 +02:00
Robin Voetter
228f71fa0c SPIR-V: Generate locals at the start of a function 2021-05-22 16:11:56 +02:00
Robin Voetter
6634abfd26 SPIR-V: Debug line info/source info 2021-05-22 16:11:56 +02:00
Robin Voetter
e3be1a1e88 SPIR-V: DeclGen constructor/destructor 2021-05-22 16:11:56 +02:00
Robin Voetter
46184ab85e SPIR-V: branching 2021-05-22 16:11:56 +02:00
Robin Voetter
5edc5f9730 SPIR-V: Pass source location to genType and genConstant for better error reporting 2021-05-22 16:11:56 +02:00
Robin Voetter
63d0576f1c SPIR-V: Preliminary alloc/store/load generation 2021-05-22 16:11:56 +02:00
Robin Voetter
6a121d9ccd SPIR-V: Split out genCmp from genBinOp 2021-05-22 16:11:56 +02:00
Robin Voetter
b8444d2c51 SPIR-V: Preliminary integer constant encoding 2021-05-22 16:11:56 +02:00
Robin Voetter
c190b2ff83 SPIR-V: ResultId and Word aliases to improve code clarity 2021-05-22 16:11:56 +02:00
Robin Voetter
9ddd7f4a60 SPIR-V: Put types in SPIRVModule, some general restructuring 2021-05-22 16:11:56 +02:00
Robin Voetter
bcda3c5b82 SPIR-V: Use Value.toFloat instead of switching on value tag when generating float constants 2021-05-22 16:11:56 +02:00
Matthew Borkowski
f4101c1153 fix accidental quadratic dependence on haystack length in replace and replacementSize (#8859) 2021-05-22 10:55:28 +02:00
Jakub Konka
bd325d1bd9 wasm: fix object extension to standard .o from .o.wasm
This should offer more compatibility with external tooling when
cross-compiling to wasm with zig.
2021-05-21 22:29:36 +02:00
Jakub Konka
fbd96907c9 wasm: build static archive unless -dynamic specified
This matches the behaviour for other targets in that

```
zig build-lib math.zig -target wasm32-freestanding
```

produces now `libmath.a` while

```
zig build-lib math.zig -dynamic -target wasm32-freestanding
```

is required to create a loadable Wasm module.
2021-05-21 20:24:13 +02:00
Jonathan Marler
b0116afd8a handle relative paths with too many ".." 2021-05-21 01:29:40 -06:00
Jakub Konka
4b69bd61e4 Merge pull request #8837 from ziglang/cc-wasm32-wasi
cc,wasi: ship WASI libc and autobuild it when needed
2021-05-21 09:04:16 +02:00
Andrew Kelley
0267abfe9b Merge pull request #8847 from Luukdegram/wasm-struct-switch
stage2: wasm - Structs and switch support
2021-05-20 18:55:49 -04:00
mason1920
884547f177 Const correct GUID parameter of getInfo and setInfo 2021-05-20 18:53:59 -04:00
Andrew Kelley
495e996169 Merge pull request #8776 from notviri/windows-wm-constants
fix & add some Win32 window message constants
2021-05-20 18:51:45 -04:00
Matthew Borkowski
510f858143 fix calculation of max_io_bits in PackedIntIo 2021-05-20 18:47:16 -04:00
Andrew Kelley
3845c264a6 stage2: fix compile error rendering for hard tabs
render them as 1 space instead. This fixes the column caret.
2021-05-20 15:20:27 -07:00
Jonathan Marler
59de5d0350 add the openDir cwd parent test 2021-05-20 14:00:41 -06:00
Jonathan Marler
a72ad61cd4 have collapseRepeats return slice intead of just len 2021-05-20 14:00:41 -06:00
Jonathan Marler
666584067a implement nt path conversion for windows 2021-05-20 14:00:40 -06:00
Isaac Freund
563ea60a86 translate-c: use inline keyword instead of callconv(.Inline) 2021-05-20 21:59:46 +02:00
Andrew Kelley
34d0542a53 Merge pull request #8695 from Bxil/socket
std.os: WSAStartup is now called upon socket creation when needed
2021-05-20 15:31:22 -04:00
Andrew Kelley
61850f8883 std: Windows: WSASocketW ensures WSAStartup
When WSASocketW gets WSANOTINITIALISED, now it will lock a mutex to
safely call WSAStartup and then try again one time.

This implementation:
 * Does not use recursion
 * Contains a detailed doc comment explaining why things are how they are
 * Is careful about which errors are surfaced in the respective error
   sets. `std.os.socket` intentionally does not have "not initialised"
   as one of the possible errors.
2021-05-20 12:28:30 -07:00
Bxil
85c2ffc9ba std.os: WSAStartup is now called upon socket creation when needed 2021-05-20 11:22:55 -07:00
Andrew Kelley
df56bf94a2 Merge pull request #8789 from Luukdegram/wasm-enum
stage2: wasm backend - Enums
2021-05-20 14:03:54 -04:00
Luuk de Gram
0ac56e7f3a Add test cases for switches 2021-05-20 19:59:37 +02:00
Isaac Freund
5b850d5c92 Run zig fmt on src/ and lib/std/
This replaces callconv(.Inline) with the more idiomatic inline keyword.
2021-05-20 17:14:18 +02:00
Isaac Freund
4a582734fd zig fmt: replace callconv(.Inline) with the inline keyword 2021-05-20 17:13:47 +02:00
Jakub Konka
b63c92f0b9 cc,wasi: do not add stack protector 2021-05-20 16:54:00 +02:00
Jakub Konka
3a5d0f7700 wasm: link dynamically by default when targeting wasm
This matches the behaviour of other languages and leaves us
the ability to create actual static Wasm archives with

```
zig build-lib -static some.zig
```

which can then be combined with other Wasm object files and linked
into either a Wasm lib or executable using `wasm-ld`.

Update langref to reflect the fact we now ship WASI libc.
2021-05-20 16:54:00 +02:00
Jakub Konka
f291b8b9bc cc,wasi: remove unused headers and sources 2021-05-20 16:54:00 +02:00
Jakub Konka
6d5002028a cc,wasi: link compiled WASI libc with wasm-ld 2021-05-20 16:54:00 +02:00
Jakub Konka
f102a5800c cc,wasi: compile all WASI libc objects 2021-05-20 16:54:00 +02:00
Jakub Konka
60d8779eae cc,wasi: add source file paths to wasi_libc.zig 2021-05-20 16:54:00 +02:00
Jakub Konka
7b74de7d71 wasi,cc: fix naming and add stubs for building
Rename include dir to match the convention:
  from `wasm32-wasi` to `wasm-wasi-musl`

Add building stubs which will be used to build and cache WASI
libc sysroot.
2021-05-20 16:54:00 +02:00
Jakub Konka
782cfedaf6 cc,wasi: add wasi-libc source 2021-05-20 16:54:00 +02:00
Jakub Konka
a901d44b4e cc,wasi: add wasi libc headers 2021-05-20 16:53:59 +02:00
Jakub Konka
b09936d728 Merge pull request #8842 from LemonBoy/thinko
Some TLCSPRNG fixes
2021-05-20 16:53:24 +02:00
Luuk de Gram
f8d0501f50 Also support multi-prong branches 2021-05-20 16:21:11 +02:00
LemonBoy
ec9a44b2a5 std: Make atfork handler more robust
The atfork handler is executed even when fork()-ing threads that have
never initialized their local csprng. Handle this case gracefully
instead of raising a runtime error.

Fixes #8841
2021-05-20 15:28:59 +02:00
LemonBoy
abfe7f96dd std: Call pthread_atfork only once
Some libc implementations (glib) deduplicate identical hooks, others
(musl, macos) do not and blindly append them to an internal list.
Ensure there's only a single call to pthread_atfork to prevent unbounded
memory use when lots of threads/forks are used.
2021-05-20 15:26:17 +02:00
Isaac Freund
3fd8ac092e stage2: support inline keyword on function decls
This is an alternative to callconv(.Inline). Using an inline keyword
as well as an explicit callconv() is a compile error.
2021-05-20 14:54:44 +02:00
Isaac Freund
569525f03e stage1: support inline keyword on function decls
This is an alternative to callconv(.Inline). Using an inline keyword
as well as an explicit callconv() is a compile error.
2021-05-20 14:54:44 +02:00
LemonBoy
992c02ab95 std: Fix error in tlcsprng init sequence
The fallback case was actually switched with the success one.
2021-05-20 14:43:04 +02:00
Luuk de Gram
81d8fe7558 stage2 wasm: Support basic switches
- Adds support for single branches
- Allows both enums and integers
- Supports 'else' branch
2021-05-20 14:21:02 +02:00
Luuk de Gram
87a9c6946d wasm backend: implement multi_value for WValue
This allows us to differentiate between regular locals and variables that create multiple locals
on the stack such as optionals and structs.
Now `struct_a = struct_b;` works and only updates a reference, rather than update all local's values.

Also created more test cases to test against this.
2021-05-20 09:25:02 +02:00
Andrew Kelley
9910bfa6d8 ci: use a different ssh private key to deploy the website
This changes the deploy key to a different one on www.ziglang.org so
that we can test notifications.
2021-05-19 21:36:48 -07:00
Andrew Kelley
a8eac0cf07 stage2 test harness: show source file name
Also support specifying source file name in compile error test cases.

closes #8829
2021-05-19 20:59:06 -07:00
Andrew Kelley
bfd051a53c stage2: use c_allocator not raw_c_allocator
when the raw C allocator alignment is not sufficient.

closes #8835
2021-05-19 10:26:50 -07:00
Evan Haas
1273bc277f translate-c: add support for __cleanup__ attribute
Use a `defer` statement to implement the C __cleanup__ attribute.

See https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
2021-05-19 12:12:18 +03:00
Sébastien Marie
28a89b9ebc openbsd: convert builtin.arch to builtin.target.cpu.arch 2021-05-19 10:55:21 +02:00
Luuk de Gram
6962647862 Do not create a local for the struct itself + test cases 2021-05-19 10:37:44 +02:00
Luuk de Gram
ac5fd47e2e Initial support for structs in wasm backend
- Creates a 'local' for the struct itself and each field
- The index of the local is calculated from the struct's local index + field index
2021-05-19 10:37:44 +02:00
Luuk de Gram
141a0cbb5a Explicit return & more complex wasm enum test
- When returning within a block, we must use an explicit return opcode. For now always emit the opcode when calling return, rather than using implicit return statements.
- Also added a more comprehensive test case to test for enum values using conditions
2021-05-19 10:35:45 +02:00
Andrew Kelley
22f51f2f7d Merge pull request #8667 from sagehane/nixos
std.zig: handle -frandom-seed in NIX_CFLAGS_COMPILE
2021-05-19 03:28:12 -04:00
Luuk de Gram
9ddede2950 Add enum test case for wasm backend 2021-05-19 08:59:11 +02:00
Luuk de Gram
b22e22ef55 wasm backend - Initial enum support
- This adds support for enum values using field indexes
- EmitConstant's signature was changed so it's easier to recursively call it using a different type (enum -> int type).
- Implemented initial support for bitcast which for now just returns the `WValue` of the operand.
2021-05-19 08:59:08 +02:00
Isaac Freund
1d6c804b29 stage2: only default to linking system libc if linking system libs
We do need to link the system libc if linking system libraries as
they may potentially be compiled against e.g. a newer glibc version
than zig can provide. However if not linking system libraries, using
the zig provided libc is more reliable as it does not depend on any
quirks of the host system or being able to invoke the system cc to
find include dirs.
2021-05-19 01:22:36 -04:00
Andrew Kelley
8861ee18f7 std: add android __SIZEOF_PTHREAD_MUTEX_T
closes #8384
2021-05-18 21:08:41 -07:00
Andrew Kelley
6435750c99 Merge pull request #8554 from ziglang/stage2-whole-file-astgen
Stage2 whole file astgen
2021-05-18 20:20:46 -04:00
Andrew Kelley
667236668f build.zig: blank out "*test.zig" files instead of omit
Now that `@import` of a non-existent file name is a compile error, the
Zig installation needs to include files that end with test.zig. However
we still want to avoid bloat in the installation size, so we blank them
out instead of omitting them entirely.

Now AstGen of the full standard library can complete successfully on a
Zig installation rather than erroring out with file not found.
2021-05-18 17:18:42 -07:00
Andrew Kelley
2c12f5f55b stage2 tests: fix missing 'pub' in one of the test cases 2021-05-18 12:53:23 -07:00
Andrew Kelley
a9cd9b021b Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
I want the updated Drone CI stuff to get the CI green.
2021-05-18 12:37:03 -07:00
Andrew Kelley
ab8f8465a3 stage2: fix deletion of Decls that get re-referenced
When scanDecls happens, we create stub Decl objects that
have not been semantically analyzed. When they get referenced,
they get semantically analyzed.

Before this commit, when they got unreferenced, they were completely
deleted, including deleted from the containing Namespace.

However, if the update did not cause the containing Namespace to get
deleted, for example, if `std.builtin.ExportOptions` is no longer
referenced, but `std.builtin` is still referenced, and then `ExportOptions`
gets referenced again, the Namespace would be incorrectly missing the
Decl, so we get an incorrect "no such member" error.

The solution is to, when dealing with a no longer referenced Decl
objects during an update, clear them to the state they would be in
on a fresh scanDecl, rather than completely deleting them.
2021-05-18 12:35:36 -07:00
Andrew Kelley
d228d86059 ci: drone: refresh docker image with latest alpine
hopefully resolves the failures we've been seeing recently
2021-05-18 11:29:14 -07:00
Andrew Kelley
4187008b5e std: update freebsd bits to new builtin 2021-05-18 10:49:33 -07:00
Jakub Konka
7588fcdd2a Merge pull request #8806 from ziglang/zld-link-shared
zig ld: add preliminary mechanism for linking dylibs
2021-05-18 11:04:06 +02:00
Jakub Konka
cb45c5521a zld: refactor warnings 2021-05-18 09:28:00 +02:00
Jakub Konka
daaec68aec zld: apply @mikdusan's suggestions
Library search paths now should be closer to what ld64 does.
Also, cwd now has to be specified explicitly to be considered.
2021-05-18 09:28:00 +02:00
Jakub Konka
1dac5f5214 zld: parse dylibs as positionals
* add preliminary rpath support
* enable shared_library test on x86_64 macOS
2021-05-18 09:28:00 +02:00
Jakub Konka
ca772735c3 zld: refactor order of searching for the dylibs
Current assumed order is:
* cwd
* `self.base.options.lib_dirs`
* finally, if `self.base.options.syslibroot` is defined,
  `self.base.options.lib_dirs` prefixed with syslibroot
2021-05-18 09:28:00 +02:00
Jakub Konka
73c015b956 zld: parse dylib id 2021-05-18 09:28:00 +02:00
Jakub Konka
17b2588598 zld: refactor out logic for dylib LC creation 2021-05-18 09:28:00 +02:00
Jakub Konka
138cecc028 zld: add prelim way of linking dylibs
The support is minimalistic in the sense that we only support actual
dylib files and not stubs/tbds yet, and we also don't support re-exports
just yet.
2021-05-18 09:28:00 +02:00
Evan Haas
35c694d614 translate-c: Demote initialization of opaque types
This fixes a segfault in translate-c that would previously occur when
initializing structs with unnamed bitfields, due to a failed assertion in
`transInitListExprRecord`. Unnamed bitfields do not have initializers,
so `transInitListExprRecord` erroneously assumes that `init_count` equals
the number of fields in the record.

Since attempting to initialize an opaque type is a syntax error in Zig,
we can just demote any attempts to initialize them.
2021-05-18 09:04:19 +03:00
Andrew Kelley
93dbf30dcf std.fmt: fix regressions from master
A previous commit from this branch incorrectly changed the usage of
`comptime` keyword, and broke the std lib tests. This commit adds
`comptime` to a few function calls, correcting the behavior.
2021-05-17 19:53:46 -07:00
Andrew Kelley
615d45da77 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * src/codegen/spirv.zig
 * src/link/SpirV.zig

We're going to want to improve the stage2 test harness to print
the source file name when a compile error occurs otherwise std lib
contributors are going to see some confusing CI failures when they cause
stage2 AstGen compile errors.
2021-05-17 19:30:38 -07:00
Andrew Kelley
1d3f76bbda stage2: skip recursion test on some hosts
In order for this test to pass, the host linking/start code needs to
support explicitly setting the stack size. Zig defaults to 16 MiB stack
size, which is enough to pass the test in Debug builds, however, most
operating systems do not honor the stack size we request for and give a
smaller amount.

Eventually the goal is to pass this test on all hosts.
2021-05-17 19:14:13 -07:00
Andrew Kelley
1d808d0dd2 stage2: fix crash in switch compile error
when the AST for the switch has never been loaded
2021-05-17 19:11:11 -07:00
Andrew Kelley
0dd0c9620d Merge pull request #8796 from Snektron/spirv
SPIR-V: Codegen basis
2021-05-17 21:25:02 -04:00
Andrew Kelley
67f5a28257 Sema: use a hash map for ZIR->AIR mapping
Previously, ZIR was per-function so we could simply allocate a slice for
all ZIR instructions. However now ZIR is whole-file, so we need a sparse
mapping of ZIR to AIR instructions in order to not waste memory.
2021-05-17 17:39:52 -07:00
Andrew Kelley
5cacc446c4 stage2: update @import("builtin") API usage 2021-05-17 17:39:26 -07:00
Andrew Kelley
98a28ece0b remove separate issues from my branch todo file 2021-05-17 16:09:39 -07:00
Andrew Kelley
910f67f77b behavior tests: re-enable commented out test
Not sure why it was failing, also not sure why it started passing again
2021-05-17 16:09:20 -07:00
Andrew Kelley
731c35f15a stage2: get rid of NameHash
Previously, stage2 used a global decl_table for all Decl objects, keyed
by a 16-byte name hash that was hopefully unique. Now, there is a tree
of Namespace objects that own their named Decl objects.
2021-05-17 16:09:20 -07:00
Andrew Kelley
3d99fb3352 stage2: get rid of DeclRef 2021-05-17 16:09:20 -07:00
Andrew Kelley
d5e894a9a7 stage2: get rid of failed_root_src_file 2021-05-17 16:09:20 -07:00
Andrew Kelley
ab6b0ad8a4 test runner: prepare stage2 workaround
This provides a simpler test runner that exercises fewer language
features so that we can get to the point faster where `zig test` works
for stage2.
2021-05-17 16:09:20 -07:00
Andrew Kelley
8a7a07f30d stage2: test cases take advantage of pub fn main support 2021-05-17 16:09:20 -07:00
Andrew Kelley
83677074f9 std: update regarding std.builtin reorganization
There are also some regressed std.fmt tests here and I haven't figured
out what's wrong yet.
2021-05-17 16:08:09 -07:00
Andrew Kelley
8cfa231104 update langref, compile-error tests, safety tests
for the std.builtin re-arranging
2021-05-17 15:25:27 -07:00
Andrew Kelley
f41892f736 std: @import("builtin").StackTrace -> std.builtin.StackTrace 2021-05-17 14:36:51 -07:00
Andrew Kelley
84fdeb47a3 compiler-rt: fix usage of builtin
In this branch std.builtin and `@import("builtin")` are rearranged, fix
a trivial compile error due to the conflict with master.
2021-05-17 14:18:30 -07:00
joachimschmidt557
65cee0b3fd stage2 ARM: correct spilling in genArmMul as well 2021-05-17 17:18:01 -04:00
LemonBoy
b7eab32f42 std: Allocate tlscsprng memory as needed
Let mmap allocate a block of memory that's wide enough to use with
MADV_WIPEONFORK, madvise granularity is the current system page size
(using a static buffer of mem.page_size bytes would be wrong, that's the
minimum page size).

As a result, we don't zero some random chunk of memory every time we
fork the process.

Fixes #7609
2021-05-17 17:16:38 -04:00
LemonBoy
fe1a166589 translate-c: Add @truncate where needed
Make getLimitedValue API much easier to use with zig.
Fixes the compilation on 32bit hosts.
2021-05-17 17:15:22 -04:00
Andrew Kelley
23fd15fd76 link/Elf: remove unintended link again libunwind
This was a merge conflict with master branch. The logic for linking
libunwind is already handled above.
2021-05-17 13:56:17 -07:00
Andrew Kelley
8405d6f7e2 link/MachO: bring in some of the Elf logic
There was missing incremental compilation logic in the MachO linker
code, causing test failures. With this logic ported over from the
corresponding ELF logic, tests pass again.
2021-05-17 13:46:54 -07:00
Andrew Kelley
3697022a41 stage2: avoid calling freeDecl when hasCodeGenBits == false
Previously the frontend incorrectly called freeDecl for structs, which
never got allocateDecl called for them. There was simply a missing check
for hasCodeGenBits().
2021-05-17 13:44:20 -07:00
aiz
5414bd48ed std.math.Complex: Change new() to init() 2021-05-17 21:57:51 +02:00
Andrew Kelley
d839835273 stage2: add some debug logs for when link functions are called 2021-05-17 11:33:21 -07:00
Michael Dusan
04d95ea419 ci linux: bump qemu-5.2.0.1
- apply patch for qemu-user syscall do_sendrecvmsg_locked
- see #8750
2021-05-17 12:06:25 -04:00
Aiz672
8467373bb8 Remove isIntegerNumber and isFloatingNumber 2021-05-17 08:41:44 +03:00
Andrew Kelley
751bb12a96 stage2: fix error message coloring
After 7a4b53fdee, bold no longer changes
the color back, so we need an extra reset.
2021-05-16 14:31:55 -07:00
Andrew Kelley
f4ee46e839 MachO/DebugSymbols: fix debug line offset
In c8b78706b7 I incorrectly made it be the
line offset from Decl to function lbrace; it needed to be line offset
from lbrace to rbrace.
2021-05-16 14:20:51 -07:00
Jonathan Marler
5042a47682 add missing EBADF error code for openat 2021-05-16 22:36:50 +02:00
Robin Voetter
880473dc3f SPIR-V: Unary not operation 2021-05-16 14:55:09 +02:00
Robin Voetter
489b3ef7d4 SPIR-V: bool binary operations 2021-05-16 14:52:11 +02:00
Robin Voetter
585122b1ac SPIR-V: comparison and equality operations 2021-05-16 14:46:58 +02:00
Robin Voetter
f14000c7e1 SPIR-V: More bitwise binary operations 2021-05-16 14:20:18 +02:00
Robin Voetter
4735e95d16 SPIR-V: More binary operations 2021-05-16 14:20:12 +02:00
Robin Voetter
10678af876 SPIR-V: genBinOp setup 2021-05-16 14:13:23 +02:00
Robin Voetter
ae2e21639a SPIR-V: Some initial floating point constant generation 2021-05-16 14:13:23 +02:00
Robin Voetter
cbf5280f54 SPIR-V: Some instructions + constant generation setup 2021-05-16 14:13:23 +02:00
Robin Voetter
da0cc732ea SPIR-V: Function parameter generation 2021-05-16 14:13:23 +02:00
Robin Voetter
074cb9f1da SPIR-V: OpFunction/OpFunctionEnd generation 2021-05-16 14:13:23 +02:00
Robin Voetter
4403f3598a SPIR-V: Proper floating point type generation 2021-05-16 14:13:23 +02:00
Robin Voetter
38cdfebad3 SPIR-V: Function prototype generation 2021-05-16 14:13:23 +02:00
Robin Voetter
458c338aeb SPIR-V: Compute backing integer bits 2021-05-16 14:13:23 +02:00
Robin Voetter
de6df2bc12 SPIR-V: Restructure codegen a bit 2021-05-16 14:13:23 +02:00
Andrew Kelley
c8b78706b7 linker: update MachO DebugSymbols to use the new line/column Decl API 2021-05-16 00:04:16 -07:00
Andrew Kelley
ae04ec776d Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Need that _main -> main improvement
2021-05-16 00:00:36 -07:00
Jakub Konka
6461b95163 macho: fix DWARF in dSYM and sym naming more consistent
* Advance line and PC prior to ending sequence in debug line program
  for a fn_decl. This is equivalent to closing scope in the debugger
  and without it, the debugger will not map source-to-address info
  as a result will not print the source when breaking at a symbol.
* Fix debug aranges sentinels to be of the size as the actual tuple
  descriptor (assuming segment selector to be ommitted). In summary,
  the sentinels were 32bit 0s, whereas they ought to be 64bit 0s.
* Make naming of symbols in the binary more consistent by prefixing
  each symbol name with an underscore '_'.
2021-05-16 08:12:29 +02:00
Andrew Kelley
9a95478c62 cmake: remove deleted file
This should have been part of 07606d12da
2021-05-15 21:46:36 -07:00
Andrew Kelley
597082adf4 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * src/Compilation.zig
 * src/codegen/spirv/spec.zig
 * src/link/SpirV.zig
 * test/stage2/darwin.zig
   - this one might be problematic; start.zig looks for `main` in the
     root source file, not `_main`. Not sure why there is an underscore
     there in master branch.
2021-05-15 21:44:38 -07:00
Andrew Kelley
07606d12da stage2: remove SPU Mark II backend
As it stands, the backend is incomplete, and there is no active contributor,
making it dead weight.

However, anyone is free to resurrect this backend at any time.
2021-05-15 21:25:42 -07:00
Andrew Kelley
7cd94d2123 stage2: omit Decl compile errors from failed AstGen files
Just like when new parse errors occur during an update, when new AstGen
errors occur during an update, we do not reveal compile errors for Decl
objects which are inside of a newly failed File. Once the File passes
AstGen successfully, it will be compared with the previously succeeded
ZIR and the saved Decl compile errors will be handled properly.
2021-05-15 21:20:06 -07:00
Andrew Kelley
dc036f5b6f codegen: implement const value rendering for ints <= 64 bits 2021-05-15 21:00:15 -07:00
Isaac Freund
d98e39fa68 stage2: make failure to find native libc verbose 2021-05-15 22:13:28 +02:00
LemonBoy
7a4b53fdee std: Avoid using white color when printing stacktraces
Use .bold instead of .white, the effect is the same for light-on-dark
terminals but greatly improves the readability for dark-on-light ones.

Closes #8761
2021-05-15 13:44:52 -04:00
viri
a994966870 remove range constants 2021-05-15 10:08:07 -06:00
Evan Haas
36da8d02b5 translate-c: translate global (file scope) assembly 2021-05-15 11:53:01 +03:00
Andrew Kelley
607abb5b14 std: dragonfly: fix duplicate definition of sockaddr_storage 2021-05-14 23:16:46 -07:00
Andrew Kelley
5769ed2d44 stage2: compile log stores node offset
Previously, compile log stored full SrcLoc info, which included absolute
AST node index. This becomes invalid after an incremental compilation.
To make it survive incremental compilation, store an offset from parent
Decl instead.
2021-05-14 23:10:38 -07:00
ZapAnton
e94bbc2237 std.testing: Added newline to the error messages
Added newline to every `std.debug.print` message.
Closes https://github.com/ziglang/zig/issues/8777
2021-05-15 01:27:39 -04:00
Andrew Kelley
1e5e664555 Merge pull request #8773 from ziglang/macho-dsym-path
macho: put dSYM bundle in zig-cache
2021-05-15 01:25:37 -04:00
Andrew Kelley
b4692c9a78 stage2: improve Decl dependency management
* Do not report export collision errors until the very end, because it
   is possible, during an update, for a new export to be added before an
   old one is semantically analyzed to be deleted. In such a case there
   should be no compile error.
   - Likewise we defer emitting exports until the end when we know for
     sure what will happen.
 * Sema: Fix not adding a Decl dependency on imported files.
 * Sema: Properly add Decl dependencies for all identifier and namespace
   lookups.
 * After semantic analysis for a Decl, if it is still marked as
   `in_progress`, change it to `dependency_failure` because if the Decl
   itself failed, it would have already been changed during the call to
   add the compile error.
2021-05-14 17:41:22 -07:00
viri
ca575f887c std: re-add weird undocumented Win32 constants
Got deleted. Not documented but sure.
2021-05-14 15:15:20 -06:00
viri
150a3ad6ff std: fix & add os.windows.user32 WM constants 2021-05-14 15:06:47 -06:00
Andrew Kelley
2dcec42b74 Merge pull request #8757 from Snektron/spirv-stuff
SPIR-V: Features + some other stuff
2021-05-14 17:02:51 -04:00
Jakub Konka
e93254412b macho: if strip is true, do not generate dSYM 2021-05-14 22:27:26 +02:00
viri
612ad779bb std: rework math.scalbn (#8733)
* std: fix overflow in math.scalbn32

* std: rewrite math.scalbn to be generic

* std: support f128 in math.isNormal

* std: enable f128 tests in math.scalbn
2021-05-14 16:15:53 -04:00
Andrew Kelley
114c6612cb Merge pull request #8764 from mattbork/json-usefirst
Fix duplicate_field_behavior UseFirst for parse in json.zig
2021-05-14 15:32:32 -04:00
Andrew Kelley
8f35c60b39 stage2: clarify logic of passing -integrated-as to clang
make it clear that the logic is only there to lower the amount of
noise on the clang command line.
2021-05-14 12:24:47 -07:00
LemonBoy
193a926301 stage2: Force Clang to use LLVM's assembler for SPARC targets
This change allows cross-compiling C code for SPARC, if you hit any
error with the internal assembler please open a ticket.
2021-05-14 15:22:22 -04:00
Andrew Kelley
826d833416 Merge pull request #8746 from koachan/sparc64-fixes
Various Linux/SPARCv9 fixes
2021-05-14 15:21:17 -04:00
LemonBoy
a52e472307 stage1: Widen non byte-sized atomic loads/stores
Checking if the size is a power of two is not enough, should also check
if it's a multiple of 8.

Closes #7976
2021-05-14 15:16:24 -04:00
Sahnvour
2d4d4baa42 std.hash_map: use 7 bits of metadata instead of 6
we only effectively need 1 control bit to represent 2 special states for
the metadata (free and tombstone)
this should reduce the number of actual element equality tests, but since
it's very low already, the impact is negligible
2021-05-14 15:15:55 -04:00
joachimschmidt557
8b4e91e18c stage2 register manager: clean up API and add more unit tests 2021-05-14 15:12:33 -04:00
LemonBoy
5185b5619a compiler-rt: Fix signedness mismatch in f128 mul impl
The `1 - shift` expression was computed using small unsigned types and
then casted to i32, producing either an underflow error or an incorrect
result.

Reported by `@notviri` in #8733
2021-05-14 15:11:54 -04:00
Robin Voetter
00428ac11b SPIR-V: Don't parse/render in gen_spirv_spec.zig, just emit in the right format 2021-05-14 19:49:32 +02:00
Robin Voetter
98dc8eb7d9 SPIR-V: Add generated SPIR-V features 2021-05-14 19:49:32 +02:00
Robin Voetter
4fe0a0b82b SPIR-V: SPIR-V feature generation tool
There is a lot left to be desired for this tool, as currently dependencies of extensions and dependencies
of capabilities on extensions are not included:
- There is no machine-readable definition of dependencies of extensions.
- A capability may depend on either of a multitude of extensions, which as of yet cannot be properly
  modelled in the target system.
2021-05-14 19:49:32 +02:00
Robin Voetter
25329ca852 SPIR-V: Split out registry from gen_spirv_spec.zig 2021-05-14 19:49:32 +02:00
Robin Voetter
42f2ff6ec9 SPIR-V: Re-generate spec.zig 2021-05-14 19:49:32 +02:00
Robin Voetter
6d1a4c8b1e SPIR-V: Adapt spec generator to new render api 2021-05-14 19:49:32 +02:00
Robin Voetter
d45e7dfc24 SPIR-V: Begin generating types 2021-05-14 19:49:32 +02:00
Robin Voetter
fa3afede58 SPIR-V: Set default ofmt to spirv 2021-05-14 19:49:32 +02:00
Jakub Konka
af9c6f2c69 macho: put dSYM bundle in zig-cache
Originally, I thought that the dSYM bundle has to reside side-by-side
with the binary it carries the debugging information for. However, it
turns out macOS is clever enough that it auto-searches for matching
dSYM bundle based on the embedded UUID of the binary.

To verify this, run this on your macOS:

```
mdfind "com_apple_xcode_dsym_uuids == <UUID from LC_UUID>"
```

See [here] for more info.

[here]: https://developer.apple.com/documentation/xcode/adding-identifiable-symbol-names-to-a-crash-report
2021-05-14 13:09:40 +02:00
Jakub Konka
00ebbe6df2 macho: require _main as global export in self-hosted
Clean up type and description flags generation for exports
in self-hosted MachO backend.
2021-05-14 13:08:56 +02:00
Jakub Konka
8eea5eddf7 macho: fix bug with symbol growth and realloc 2021-05-14 11:02:43 +02:00
Andrew Kelley
9958652d92 stage2: update test cases to improved source locations 2021-05-14 00:08:29 -07:00
Andrew Kelley
8344a50e1c AstGen: add compile error for decl name conflicts
* Remove the ability for GenZir parent Scope to be null. Now there is a
   Top Scope at the top.
 * Introduce Scope.Namespace to contain a table of decl names in order
   to emit a compile error for name conflicts.
 * Fix use of invalid memory when reporting compile errors by
   duplicating decl names into a temporary heap allocated buffer.
 * Fix memory leak in while and for loops, not cleaning up their
   labeled_breaks and store_to_block_ptr_list arrays.
 * Fix stage2 test cases because now the source location of redundant
   comptime keyword compile errors is improved.
 * Implement compile error for local variable shadowing declaration.
2021-05-13 23:51:22 -07:00
Andrew Kelley
93896ef860 std: dragonfly: fix duplicate definition of sockaddr_storage 2021-05-13 23:50:39 -07:00
Matthew Borkowski
11fd2aa767 fix logic for duplicate comptime fields and avoid freeing comptime fields in parseFree and parseInternal 2021-05-14 01:51:39 -04:00
Andrew Kelley
134853f106 stage2: fix tests expected values 2021-05-13 20:44:34 -07:00
Andrew Kelley
579694893e Sema: remove compile error for comptime function calls
Not sure why that was there - comptime function calls are already
implemented!
2021-05-13 20:09:25 -07:00
Andrew Kelley
2cee19ab21 CLI repl: "run" command handles cross compiled binaries
with an appropriate error message, and does not terminate the repl.
2021-05-13 20:08:35 -07:00
Andrew Kelley
a854795f52 link: fix memory leak of system_libs 2021-05-13 20:08:17 -07:00
Andrew Kelley
edab03bc22 link/MachO: fixes to debug symbols
commitDeclDebugInfo: stop trying to write length 0 debug info - avoids
hitting an error where zig tries to move the debug info section
unnecessarily, gets confused, and reports `error.InputOutput`.

The 2 pieces of code that looked at the source and tried to compute
source line offsets is now improved to match link/Elf - use the
line/column data stored in the Decl object to skip the costly scanning
of source bytes. No need to load Zig source code, AST, or tokens, when
we have the ZIR!
2021-05-13 20:05:41 -07:00
Andrew Kelley
826179bff4 stage2: -lunwind is handled specially
* `-lc++` now implies `-lc`.
 * `-lunwind` is now pulled out into a separate `link_libunwind` flag in
   the frontend driver code. This allows a project to request zig to
   provide libunwind even if the default situation that causes it to be
   implicitly added, is not active.
 * build.zig: ask for -lunwind when building the self-hosted compiler on
   Linux. Otherwise we get linker errors with unresolved symbols to
   libunwind.
2021-05-13 22:42:57 -04:00
Andrew Kelley
78632894da AstGen: fix elision of store_to_block_ptr for condbr 2021-05-13 17:56:01 -07:00
Andrew Kelley
e83cf6a454 Sema: detect and skip over elided instructions
It would be better if AstGen would actually omit these instructions
rather than only marking them as elided, but that can be solved
separately.
2021-05-13 16:50:27 -07:00
Andrew Kelley
76a259799d stage2: only build and link libunwind when linking libc++ 2021-05-13 17:40:39 -04:00
Andrew Kelley
173142cc36 Merge pull request #8611 from shachaf/precedence
parser: Use an operator precedence table
2021-05-13 17:40:03 -04:00
Jakub Konka
1b222cb1ff start.zig: export main with strong linkage
Unmarks `_main` as weak symbol making it global (the entire linked
program) in scope.
2021-05-13 17:24:32 -04:00
Jakub Konka
402264ab0e Add experimental Darling support for cross testing macOS
* for cross testing stage2 tests, we use `darling shell` command
  since the path to the tested binary is relative to cwd
* for the `zig test` command, we simply use `darling` since the
  path to the binary is absolute
2021-05-13 20:31:33 +02:00
Matthew Borkowski
cadb84b3ac fix duplicate_field_behavior UseFirst in json.zig 2021-05-13 09:43:55 -04:00
Matthew Borkowski
e902c19c0e std/json: Fix premature closing brace being considered valid JSON
return error from StreamingParser when reading closing brace when expecting value for an object key
2021-05-13 11:11:28 +02:00
Jakub Konka
4f71852c10 Merge branch 'streamline-stage2-build-script' 2021-05-13 08:24:46 +02:00
Jakub Konka
1aee896cae Merge branch 'master' into streamline-stage2-build-script 2021-05-13 08:24:21 +02:00
Andrew Kelley
b109daacdd stage2: fix test cases to add pub on exported _start fn
This way the start code respects them.
2021-05-12 23:17:24 -07:00
Jakub Konka
6c3050e3c3 macos: link static libc++ when building stage2
With this change, it is now possible to use zig-bootstrap as the
initial C/C++ compiler, and then build stage2 with the resultant
stage1 without the need to link any system libs!
2021-05-13 07:55:59 +02:00
Andrew Kelley
c102e13710 stage2: fix source location of Decl compile errors
In `Module.semaDecl`, the source location being used was double-relative
to the `Decl`, causing a crash when trying to compute byte offset for
the compile error.

Change the source location to node_offset = 0 since the scope being used
makes the source location relative to the Decl, which already has the
source node index populated.
2021-05-12 22:50:47 -07:00
Andrew Kelley
4b59f56434 stage2: build and provide libunwind when compiling for native libc
5ac91794cc made Zig link against the
system libc when targeting the native C ABI. However this made it stop
putting libunwind.a on the linker line when it needed to sometimes,
causing undefined symbols when linking against C++ code.
2021-05-12 22:29:21 -07:00
Andrew Kelley
a7aa3ca66c stage2: build and provide libunwind when compiling for native libc
5ac91794cc made Zig link against the
system libc when targeting the native C ABI. However this made it stop
putting libunwind.a on the linker line when it needed to sometimes,
causing undefined symbols when linking against C++ code.
2021-05-12 22:25:20 -07:00
Andrew Kelley
344dc0cc0f stage2: fix handling of "prev successful ZIR"
Before this change, the attempt to save the most recent successful ZIR
code only worked in some cases; this reworks the code to be more robust,
thereby fixing a crash when running the stage2 "enums" CBE test cases.
2021-05-12 22:02:44 -07:00
Isaac Freund
459c9f0535 stage2: fix build on OpenBSD/NetBSD
Apparently these systems do not provide libdl or librt.
2021-05-13 00:44:56 -04:00
Andrew Kelley
417b5b1daa std: fix redundant comptime keywords
caught by stage2 astgen
2021-05-12 20:44:05 -07:00
Andrew Kelley
1ab3dff846 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Need the latest commit which fixes std and behavior tests for cross
compiled glibcs.
2021-05-12 20:37:40 -07:00
Andrew Kelley
799d1f0d36 build system: fix wrong glibc dir passed to qemu for i386
Without this, and with `-Denable-qemu -Denable-foreign-glibc`,
i386-linux-gnu tests failed because the `-L` path passed to qemu
was "i386-linux-gnu" (nonexistent) rather than "i686-linux-gnu".

Fixes std lib and behavior tests when using these options to enable
test coverage with cross compiled glibcs.
2021-05-12 20:34:54 -07:00
Andrew Kelley
c9cc09a3bf Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux.zig
 * lib/std/os/windows/bits.zig
 * src/Module.zig
 * src/Sema.zig
 * test/stage2/test.zig

Mainly I wanted Jakub's new macOS code for respecting stack size, since
we now depend on it for debug builds able to pass one of the test cases
for recursive comptime function calls with `@setEvalBranchQuota`.

The conflicts were all trivial.
2021-05-12 16:41:20 -07:00
Koakuma
90a54f06e5 Add a comment to explain the alignment directive 2021-05-13 06:18:51 +07:00
Matthew Borkowski
40a47eae65 fix shrinkAndFree and remove shrinkRetainingCapacity in PriorityQueue and PriorityDequeue 2021-05-12 18:33:25 -04:00
Evan Haas
19aab5302c translate-c: Ensure extra_cflags are passed to clang
Additionally ensure that the Zig cache incorporates any extra cflags when
using translate-c.

Fixes the issue identified in #8662
2021-05-12 18:17:45 -04:00
Andrew Kelley
43da102920 Merge pull request #8698 from ifreund/scanZ
std/mem: add sliceTo(), deprecate spanZ(), lenZ()
2021-05-12 18:15:36 -04:00
LemonBoy
893a428656 stage2: Drop LLVM's host CPU detection method as fallback
The CPU detection code is nearly at feature parity, we do support
detecting the native CPU on Sparc systems and macos, our ARM/AArch64
model list is quite comprehensive and so is our PPC one.

The only missing pieces are:
- ARM32 detection on Darwin hosts (I don't think anybody is planning on
  running the compiler on a old-ass iPhone)
- s390x detection on Linux hosts, this can be easily added at a later
  stage.
2021-05-12 14:03:59 -04:00
Jakub Konka
7b77246289 macho: allow overriding stack size in binary 2021-05-12 19:25:26 +02:00
Koakuma
9e67c062c4 Add missing f128 compiler-rt shim 2021-05-12 20:13:29 +07:00
Michael Dusan
fb8527b289 azure: bump timeout for macos-arm64 2021-05-12 06:38:01 -04:00
Isaac Freund
cd7b5a3718 std/mem: add sliceTo(), deprecate spanZ(), lenZ()
The current spanZ() function will not scan for a 0 terminator if the
type is not 0 terminated. This encourages using 0 terminated array
types to bind C arrays which hold 0 terminated strings. However, this is
a big footgun as nothing in the C type system guarantees there to be a
0 terminator at the end of the array and if there is none this becomes
Illegal Behavior in Zig.

To solve this, deprecate spanZ() and lenZ(), adding a new sliceTo()
function that always scans for the given terminator even if the type is
not sentinel terminated.
2021-05-12 11:24:49 +02:00
Jakub Konka
53acb54fad Bump zig-bootstrap and wasmtime versions in linux CI (#8738)
* Bump zig-bootstrap and wasmtime versions in linux CI

* Revert wasm stage2 test fixup; point to issue
2021-05-12 09:56:55 +02:00
Koakuma
f24d0fbb07 Remove SPARC pthreadtypes-arch.h to match upstream glibc
This is only a temporary measure, we need to properly update the bundled glibc.
2021-05-12 14:54:13 +07:00
Koakuma
5dd6f9616e Fix linux dirent64 buffer align directive 2021-05-12 14:52:53 +07:00
LemonBoy
e260cfae85 stage2: Add CPU feature detection for macos
This is mostly meant to detect the current and future AArch64 core types
as the x86 part is already taken care of with OS-independent machinery.
2021-05-12 09:43:49 +02:00
Koakuma
9c07d30ef5 Fix crti/crtn path for SPARC 2021-05-12 14:23:28 +07:00
Koakuma
6e5330ee38 Define ENOTSUP for SPARC 2021-05-12 14:23:08 +07:00
Andrew Kelley
71afc30880 stage2: more Decl lifetime fixes
* File stores `root_decl: Decl` instead of `namespace: *Namespace`.
   This maps more cleanly to the actual ownership, since the `File` does
   own the root decl, but it does not directly own the `Namespace`.
 * `semaFile` completes the creation of the `Decl` even when semantic
   analysis fails. The `analysis` field of the `Decl` will contain the
   results of semantic analysis. This prevents cleaning up of memory
   still referenced by other Decl objects.
 * `semaDecl` sets `Struct.zir_index` of the root struct decl, which
   fixes use of undefined value in case the first update contained a ZIR
   compile error.
2021-05-11 23:20:22 -07:00
Andrew Kelley
1ab1a96f87 stage2: improve Decl lifetime management
* Compilation: iteration over the deletion_set only tries to delete the
   first one, relying on Decl destroy to remove itself from the deletion
   set.
 * link: `freeDecl` now has to handle the possibility of freeing a Decl
   that was never called with `allocateDeclIndexes`.
 * `deleteDecl` recursively iterates over a Decl's Namespace sub-Decl
   objects and calls `deleteDecl` on them.
   - Prevents Decl objects from being destroyed when they are still in
     `deletion_set`.
 * Sema: fix cleanup of anonymous Decl objects when an error occurs
   during semantic analysis.
 * tests: update test cases for fully qualified names
2021-05-11 22:12:36 -07:00
Michael Dusan
30ace64fc4 bsd: detect os version
- netbsd, dragonly: use sysctlbyname
- openbsd: use sysctl
- updated default semver ranges
2021-05-11 22:05:08 -04:00
Andrew Kelley
d7567c06fd Sema: implement duplicate enum tag compile error 2021-05-11 18:56:56 -07:00
Andrew Kelley
7873e4f588 stage2: lookupIdentifier can return error.AnalysisFailed
This avoids causing false positive compile errors when, for example, a
file had ZIR errors, and then code tried to look up a public decl from
the failed file.
2021-05-11 17:44:19 -07:00
Andrew Kelley
cbbc7cc8b1 stage2: better handling of file-level compile errors across updates
* `Module.File` now retains the most recent successful ZIR in the event
   that an update causes a ZIR compile error. This way Zig does not
   throw out useful semantic analysis results when an update temporarily
   introduces a ZIR compile error.
 * Semantic analysis of a File now unconditionally creates a Decl object
   for the File. The Decl object is marked as `file_failed` in case of
   File-level compile errors. This allows detecting of the File being
   outdated, and dependency tracking just like any other Decl.
2021-05-11 17:34:13 -07:00
Andrew Kelley
e3dd4dc91d Merge pull request #8737 from ifreund/link-system-libc
stage2: use system libc when targeting the native OS/ABI
2021-05-11 20:28:14 -04:00
Andrew Kelley
5d9fc11d18 stage2: update tests now that structs have fully qualified names 2021-05-11 14:51:54 -07:00
Andrew Kelley
a74632b50a C backend: fix emitting '$' in identifier names
This causes warnings from clang when compiled.
2021-05-11 14:51:21 -07:00
Andrew Kelley
fb39526159 AstGen: support emitting multiple compile errors 2021-05-11 14:51:08 -07:00
Andrew Kelley
bcf15e39e2 stage2: add owns_tv flag to Module.Decl
Decl objects need to know whether they are the owner of the Type/Value
associated with them, in order to decide whether to destroy the
associated Namespace, Fn, or Var when cleaning up.
2021-05-11 14:17:52 -07:00
Isaac Freund
e6881d4373 std/json: fix previous commit for std.testing changes 2021-05-11 23:09:25 +02:00
Matthew Borkowski
1b87d45494 fix a double free in parse when duplicate_field_behavior is UseLast and a leak in parse when allocating a single item 2021-05-11 22:54:02 +02:00
Isaac Freund
c036957521 std.meta.Elem: support all optional types 2021-05-11 22:22:21 +02:00
Isaac Freund
f8cf106fc9 ci: unset CC/CXX before make install on macos arm64
Having these set causes zig's native libc detection code to fail.
2021-05-11 21:30:13 +02:00
Isaac Freund
3b2c9ef828 stage2: link all libc components if using system libc 2021-05-11 21:30:13 +02:00
Isaac Freund
01e30002c5 stage2: error if requested glibc version too high
Falling back to the max provided glibc version is insufficient as
linking to shared objects compiled against the requested version
will fail.
2021-05-11 21:30:13 +02:00
Isaac Freund
5ac91794cc stage2: use system libc when targeting the native OS/ABI
Currently zig will always try to build its own libc and compile against
that. This of course makes sense for cross-compilation, but can cause
problems when targeting the native OS/ABI.

For example, if the system uses a newer glibc version than zig ships
zig will fall back to using the newest version it does ship. However
this causes linking system libraries to fail as they are built against a
different glibc version than the zig code is built against.

To remedy this, simply default to linking the system libc when targeting
the native OS/ABI.
2021-05-11 21:30:07 +02:00
Andrew Kelley
ace5714551 Merge pull request #8705 from LemonBoy/libc-fix
32bit glibc fixes
2021-05-11 15:15:00 -04:00
Andrew Kelley
c3d4733a00 test runner: avoid an "out of memory" error return trace entry
The long term solution to this will be #1923
2021-05-11 11:47:22 -07:00
Andrew Kelley
65d279bc05 test runner: print error return trace after failed test 2021-05-11 10:50:17 -07:00
LemonBoy
8bb58fb428 std: Fix offset param splitting for preadv/pwritev
The kernel interface expects the offset as a low+high pair even on BE
systems.
2021-05-11 15:49:53 +02:00
Matthew Borkowski
75ed835d08 fix AutoArrayHashMap's store_hash logic 2021-05-11 16:14:23 +03:00
LemonBoy
2bb8e1ff55 stage2: Change libc components' linking order
Use the same order as Clang (and, by extension, GCC) for the three most
important libc components: lm comes first, followed by lpthread and then
lc.
2021-05-11 12:43:58 +02:00
LemonBoy
780f510ac0 std: Fix fallocate offset type 2021-05-11 12:33:48 +02:00
LemonBoy
c065e12dbe std: Add more tests, fix broken code
It turns out that nothing in the test suite was exercising
preadv/pwritev and so the previous commits silently broke them.

Adding tests revealed readvAll and preadvAll were also broken and not
covered by any test.
2021-05-11 12:33:48 +02:00
LemonBoy
31f1cc9a0d std: Harmonize use of off_t between libc and Zig impls
Let's follow the libc/kernel convention and use an i64 for offsets, we
bitcast as needed and avoid the useless conditional casts.
2021-05-11 12:33:48 +02:00
LemonBoy
f4a05286d3 std: Fix cast that's sometimes invalid 2021-05-11 12:33:48 +02:00
LemonBoy
93f48189f1 test: Enable i386-linux-gnu test
This is needed to catch any possible problem with executables linking to
32bit glibc.
2021-05-11 12:33:48 +02:00
LemonBoy
679876ba72 c: Fix prototypes for bcmp and memcmp
They return c_int and not isize.
2021-05-11 12:33:47 +02:00
LemonBoy
a909db6aea std: Prefer 64bit libc functions where possible
While musl decided to hard-wire off_t to a 64bit quantity, glibc is much
older and defaults to 32bit offsets and offers some -64 suffixed
versions of I/O functions.

There's a weird mix-up of types: sometimes off_t is used, sometimes not,
sometimes it's defined as a signed quantity and sometimes as an unsigned
one, but we'll sort this problem later.
2021-05-11 12:33:47 +02:00
LemonBoy
28a9e4c4aa libc: Add workaround for #4926
This change was cherry-picked from an updated version of the sysdep
folder contents, we're still shipping an outdated and incomplete set of
files.
2021-05-11 12:33:47 +02:00
LemonBoy
ac546f56eb stage2: Allow building musl/glibc in thumb mode 2021-05-11 12:27:24 +02:00
LemonBoy
b288f8c9a6 stage2: Always link -lpthread when using system libc
This is required when cross-compiling glibc targets.
2021-05-11 12:27:24 +02:00
LemonBoy
65ee7909b9 stage2: Pass -mthumb when compiling C/C++ code
Apparently the Clang driver requires this flag and ignores the target
triple.
2021-05-11 12:27:24 +02:00
Andrew Kelley
dae22a0a1f stage2: struct, union, enum, opaque, error sets get better names
This commit takes advantage of the new "NameStrategy" that is exposed
in the ZIR in order to name Decls after their parent when asked to. This
makes the next failing test case pass.
2021-05-10 22:50:00 -07:00
Andrew Kelley
b9a099e83c stage2: type declarations ZIR encode AnonNameStrategy
which can be either parent, func, or anon. Here's the enum reproduced in
the commit message for convenience:

```zig
pub const NameStrategy = enum(u2) {
    /// Use the same name as the parent declaration name.
    /// e.g. `const Foo = struct {...};`.
    parent,
    /// Use the name of the currently executing comptime function call,
    /// with the current parameters. e.g. `ArrayList(i32)`.
    func,
    /// Create an anonymous name for this declaration.
    /// Like this: "ParentDeclName_struct_69"
    anon,
};
```

With this information in the ZIR, a future commit can improve the
names of structs, unions, enums, and opaques.

In order to accomplish this, the following ZIR instruction forms were
removed and replaced with Extended op codes:

 * struct_decl
 * struct_decl_packed
 * struct_decl_extern
 * union_decl
 * union_decl_packed
 * union_decl_extern
 * enum_decl
 * enum_decl_nonexhaustive

By being extended opcodes, one more u32 is needed, however we more than
make up for it by repurposing the 16 "small" bits to provide shorter
encodings for when decls_len == 0, fields_len == 0, a source node is not
provided, etc. There tends to be no downside, and in fact sometimes
upsides, to using an extended op code when there is a need for flag
bits, which is the case for all three of these. Likewise, the container
layout can be encoded in these bits rather than into the opcode.

The following 4 ZIR instructions were added, netting a total of 4 freed
up ZIR enum tags for future use:

 * opaque_decl_anon
 * opaque_decl_func
 * error_set_decl_anon
 * error_set_decl_func

This is so that opaques and error sets can have the same name hint as
structs, enums, and unions.

`std.builtin.ContainerLayout` gets an explicit integer tag type so that
it can be used inside packed structs.

This commit also makes `Module.Namespace` use a separate set for
anonymous decls, thus allowing anonymous decls to share the same
`Decl.name` as their owner `Decl` objects.
2021-05-10 21:34:43 -07:00
Andrew Kelley
9e72f31735 stage1: ignore enum ContainerLayout for comptime memory purposes
See #2115. The concept of `packed enum` and `extern enum` is
getting removed from the language.
2021-05-10 20:34:18 -07:00
Andrew Kelley
55d235dc38 Merge pull request #8711 from lithdew/master
std/os, x/os/socket: windows support, socket helpers, getpeername()
2021-05-10 19:00:53 -04:00
Andrew Kelley
2e4a48ef29 Merge pull request #8736 from ziglang/macos-zig-bootstrap
Use zig-bootstrap to build macOS binaries
2021-05-10 18:41:29 -04:00
jacob gw
24dfa61236 stage1: remove outdated error message regarding #447 2021-05-10 21:00:10 +02:00
xackus
8f8efcdd6e translate-c: fix typedefs with multiple names 2021-05-10 21:59:42 +03:00
Jakub Konka
b7a6a251a0 Tweak macos_arm64_script to use bootstrapped zig 2021-05-10 18:42:01 +02:00
Jakub Konka
603242fa86 Use zig-bootstrapped x86_64 macos compiler in CI 2021-05-10 13:55:48 +02:00
lithdew
0d0edd23a8 std/os: add missing sockaddr_storage defs 2021-05-10 19:22:31 +09:00
lithdew
e652595f2a std/os: fix sockaddr_storage padding size 2021-05-10 19:22:31 +09:00
lithdew
6d41e08664 x/os, os: fix setsockopt on windows, simplify Socket.setOption error set 2021-05-10 19:22:31 +09:00
lithdew
6cb6edb6f6 std/os/windows/ws2_32: add missing FIONBIO constant 2021-05-10 19:22:31 +09:00
lithdew
77f8a9ae22 x/os/socket, std/os/windows: implement loading winsock extensions
Implement loading Winsock extensions.

Add missing Winsock extension GUID's.

Implement readVectorized() for POSIX sockets and
readVectorized() / writeVectorized() for Windows
sockets.

Inverse how mixins are used to implement platform-independent syscalls
for the std.x.os.Socket abstraction. This cleans up the API as suggested
by @komuw.
2021-05-10 19:22:31 +09:00
lithdew
3d946ef5eb x/os, x/net, os:, fix typos/errors, add missing constants/docs
Add missing constants to ws2_32 such as SIO_BASE_HANDLE.

Made all declared constants in ws2_32 comptime_int, and fixed a few
broken constants (i.e. GUID's).

Fixed a few syscalls not having callconv(WINAPI) in ws2_32.

Fixed a typo in std.x.net.tcp.Client.

Removed unnecessary @alignCast's for socket addresses in
std.x.net.Socket.

Added a warning on using timeout methods for std.x.net.Socket.

Fixed compilation error spotted by CI in std.os that references
std.os.windows.ws2_32.SD_RECEIVE.

Renamed std.x.os.Socket.setOption()'s parameter `name: u32` to `code:
u32`.
2021-05-10 19:22:31 +09:00
Kenta Iwasaki
a24101be5b x/os/socket_posix.zig: make linger struct extern
Co-authored-by: LemonBoy <LemonBoy@users.noreply.github.com>
2021-05-10 19:22:31 +09:00
lithdew
e739b2b7d6 x/os/socket: use sockaddr_storage for accept() 2021-05-10 19:22:31 +09:00
lithdew
d3871af724 x/net/tcp, x/os/socket: tcp.Client.{Reader, Writer}
Only allow SOCK_STREAM (std.x.net.tcp.Client) sockets to have wrappers
for std.io.Reader and std.io.Writer provided, instead of Socket's in
general.
2021-05-10 19:22:31 +09:00
lithdew
d7b601b35e std/os, x/os/socket: windows support, socket helpers, getpeername()
Socket I/O methods such as read, readv, write, writev, send, recv,
sendmsg, recvmsg have been generalized to read(buf, flags), write(buf,
flags), readVectorized(vectors, flags), and writeVectorized(vectors,
flags). There is still some work left to be done abstracting both
readVectorized and writeVectorized properly across platforms, which is
work to be done in a future PR.

Support for setting the linger timeout of a socket, querying the remote
address of a socket, setting whether or not keep-alive messages are to
be sent through a connection-oriented socket periodically depending on
host operating system settings has been added.

`std.io.Reader` and `std.io.Writer` wrappers around `Socket` has been
implemented, which wrap around Socket.read(buf, flags) and
Socket.write(buf, flags). Both wrappers may be provided flags which are
passed to Socket.read / Socket.write accordingly.

Cross-platform support for `getpeername()` has been implemented.

Windows support for the new `std.x.os.Socket` has been implemented. To
accomplish this, a full refactor of `std.os.windows.ws2_32` has been
done to supply any missing definitions and constants based on
auto-generated Windows syscall bindings by @marler8997.

`std.x.net.TCP.Listener.setQuickACK` has been moved to
`std.x.net.TCP.Client.setQuickACK`.

Windows support for resolving the scope ID of an interface name
specified in an IPv6 address has been provided.

`sockaddr_storage` definitions have been provided for Windows, Linux,
and Darwin. `sockaddr_storage` is used to allocate space before any
socket addresses are queried via. calls such as accept(), getsockname(),
and getpeername().

Zig-friendly wrappers for GetQueuedCompletionStatusEx(), getpeername(),
SetConsoleCtrlHandler(), SetFileCompletionNotificationModes() syscalls
on Windows have been provided.

Socket.setOption() was provided to set the value of a socket option in
place of os.setsockopt. Socket.getOption() will be provided in a future
PR.

There is still further work to be done regarding querying socket option
values on Windows, which is to be done in a subsequent PR.
2021-05-10 19:22:31 +09:00
Jakub Konka
9c03b39d1e Merge pull request #8723 from jedisct1/init-stat
Initialize the Stat structure
2021-05-10 09:42:37 +02:00
Frank Denis
2d11967734 p256: properly handle neutral element & add AffineCoordinates struct (#8718)
Instead of multiple references to an anonymous structure to represent affine coordinates, add an actual `AffineCoordinates` structure.

Also properly handle the neutral element during coordinate conversion and fix mixed addition.

And comptime the small precomputation table for basepoint multiplication.
2021-05-09 18:20:43 +02:00
Frank Denis
c3675d9351 Shorten 2021-05-09 18:17:09 +02:00
Frank Denis
4e399ef62c Initialize the Stat structure
The system `stat` structure includes padding, and, on some
operating systems such as all BSDs, "spare" bytes at the end.

We can't reliably compare two `Stat` values if these are
uninitialized, while being later compared.

This is what was causing the `fstatat` test to fail on FreeBSD
since the update to LLVM 12. It was previously only passing by
accident.
2021-05-09 18:15:42 +02:00
Jakub Konka
f67e756211 zld: adjust signed displacement source target addr
Previously, I mistakenly assumed that offset of the relocation
is enough when calculating relative offset of the target from the
source target section base address in case of section-based relocs
on x86_64. While this is true for `__TEXT,__text` section which
always starts at 0x0 in object files, this is absolutely not true
for `__TEXT,__StaticInit` section which will have nonzero base
address hence resulting in incorrect displacement calculations for
SIGNED relocs.
2021-05-09 16:24:53 +02:00
Jakub Konka
15d6efecfb Merge pull request #8709 from joachimschmidt557/stage2-arm
stage2 ARM: Generate correct code when spilling registers
2021-05-09 14:16:40 +02:00
joachimschmidt557
f2a3368891 stage2 ARM: Add spill registers test 2021-05-09 08:48:58 +02:00
joachimschmidt557
d211dc37c8 stage2 ARM: Overhaul of genArmBinOp 2021-05-09 08:48:58 +02:00
Andrew Kelley
2299e5ff1d fix merge conflicts from previous commit
Any PRs merged after the one that made testing functions return errors
needs to get rebased!
2021-05-08 23:12:34 -07:00
Andrew Kelley
b88d381dec Merge pull request #8474 from gracefuu/grace/encode-instruction
stage2 x86_64: encoding helpers, fix bugs
2021-05-09 01:36:51 -04:00
Andrew Kelley
6361d7a928 stage2 test harness: report multiple failures
so you can debug more than one thing at a time
2021-05-08 16:11:07 -07:00
Andrew Kelley
5619ce2406 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * doc/langref.html.in
 * lib/std/enums.zig
 * lib/std/fmt.zig
 * lib/std/hash/auto_hash.zig
 * lib/std/math.zig
 * lib/std/mem.zig
 * lib/std/meta.zig
 * test/behavior/alignof.zig
 * test/behavior/bitcast.zig
 * test/behavior/bugs/1421.zig
 * test/behavior/cast.zig
 * test/behavior/ptrcast.zig
 * test/behavior/type_info.zig
 * test/behavior/vector.zig

Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
2021-05-08 14:45:21 -07:00
Andrew Kelley
5cd9afc6b6 stage2: fully qualified names and better anonymous names
* no more global atomic variable for anonymous decl indexes. Instead
   the Namespace decl table is used to figure out anonymous decl names.
   - This prepares for better multi-threaded semantic analysis in the
     future, with no contention on this global atomic integer.
 * implement fully qualified names for namespaces.
2021-05-08 14:34:30 -07:00
Andrew Kelley
67154d233e Merge pull request #8686 from Vexu/try
Allow tests to fail
2021-05-08 17:29:44 -04:00
Andrew Kelley
aa0352fad6 Sema: fix @setEvalBranchQuota incorrectly requiring a function body 2021-05-08 14:06:36 -07:00
Andrew Kelley
b98a753b52 AstGen: fix incorrect logic for adding implicit return instruction 2021-05-08 13:48:40 -07:00
Andrew Kelley
fed1c9c3ec link/MachO: fix --verbose-link ensureCapacity bug 2021-05-08 11:24:07 -07:00
Andrew Kelley
3d351c91d8 Type: fix abiAlignment calculation for unions 2021-05-08 10:54:40 -07:00
Andrew Kelley
b6bb0ee1ac Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux/tls.zig
 * test/behavior/align.zig
 * test/behavior/atomics.zig
 * test/behavior/vector.zig
2021-05-08 10:53:22 -07:00
Veikka Tuominen
7437c47d55 tests: work around miscompilation 2021-05-08 15:18:13 +03:00
Veikka Tuominen
08b6baca12 update usage of std.testing in langref.html 2021-05-08 15:16:05 +03:00
Veikka Tuominen
7fe39c4e96 update usage of std.testing in compiler_rt 2021-05-08 15:15:30 +03:00
Veikka Tuominen
42a95197f3 update usage of std.testing in stage2 2021-05-08 15:15:30 +03:00
Veikka Tuominen
0a38f61d58 update usage of std.testing in behavior and standalone tests 2021-05-08 15:15:30 +03:00
Veikka Tuominen
fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
Veikka Tuominen
59f9253d94 allow tests to fail 2021-05-08 15:15:23 +03:00
Andrew Kelley
28353b3159 stage2: fix struct inits not getting fields resolved 2021-05-07 22:16:15 -07:00
Andrew Kelley
73bf53069d ZIR: implement iteration over switch instructions
for changelist detection
2021-05-07 21:54:26 -07:00
Andrew Kelley
6ec24a6502 std: start code on linux when -lc also expands stack size
See #8708
2021-05-07 21:34:53 -07:00
Andrew Kelley
f69cf93064 std: start code increases stack size as appropriate on linux
closes #8708
2021-05-07 21:23:51 -07:00
Andrew Kelley
d577654e66 stage2: fix stack overflow in @setEvalBranchQuota test case
Some of the reworkings in this branch put us over the limit, on Linux,
where the kernel disregards the fact that we ask for 16 MiB in the ELF
file. So we ask for more stack space in `main`.
2021-05-07 20:03:27 -07:00
Andrew Kelley
81d5104e22 stage2: implement global variables
* Sema: implement global variables
   - Improved global constants to stop needlessly creating a Var
     structure; they can just store the value directly.
   - This required making memory management a bit more sophisticated to
     detect when a Decl owns the Namespace associated with it, for the
     purposes of deinitialization.
 * Decl.name and Namespace decl table keys no longer directly
   reference ZIR; instead they have heap-duped names, so that deleted
   decls, which no longer have any ZIR to reference for their names, can
   be removed from the parent Namespace table.
   - In the future I would like to explore going a different direction
     with this, where the strings would still point to the ZIR however
     they would be removed from their owner Namespace objects during the
     update detection. The design principle here is that the existence
     of incremental compilation as a feature should not incur any cost
     for the use case when it is not used. In this example Decl names
     could simply point to ZIR string table memory, and it is only
     because of incremental compilation that we duplicate their names.
 * AstGen: implement threadlocal variables
 * CLI: call cleanExit after building a compilation so that in release
   modes we don't bother freeing memory or closing file descriptors,
   allowing the OS to do it more efficiently.
 * Avoid calling `freeDecl` in the linker for unreferenced Decl objects.
 * Fix CBE test case expecting the compile error to point to the wrong
   column.
2021-05-07 18:52:11 -07:00
Andrew Kelley
e7c4d545cd stage2: no '$' in anonymous decl names
This way it will not cause a compile error for the C backend.
2021-05-07 16:18:49 -07:00
Andrew Kelley
6ac2047142 stage2: implement extern functions 2021-05-07 16:06:25 -07:00
Andrew Kelley
47531b7d93 Sema: support enough to check main calling convention via @typeInfo
After this commit, `pub export fn main() c_int { ... }` will be
correctly detected as the intended entry point, and therefore start code
will not try to export its own conflicting `main` function.

 * Implement basic union support
   - lots of stuff is still TODO, including runtime field access
   - also TODO: resolving the union tag type
   - comptime field access is implemented
 * DRY up some code by using the `Zir.DeclIterator` for skipping over
   decls in structs and unions.
 * Start to clean up Sema with regards to calling `.value()` to find out
   a const value. Instead, Sema code should call one of these two:
   - `resolvePossiblyUndefinedValue` (followed by logic dealing with
     undefined values)
   - `resolveDefinedValue` (a compile error will be emitted if the value
     is undefined)
 * An exported function with an unspecified calling convention gets the
   C calling convention.
 * Implement comptime field access for structs.
 * Add another implementation of "type has one possible value" in Sema.
   This is a bit unfortunate since the logic is duplicated, but the one
   in Type asserts that the types are resolved already, and is
   appropriate to call from codegen, while the one in Sema performs
   type resolution if necessary, reporting any compile errors that occur
   in the process.
2021-05-07 14:18:14 -07:00
Andrew Kelley
a7221ef4e9 Sema: implement @typeInfo for functions
The goal is to get start code to be able to inspect the calling
convention of `main` in order to determine whether to export a main for
libc to call, or to allow the root source file to do it.
2021-05-06 22:30:44 -07:00
Michael Dusan
84d5cc31c5 fix test to restore cwd after chdir
- `../zig-cache/tmp` is no longer created by subsequent test(s)
2021-05-07 01:04:38 -04:00
Andrew Kelley
3acd98fa34 stage2: CBE tests pub export instead of export main
This is needed so that start code can avoid redundantly trying to export
a main function for libc to call.
2021-05-06 17:51:09 -07:00
Andrew Kelley
7dd33d4316 stage2: fix compile errors in test harness 2021-05-06 17:48:38 -07:00
Andrew Kelley
9b9ea405ef CLI: add an update-and-run cmd and make enter re-run last cmd 2021-05-06 17:35:21 -07:00
Andrew Kelley
cdea22f5d7 stage2: wire up outdated/deleted decl detection
we're back to incremental compilation working smoothly
2021-05-06 17:20:45 -07:00
Andrew Kelley
3791cd6781 CLI: add 'run' command to the repl 2021-05-06 12:51:51 -07:00
Andrew Kelley
426e4c784c std.ArrayHashMap: ensureUnusedCapacity and ensureTotalCapacity
Same as 22015c1b3b, but for ArrayHashMap.
2021-05-06 12:50:53 -07:00
Andrew Kelley
530e67cb86 Merge pull request #8683 from LemonBoy/thumblinux
Initial bringup for Linux/Thumb2
2021-05-06 12:50:34 -04:00
lars
96e593145d stage1: improve message for missing fn return type
Coming from other languages it might be tempting for programmers to
accidentally leave out the return type instead of returning 'void'.

The error for this used to be

    error: invalid token: '{'
    pub fn main() {
                  ^

which is misleading. The '{' is expected but only after a return type.

The new message is

    error: expected return type (use 'void' to return nothing), found: '{'
    pub fn main() {
                  ^

which not only points out the real error but also hints at a (probably)
very common case where someone coming from e.g. Go is used to not
specifying a return type if a function returns nothing and thus forgets
to put 'void' there.

It might seem overkill to hint at the 'void' option but then the
compiler error messages are our user interface to the programmer. We
can be better than other languages in our error messages and leaving
out the return type seems to be a rather clear indication of the above
mentioned issue. Adding this will help more than distract.
2021-05-06 18:44:10 +02:00
Jakub Konka
88d40fc005 zld: sort tlv offsets by source address 2021-05-06 17:10:05 +02:00
Jakub Konka
ef8a666797 zld: cleanup relocs and flag errors on unhandled symbol types 2021-05-06 17:09:58 +02:00
Andrew Kelley
17067e0e6b stage2: fix contents hash computation
during an incremental update change detection,
the function call to get the old contents hash took place
after mangling the old ZIR index, making it access the wrong
array index.
2021-05-05 17:00:10 -07:00
Andrew Kelley
9b1aac8a65 stage2: mapping old to new ZIR recursively
now it walks into functions and blocks to find decls.
2021-05-05 16:56:24 -07:00
Andrew Kelley
c714a3250f std.ArrayList: add clearRetainingCapacity and clearAndFree 2021-05-05 16:55:49 -07:00
Andrew Kelley
5d7f2697de stage2: add zig changelist debug command
and implement the first pass at mechanism to map old ZIR to new ZIR.
2021-05-05 13:16:14 -07:00
Jakub Konka
ad33e34836 tests: re-enable reduce behavior tests for wasm32 2021-05-05 21:26:50 +02:00
Andrew Kelley
6b5d0b3711 std: fix compile errors found by stage2
* redundant `comptime`
 * `try` outside function
 * `extern enum`
2021-05-05 11:03:54 -07:00
Andrew Kelley
fc40d23723 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * lib/std/array_list.zig
 * lib/std/c/ast.zig
 * lib/std/c/parse.zig
 * lib/std/os/bits/linux.zig
2021-05-05 10:48:22 -07:00
LemonBoy
9d409233b2 std: Implement hex float printing
The results have been cross-checked with LLVM's APFloat implementation
by randomly sampling the f32/f64 space, while the f16 one was completely
checked given the small size.
2021-05-05 12:37:40 -04:00
LemonBoy
18b46485bc stage2: Fix UAF in ErrorMsg destructor
After calling gpa.destroy the object is gone for good, setting the
contents to undefined is a bug and may crash the compiler.
2021-05-05 12:37:04 -04:00
Michael Dusan
622a3ac876 Merge pull request #8691 from lithdew/master
x/net: fix tcp tests for openbsd and add missing `fmt` import
2021-05-05 05:54:47 -04:00
Andrew Kelley
368e13a9a1 Merge pull request #8671 from LemonBoy/arm-host-det
ARM/AArch64 CPU host detection
2021-05-05 03:17:32 -04:00
LemonBoy
e863204c47 zig fmt: Fix edge case in inline asm parsing
The presence of a trailing comma in the single and only input/output
declaration confused the parser and made zig fmt discard any element
placed after the comma.
2021-05-05 03:16:07 -04:00
Jay Petacat
70a9a3a562 stage1: Fix other OS target
PR #7827 added some new `std.Target.Os.Tag` before `other`.
The corresponding enum in stage1.h was not updated, which caused a
mismatch in the underlying integer values. While attempting to target
`other`, I encountered crashes.

This PR updates the stage1.h enum to include the added OS tags.
The new tags also had to be added to various switch cases to fix
compiler warnings, but have not been tested in any way.
2021-05-05 03:15:44 -04:00
lithdew
c75ae8b66d x/net: fix tcp tests for openbsd and add missing fmt import
On OpenBSD, connecting to a newly-allocated port on an unspecified IPv4
host address causes EINVAL. This was found by @mikdusan when running TCP
tests on OpenBSD.

This commit fixes TCP tests on OpenBSD by having all tests that allocate
a new host-port pair to have the host IPv4/IPv6 address point to the
host's loopback adapter (on localhost).
2021-05-05 16:09:08 +09:00
Andrew Kelley
7a27f0d80c Sema: restore the extern lib name functionality 2021-05-04 14:40:59 -07:00
Andrew Kelley
1f0fd64302 stage2: test coverage for inline asm return type not type 2021-05-04 14:23:53 -07:00
Andrew Kelley
edfbf85ecd Sema: implement error sets 2021-05-04 13:58:08 -07:00
Andrew Kelley
230ce72f16 stage2: fix "other symbol here" error note
It wasn't setting the source location properly.
2021-05-04 12:32:22 -07:00
Sage Hane
975cb9e9a9 std.zig: make the unrecognized C flag case non-fatal 2021-05-05 04:19:08 +09:00
Andrew Kelley
3dafec0acd stage2: fix structs and enums setting wrong owner_decl
No more memory leaks.
2021-05-04 11:08:40 -07:00
Andrew Kelley
785a6c1aa9 std: remove dead and rotting C parsing code 2021-05-04 10:26:44 -07:00
LemonBoy
afbcb6209d std: Initial bringup for Linux on Thumb2
There are some small problems here and there, mostly due to the pointers
having the lsb set and disrupting the fn alignment tests and the
`@FrameSize` implementation.
2021-05-04 18:52:53 +02:00
LemonBoy
4bf093f1a0 compiler-rt: Better selection of __clzsi implementation
To be honest all this detection logic is starting to become a real PITA,
the ARM32 version can be possibly removed as the generic version
optimizes pretty well...
2021-05-04 18:45:52 +02:00
LemonBoy
389d1177a5 stage1: Fix LLVM error in inline asm invocation
Pointer types need an extra indirection layer during the generation of
the function prototype for inline asm blocks.

Closes #3606
2021-05-04 18:43:31 +02:00
Jakub Konka
96556ce8b8 zld: port over a few more bits from ld64
* UTF16 gets its own section, `__TEXT,__ustring`
* TLV data and bss sections have to aligned to the same max alignment
  according to Apple rdar comment in the latest ld64
2021-05-04 13:09:32 +02:00
Jakub Konka
1867c3c34c zld: disable most logs 2021-05-04 13:09:32 +02:00
Jakub Konka
9e11f27c41 zld: build updated macho backend 2021-05-04 13:09:32 +02:00
Jakub Konka
00c3d57a51 zld: rewrite symbol allocations 2021-05-04 13:09:32 +02:00
Jakub Konka
fcd57f0857 zld: resolve GOT loads and stubs 2021-05-04 13:09:32 +02:00
Jakub Konka
68ebc7cba0 zld: rewrite symbol resolution 2021-05-04 13:09:32 +02:00
Jakub Konka
86ab6ca56c zld: rewrite Object to include pointers to Symbols 2021-05-04 13:09:32 +02:00
LemonBoy
b6be28ddcc std: Accept unaligned slice in several ArrayListAligned ops
Do not impose the internal alignment requirements to the user-supplied
parameters.

Closes #8647
2021-05-04 14:08:19 +03:00
Andrew Kelley
2910b10033 build.zig: add -Dmem-leak-frames option
to configure how many stack frames to save with every allocation, in
case it leaks and needs to get printed on process termination.
2021-05-03 20:42:36 -07:00
Andrew Kelley
2ae72c6f09 Sema: implement ExportOptions support in @export
Also fix switch blocks not emitting their AIR code.
2021-05-03 20:05:29 -07:00
Andrew Kelley
69d18ad7f0 ZIR: typeof uses the un_node field not un_tok 2021-05-03 18:47:53 -07:00
Andrew Kelley
95b014caea Sema: implement struct_decl instruction 2021-05-03 18:35:37 -07:00
Andrew Kelley
0e3930bb5a Merge pull request #8649 from lithdew/master
x/os, x/net: layout tcp, ipv4/ipv6, and socket abstractions
2021-05-03 17:38:10 -04:00
Andrew Kelley
5622f9382c Merge pull request #8657 from jedisct1/ci-split
Azure CI: Test std.* and the rest separately
2021-05-03 17:36:51 -04:00
Andrew Kelley
aa4e9399db ZIR: implement debug text printing for struct_init and friends 2021-05-03 12:25:20 -07:00
Andrew Kelley
773902e9de stage2: hook up semantic analysis of struct fields
Now that they are lazy, they need to get analyzed in the correct
context, when requested.

This commit also hooks up std.builtin type values being resolved
properly. This is needed, for example, with the `@export` builtin
function, which occurs in start.zig, for `std.builtin.ExportOptions`.
The ZIR code uses the special `Ref.export_options` value, and semantic
analysis has to map this to the corresponding type from `std.builtin`.
2021-05-03 11:46:02 -07:00
LemonBoy
3eed613407 std: Add two more ARM CPUs to the known CPU list
Modeled after GCC's description.
2021-05-03 12:32:13 +02:00
LemonBoy
e2d2295382 std: Add many more vendors and cpus to the ARM detection list
Hand-picked from GCC and LLVM lists.
2021-05-03 12:32:13 +02:00
LemonBoy
a7f3e12d23 std: Add fallback on pre-v6 ARM targets
Thanks xackus for noticing the missing else branch.
2021-05-03 12:32:13 +02:00
LemonBoy
792cf925ec std: Fix missing CPU feature check
We need both the v6k and the v6m checks.
2021-05-03 12:32:13 +02:00
LemonBoy
b10d40b89b stage2: Implement CPU host detection for ARM/AArch64 targets 2021-05-03 12:32:13 +02:00
Frank Denis
97779442d0 Prepare std/crypto/pcurves for ecdsa and other curves (#8670)
Functions generated by Fiat-crypto are not prefixed by their description any more. This matches an upstream change.

We can now use a single type for different curves and implementations.

The field type is now generic, so we can properly handle the base field and scalars without code duplication.
2021-05-03 09:57:45 +02:00
lithdew
96fe49ef62 std/os/bits/windows: add timeval extern struct 2021-05-03 14:49:10 +09:00
lithdew
16fc1b904c std/os/linux/bits: correct socket option codes for ppc/ppc64 2021-05-03 14:49:10 +09:00
lithdew
af057c888b x/net/ip: add copyright header 2021-05-03 14:49:10 +09:00
lithdew
5c4fbc4014 x/net: generalize tcp.Address into ip.Address
Generalize `tcp.Address` into `ip.Address` given that multiple transport
protocols apart from TCP (i.e. UDP) operate solely over IP.
2021-05-03 14:49:10 +09:00
lithdew
cc6714a929 std/os/bits: add timeval struct for riscv64 linux 2021-05-03 14:49:10 +09:00
lithdew
a799ad05b3 x/net/tcp: make tcp tests blocking to avoid unit test races 2021-05-03 14:49:10 +09:00
lithdew
aa15699269 x/os/net: skip ipv6 scope id parse test on unsupported platforms 2021-05-03 14:49:10 +09:00
lithdew
9a7c57144d x/net: disable tcp tests on wasi 2021-05-03 14:49:10 +09:00
lithdew
8ef9d98e6d x/os: fix compile errors on mac and linux
Use i32 instead of isize for os.timeval's for socket read/write
timeouts.

Add a comptime check to resolveScopeID to see if `IFNAMESIZE` is
available on the host. If it is not available, return an error
indicating that resolving the scope ID of a IPv6 address is not yet
supported on the host platform.
2021-05-03 14:49:10 +09:00
lithdew
76304a36af std/builtin: add missing comma to CallingConvention 2021-05-03 14:49:10 +09:00
lithdew
13068da43e x/os, x/net: re-approach Address, rename namespace TCP -> tcp
Address comments from @ifreund and @MasterQ32 to address unsafeness and
ergonomics of the `Address` API.

Rename the `TCP` namespace to `tcp` as it does not contain any
top-level fields.

Fix missing reference to `sockaddr` which was identified by @kprotty in
os/bits/linux/arm64.zig.
2021-05-03 14:49:10 +09:00
lithdew
2ab588049e x/os, x/net: layout tcp, ipv4/ipv6, and socket abstractions
The `Socket` abstraction was refactored to only comprise of methods that
can be generically used/applied to all socket domains and protocols.

A more comprehensive IPv4/IPv6 module derived from @LemonBoy's earlier
work was implemented under `std.x.os.IPv4` and `std.x.os.IPv6`. Using
this module, one can then combine them together into a union for example
in order to optimize memory usage when dealing with socket addresses.

A `TCP.Client` and `TCP.Listener` abstraction is introduced that is one
layer over the `Socket` abstraction, which isolates methods that can
only be applied to a "client socket" and a "listening socket". All prior
tests from the `Socket` abstraction, which all previously operated
assuming the socket is operating via. TCP/IP, were moved. All TCP socket
options were also moved into the `TCP.Client` and `TCP.Listener`
abstractions respectively away from the `Socket` abstraction.

Some additional socket options from @LemonBoy's prior PR for Darwin were
also moved in (i.e. SIGNOPIPE).
2021-05-03 14:49:10 +09:00
Andrew Kelley
807a8b6f75 stage2: make struct field analysis lazy
This commit breaks struct field analysis; will be fixed in a future
commit.
2021-05-02 18:50:01 -07:00
Andrew Kelley
5f4c52209e AstGen: fix outdated doc comment 2021-05-02 17:17:24 -07:00
Andrew Kelley
a973c362e5 AstGen: decouple from Module/Compilation
AstGen is now completely independent from the rest of the compiler. It
ingests an AST tree and produces ZIR code as the output, without
depending on any of the glue code of the compiler.
2021-05-02 17:08:19 -07:00
Andrew Kelley
d5f77c0bab stage2: fix error reporting not loading AST
In the byteOffset function, compile errors may need to compute the AST
from source bytes in order to resolve source locations. Previously there
were a few lines trying to access the AST before it was loaded. Trivial
fix, just move load the tree at the beginning.
2021-05-02 15:06:32 -07:00
Andrew Kelley
0611aa3985 stage2: test decls encode that they are tests in ZIR
This allows Sema to namespace them separately from function decls with
the same name. Ran into this in std.math.order conflicting with a test
with the same name.
2021-05-02 14:58:27 -07:00
Luna
c47028cd02 ci: freebsd: use py38-s3cmd 2021-05-02 17:24:17 -04:00
Andrew Kelley
4dd724d06a Sema: fix struct decl decoding ZIR incorrectly 2021-05-01 23:31:26 -07:00
Andrew Kelley
eadcefc124 stage2: dbg_stmt ZIR instructions have line/col
instead of node indexes.

 * AstGen: dbg_stmt instructions now have line and column indexes,
   relative to the parent declaration. This allows codegen to emit debug
   info without having the source bytes, tokens, or AST nodes loaded
   in memory.
 * ZIR: each decl has the absolute line number. This allows computing
   line numbers from offsets without consulting source code bytes.

Memory management: creating a function definition does not prematurely
set the Decl arena. Instead the function is allocated with the general
purpose allocator.

Codegen no longer looks at source code bytes for any reason. They can
remain unloaded from disk.
2021-05-01 21:57:52 -07:00
Andrew Kelley
6248e2a560 std.GeneralPurposeAllocator: print leaked memory addresses
This helps when using it with other tools, such as memory watchpoints.
2021-05-01 21:25:01 -07:00
Frank Denis
9a637f81e0 Restore the CI logging as before 2021-05-02 02:07:59 +02:00
Andrew Kelley
4f9c928e56 Merge pull request #8665 from LemonBoy/misc
Miscellaneous patches
2021-05-01 18:07:58 -04:00
Andrew Kelley
d788181a3b fix typo
Co-authored-by: Maciej Walczak <14938807+xackus@users.noreply.github.com>
2021-05-01 18:07:26 -04:00
Sage Hane
6490e57136 std.zig: handle -frandom-seed in NIX_CFLAGS_COMPILE 2021-05-02 02:44:55 +09:00
LemonBoy
06b2fee05e std: Implement isFinite for f128 2021-05-01 16:28:13 +02:00
LemonBoy
236dba8ba9 std: Implement copysign for f128 2021-05-01 16:28:08 +02:00
LemonBoy
9f6edfd201 std: Implement signbit for f128 2021-05-01 16:28:03 +02:00
LemonBoy
718b43504e std: Fix pwrite/pread syscalls on SPARC targets 2021-05-01 15:46:28 +02:00
LemonBoy
69a9c1488d std: Add signal numbers for SPARC 2021-05-01 12:25:40 +02:00
LemonBoy
527053a4e4 std: Import correct errno defs for SPARC
Taken from Linux arch/sparc/include/uapi/asm/errno.h
2021-05-01 11:03:59 +02:00
LemonBoy
51f80deaf6 std: Fix stack overflow in SPARC clone() impl
Leave the minimum amount of stack space required by the ABI (16 * 8
bytes for the window contents plus 6 * 8 bytes for the input arguments)
on the new thread stack.
2021-05-01 11:02:04 +02:00
g-w1
e9e91b4ed0 std.build: if using a RunStep, show the command run on verbose (#8571) 2021-05-01 08:17:17 +02:00
Frank Denis
fe8781357a std.crypto: add support for the NIST P-256 curve (#8627)
Uses verified code generated by fiat-crypto for field arithmetic, and complete formulas to avoid side channels.

There's still plenty of room for optimizations, especially with a fixed base. But this gives us a framework to easily add other similar curves.
2021-05-01 08:14:32 +02:00
Andrew Kelley
dc28f5c3ec Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
	lib/std/crypto/25519/field.zig
	lib/std/crypto/poly1305.zig

I had resolved those by removing `comptime` but master branch decided to
make the parameters `comptime`.

This also pulls in the updated default `zig build` install directory.
2021-04-30 23:13:17 -07:00
Andrew Kelley
351b57497b stage2: implement function body analysis
now with whole-file-astgen
2021-04-30 23:11:20 -07:00
Andrew Kelley
557eb414ee CLI: fix incorrect error message with -cflags 2021-04-30 21:55:28 -07:00
Andrew Kelley
077b8d3def stage2: introduce new ZIR instruction: arg
* AstGen: LocalVal and LocalPtr use string table indexes for their
   names. This is more efficient because local variable declarations do
   need to include the variable names so that semantic analysis can emit
   a compile error if a declaration is shadowed. So we take advantage of
   this fact by comparing string table indexes when resolving names.

 * The arg ZIR instructions are needed for the above reasoning, as well
   as to emit equivalent AIR instructions for debug info.
   Now that we have these arg instructions, get rid of the special
   `Zir.Inst.Ref` range for parameters. ZIR instructions now refer
   to the arg instructions for parameters.

 * Move identAsString and strLitAsString from Module.GenZir to AstGen
   where they belong.
2021-04-30 21:43:18 -07:00
Devin Bayer
5fcc922ff2 add doc in Anonymous Struct Literal section for special @"0" syntax. (#8630) 2021-05-01 01:05:45 +02:00
Frank Denis
33cb660838 Doc: zig-cache/bin -> zig-out/bin (#8659) 2021-05-01 00:41:59 +02:00
Frank Denis
3e389d01ed CI: no need to try qemu and wasmtime on macOS builds 2021-05-01 00:38:54 +02:00
Frank Denis
b49d99b246 Azure CI: Test std.* and the rest separately
On CI, we have been running into OOM issues when running the test
suite on Windows for quite some time.

Unfortunately, we are very close to having the same issues on Linux
as well. Some additional comptime work immediately makes these builds
fail as well.

Add a new `test-toolchain` step, that tests everything except `std.*`
and documentation.

On CI, call `test-toolchain`, `test-std` and `docs` separately
instead of the `test` big hammer that emcompasses all of them.

Change the special case we made for Windows to the same code as other
platforms.

This is a stopgap measure that stage2 will eventually make useless.

Until then, it gives us some headroom.

Change `linux_script` by the way to only output the log of failing
steps. This shrinks the Linux CI log from a bazilion lines down to
something more humanely manageable.
2021-04-30 23:41:28 +02:00
Andrew Kelley
db7acd83d2 Sema: implement function declarations 2021-04-30 14:36:02 -07:00
Devin Bayer
d3f55782b0 rename doc refs to deprecated functions like openC (#8467) 2021-04-30 21:31:01 +02:00
Andrew Kelley
fb95fd8443 start.zig: unconditionally import the root source file
stage1 did this by accident by unconditionally semantically analyzing
std.builtin.panic, which imports the root source file to look for a
panic handler override. But stage2 is smarter; it will only semantically
analyze std.builtin.panic if any panic calls are emitted. So for very
simple compilations, the root source file was being ignored, even if it
contained `export` functions in it.
2021-04-30 11:24:15 -07:00
Andrew Kelley
2d8d681b5e stage2: un-tangle memory management of Decl and Namespace
Before there was this "top_decl" and "tmp_namespace" stack values that
were kludgy and buggy. Now Sema is slightly reworked so that files which
are structs are analyzed with their own Decl and Namespace already set
up.

After this commit there are no memory leaks for a successful build-obj.
2021-04-30 11:07:31 -07:00
LemonBoy
807bb7c03f std: Improve spinloop hint
* Add a yield pattern for PowerPC64
* Fix compile error on pre-v6 ARM targets
* Use isb instead of yield on AArch64 to give the CPU a chance to enter
  low-power states.
* Make the hint an inline function, the call overhead can be avoided.
2021-04-30 17:11:03 +02:00
Yorhel
f79b487337 Handle EPERM and ELOOP in os.fstatat() 2021-04-30 15:08:07 +02:00
Andrew Kelley
4e07755ce7 Merge pull request #8638 from ifreund/build-default-prefix
std/build: change default install prefix to zig-out
2021-04-30 00:10:44 -04:00
Andrew Kelley
5d696b0706 stage2: fix File incorrectly freeing its Namespace 2021-04-29 20:49:31 -07:00
Andrew Kelley
8ab4a003c8 stage2: properly free Decl name
Two problems solved:

 * The Decl name may be allocated with gpa or it may be a reference to
   the ZIR string table.

 * The main update() function was freeing the ZIR when we still had
   Decl objects referencing it.
2021-04-29 20:34:33 -07:00
Andrew Kelley
474ade88b5 std: fix compile errors found by stage2 AstGen 2021-04-29 20:33:29 -07:00
Andrew Kelley
8944240aec AstGen: represent global variables directly
Rather than with `block_inline_var`. This matches how function
declarations work and how extern variables work.
2021-04-29 19:56:01 -07:00
Andrew Kelley
86d564eed8 AstGen: implement extern variables 2021-04-29 19:44:51 -07:00
Andrew Kelley
ba9b9cb38d AstGen: implement function prototypes with alignment exprs 2021-04-29 18:25:25 -07:00
Andrew Kelley
2eef83e85f AstGen: fix comptime compile error source location 2021-04-29 17:43:07 -07:00
Andrew Kelley
47585cbe12 Sema: rename TZIR to AIR
Analyzed Intermediate Representation
2021-04-29 17:26:21 -07:00
Andrew Kelley
478dac5346 Sema: skip analysis of empty enum blocks
For these, the ZIR code has an empty block rather than a block with a
single `break_inline` instruction.
2021-04-29 17:25:10 -07:00
Andrew Kelley
9e49a65e1b AstGen: implement anytype struct fields 2021-04-29 17:13:18 -07:00
Andrew Kelley
55e86b724a AstGen: implement comptime struct fields 2021-04-29 16:57:13 -07:00
Andrew Kelley
fb4cb430e0 std.enums: remove stuff for enums with field aliases
This will probably conflict with the real patch to rework this code, and
in such case this commit should be discarded in favor of the other
commit.
2021-04-29 16:05:30 -07:00
Andrew Kelley
4307436b99 move behavior tests from test/stage1/ to test/
And fix test cases to make them pass. This is in preparation for
starting to pass behavior tests with self-hosted.
2021-04-29 15:54:04 -07:00
Andrew Kelley
5a02c938da update behavior tests with respect to new builtin pkg 2021-04-29 15:18:40 -07:00
Isaac Freund
5079d11b21 std/build: change default install prefix to zig-out
Currently the default install prefix is $BUILD_ROOT/zig-cache,
but mixing cache and artifacts makes little sense. Instead make
$BUILD_ROOT/zig-out the default.
2021-04-29 23:58:45 +02:00
Andrew Kelley
eb53680bce tests: prepare behavior tests for stage2 2021-04-29 14:51:21 -07:00
Matthew Borkowski
585479500e check for overflow when reading code lengths for a block with dynamic Huffman codes 2021-04-29 17:48:08 -04:00
Frank Denis
687ef42f98 x: comptime bool -> comptime x: bool (#8639) 2021-04-29 16:27:50 +02:00
Isaac Freund
2ed368fb92 std/build: add -p alias for --prefix 2021-04-29 14:25:58 +02:00
Andrew Kelley
d36a31ba75 stage2: fix scanDecls not advancing the field bits
Also fix `semaFile` not handling compile errors properly.
2021-04-28 23:16:13 -07:00
Andrew Kelley
c60d8f017e std: remove redundant comptime keyword
@g-w1's fancy new compile error in action
2021-04-28 22:58:12 -07:00
Andrew Kelley
0c71d2fdc1 stage2: implement semantic analysis for functions and global vars
* AstGen: add missing `break_inline` for comptime blocks.
 * Module: call getTree() in byteOffset(). This generates the AST when
   using cached ZIR and compile errors need to be reported.
 * Scope.File: distinguish between successful ZIR generation and AIR
   generation (when Decls in scope have been scanned).
   - `semaFile` correctly avoids doing work twice.
 * Implement first pass at `lookupInNamespace`. It has various TODOs
   left, such as `usingnamespace`, and setting up Decl dependencies.
2021-04-28 22:43:26 -07:00
Andrew Kelley
3462193d30 stage2: prepare for mainining Decl references to ZIR indexes 2021-04-28 16:57:01 -07:00
Andrew Kelley
f86469bc5e stage2: semaDecl properly analyzes the decl block
Also flattened out Decl TypedValue fields into
ty, val, has_tv
and add relevant fields to Decl for alignment and link section.
2021-04-28 16:57:01 -07:00
Andrew Kelley
fa6bb4b662 Sema: do not analyze test decls when not in test mode
We do this by reserving string table indexes 0 and 1 in ZIR to be
special. Decls now have 0 to mean comptime or usingnamespace, and 1 to
mean an unnamed test decl.
2021-04-28 16:57:01 -07:00
jacob gw
2354cbafdb stage2: implement #8364 2021-04-28 19:54:04 -04:00
Andrew Kelley
c90e52b74c std: remove redundant comptime const 2021-04-28 15:15:44 -07:00
Andrew Kelley
d3ffacb55c AstGen: hook up hex float parsing to float literals
Thanks @LemonBoy!
2021-04-28 15:13:43 -07:00
Andrew Kelley
9db5b2c5c6 AstGen: function prototypes can have alignment 2021-04-28 15:02:52 -07:00
Andrew Kelley
df24ce52b1 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted to take advantage of the new hex float parsing
code.
2021-04-28 14:57:38 -07:00
LemonBoy
55c58f226d std: Add a parser for hexadecimal floating point numbers
Should be good enough to unblock progress on the stage2 compiler.

Unifying this parser and the regular one (and perhaps rewrite it, #2207)
is left as an exercise for the reader.
2021-04-28 17:36:12 -04:00
Andrew Kelley
86e129eff6 std.Target: bump freebsd known maximum version 2021-04-28 10:26:47 -07:00
Andrew Kelley
2c9ed6daee Merge pull request #8472 from sreehax/master
callconv: add SysV
2021-04-28 13:11:40 -04:00
joachimschmidt557
bc06e19828 stage2 riscv64: cleanup code and add tests 2021-04-28 07:20:45 +02:00
Andrew Kelley
eb9c29eb81 AstGen: fix function src hash not including body 2021-04-27 22:20:25 -07:00
Andrew Kelley
3d9e4edb57 link: fix compile error from previous commit 2021-04-27 14:46:55 -07:00
LemonBoy
da9da76e3f stage1: Implement CPU host detection for PowerPC targets
Untested but should work well on both 32 and 64 bit systems.
2021-04-27 13:11:39 -04:00
Andrew Kelley
bfded492f0 stage2: rewire the frontend driver to whole-file-zir
* Remove some unused imports in AstGen.zig. I think it would make sense
   to start decoupling AstGen from the rest of the compiler code,
   similar to how the tokenizer and parser are decoupled.
 * AstGen: For decls, move the block_inline instructions to the top of
   the function so that they get lower ZIR instruction indexes. With
   this, the block_inline instruction index combined with its corresponding
   break_inline instruction index can be used to form a ZIR instruction
   range. This is useful for allocating an array to map ZIR instructions
   to semantically analyzed instructions.

 * Module: extract emit-h functionality into a struct, and only allocate
   it when emit-h is activated.
 * Module: remove the `decl_table` field. This previously was a table of
   all Decls in the entire Module. A "name hash" strategy was used to
   find decls within a given namespace, using this global table. Now,
   each Namespace has its own map of name to children Decls.
   - Additionally, there were 3 places that relied on iterating over
     decl_table in order to function:
     - C backend and SPIR-V backend. These now have their own decl_table
       that they keep populated when `updateDecl` and `removeDecl` are
       called.
     - emit-h. A `decl_table` field has been added to the new GlobalEmitH
       struct which is only allocated when emit-h is activated.
 * Module: fix ZIR serialization/deserialization bug in debug mode having
   to do with the secret safety tag for untagged unions. There is still an
   open TODO to investigate a friendlier solution to this problem with
   the language.
 * Module: improve deserialization of ZIR to allocate only exactly as
   much capacity as length in the instructions array so as to not waste
   space.
 * Module: move `srcHashEql` to `std.zig` to live next to the definition
   of `SrcHash` itself.
 * Module: re-introduce the logic for scanning top level declarations
   within a namespace.

 * Compilation: add an `analyze_pkg` Job which is used to kick off the
   start of semantic analysis by doing the equivalent of
   `_ = @import("std");`. The `analyze_pkg` job is unconditionally added
   to the work queue on every update(), with pkg set to the std lib pkg.

 * Rename TZIR to AIR in a few places. A more comprehensive rename will
   come later.
2021-04-26 20:41:07 -07:00
Andrew Kelley
1c0259f11e Merge pull request #8609 from jedisct1/timingSafeCompare
Add std.crypto.utils.timingSafeCompare
2021-04-26 23:03:46 -04:00
Andrew Kelley
91c317bb9a AstGen: improved handling of declarations
* Every decl provides a 16 byte source hash which can be used to detect
   if the source code for any particular decl has changed.
 * Include comptime decls, test decls, and usingnamespace decls in the
   decls list of namespaces.
   - Tests are encoded as extended functions with is_test bit set.
2021-04-26 17:36:28 -07:00
Frank Denis
d3361c41db Change timingSafeCompare() to accept slices 2021-04-26 22:32:22 +02:00
Frank Denis
030fa5e7eb 25519: remove unused const, safeguard against unreduced scalars (#8624)
* 25519: remove unused const, safeguard against unreduced scalars

No behavior change, but it makes the existing code better match
the forthcoming code for other curves.

Rename nonAdjacentForm() to slide(), remove an unneeded and
confusing constant, and do a reduction in slide() if 257 bits would
be required.

Note that in all the high-level functions, the top bit is always
cleared, so the reduction is never necessary. But since the low-level
functions are public, the check is a safe thing to have.

* 25519: make identityElement public, deprecate neutralElement

Also fix a few comments by the way.
2021-04-26 22:25:48 +02:00
Andrew Kelley
95b42f9e6b Merge pull request #8604 from hoanga/haiku-support-sysdefs
further haiku support system definitions
2021-04-26 16:12:23 -04:00
Andrew Kelley
0de962fdd9 Merge pull request #8622 from LemonBoy/cpuinfo
stage2: Add framework for host CPU detection on Linux
2021-04-26 16:02:07 -04:00
Andrew Kelley
646eb1fa93 AstGen: implement opaque decls
Also move the decls to the beginning in ZIR encoding because in Sema we
want to create the namespace with the decls before evaluating the
fields.
2021-04-26 12:49:02 -07:00
Andrew Kelley
528a83dd6b Merge pull request #8618 from LemonBoy/mini-stuff
Two small patches
2021-04-26 14:32:45 -04:00
Andrew Kelley
ddf9ff79bd Revert "thread: simplify and remove useless return in spawn (#8621)"
This reverts commit 77cb45f59f.

Zig's error return traces will point to the return token if they
happen to occur, so having multiple return statements makes those
stack traces really helpful. This destroys debuggability.
2021-04-26 10:44:40 -07:00
LemonBoy
7e6cc4c505 stage2: Ensure the features set is populated 2021-04-26 18:28:17 +02:00
LemonBoy
896d93e1e6 stage2: Add framework for host CPU detection on Linux
Add a generic framework to parse /proc/cpuinfo and implement the model
detection for 64bit SPARC targets as proof of concept.
2021-04-26 18:11:28 +02:00
Vincent Rischmann
77cb45f59f thread: simplify and remove useless return in spawn (#8621) 2021-04-26 18:03:32 +02:00
jumpnbrownweasel
bf67a3fdc9 #8454 Fix for std.mem.replacementSize adjacent matches bug. (#8455)
* #8454 Fix for std.mem.replacementSize adjacent matches bug.

When two 'needle' values are adjacent in the 'input' slice, the size is not
counted correctly. The 2nd 'needle' value is not matched because the index is
incremented by one after changing the index to account for the first value.

The impact is the the size returned is incorrect, and could cause UB when this
amount is used to size of the buffer passed to std.mem.replace.

* Apply changes from PR review:

- Add assert checking that the needle is non-empty and doc for this.
- Add minimal test that an empty input works.
- Use testing.expectEqualStrings.
2021-04-25 19:16:24 -04:00
Andrew Kelley
c420eb60ad Merge pull request #8590 from lithdew/master
x,  x/os/Socket: initial work on new Socket abstraction
2021-04-25 19:15:15 -04:00
Andrew Kelley
2fc6b347ec Merge pull request #8616 from LemonBoy/fn-align
Function pointer alignment
2021-04-25 19:12:06 -04:00
LemonBoy
82f1d592fa stage1: Use correct alignment for asyncCall frame 2021-04-25 20:41:49 +02:00
Andrew Kelley
56226449d2 stage2: pre-open ZIR cache dir handles
So that we do not needlessly open and close the ZIR cache dir handles in
each AstGen operation.
2021-04-25 10:43:07 -07:00
Andrew Kelley
6f61594692 Merge pull request #8496 from xackus/isError
std.meta: add isError
2021-04-25 13:27:44 -04:00
LemonBoy
5a94794b73 std: Fix thread creation with field-less context type
Closes #8524
2021-04-25 13:21:15 -04:00
joachimschmidt557
3a55cda14d stage2 register manager: Use an array instead of a hashmap for tracking
allocated registers
2021-04-25 13:20:53 -04:00
LemonBoy
dc29d86649 std: Fix wrong alignOf expression
Mostly harmless but conceptually wrong, luckily it hasn't tripped any
safety check.
2021-04-25 19:12:49 +02:00
LemonBoy
54db36cd88 std: Fix backtraces on sparcv9
Flush all the register windows to stack before starting the stack walk,
we may otherwise try to read garbage and crash and burn.

Add a few comptime annotations to debloat some functions.
2021-04-25 19:10:11 +02:00
Frank Denis
0747591c3d Add std.crypto.utils.timingSafeCompare
A little function to complement the existing crypto.utils.timingSafeEql
function with a way to compare large numbers serialized as arrays.

This is useful to compare nonces and to check that group elements are
in canonical form.

Absence of side channels remains a best effort, reusing the common
pattern we use elsewhere.
2021-04-25 17:07:11 +02:00
LemonBoy
0340ed3a9e build: Re-add test-translate-c and test-run-translated-c 2021-04-25 17:02:48 +02:00
LemonBoy
ae15022406 translate-c: Fix casting of function pointers
The @ptrCast(X, @alignCast(@alignOf(T), Y)) pattern is only correct if T
is not a function type or a pointer, in that case the @alignOf refers to
the pointer itself and not to the pointee type.
2021-04-25 16:50:41 +02:00
LemonBoy
19cec0db1e std: Make met.alignment work on more types
Make it return the correct value for function types and optional
pointers.
2021-04-25 16:49:21 +02:00
LemonBoy
50a8124f45 stage1: Change how the Frame alignment is computed
The code would previously assume every function would start at addresses
being multiples of 16, this is not true beside some specific cases.
Moreover LLVM picks different alignment values depending on whether it's
trying to generate dense or fast code.

Let's use the minimum guaranteed alignment as base value, computed
according to how big the opcodes are.

The alignment of function pointers is always 1, a safe value that won't
cause any error at runtime. Note that this was already the case before
this commit, here we're making this choice explicit.

Let the 'alignment' field for TypeInfo of fn types reflect the ABI
alignment used by the compiler, make this field behave similarly to the
'alignment' one for pointers.
2021-04-25 16:40:41 +02:00
lithdew
98706c9686 x: fmt source code 2021-04-25 21:15:02 +09:00
lithdew
b435d7fa60 x, x/os/Socket: initial work on new Socket abstraction
Kick-start initial work on new cross-platform abstraction for
sockets. Adds a test for read timeouts and a test for creating
a non-blocking socket pair on Linux.

The new Socket abstraction is barebones and is made to support both
blocking and non-blocking abstractions, alongside different socket
protocols and domains.

Support for platform-dependant socket options that handles unsupported
platforms gracefully via. comptime checks is provided for the new Socket
abstraction.

This also marks the first out of many commits for introducing breaking
changes to the standard library in a separate `x` folder, which was
pre-approved by @andrewrk.

The intent for the new `x` package is to introduce new async, event loop,
networking, and operating system abstractions that would require breaking
the standard library significantly. By having the `x` package, code in the
standard library and compiler may then slowly be refactored to use the `x`
package. Once modules in the `x` package are stabilized, they can be moved
out of the `x` package, and a global 'grep' can be done to update import
paths that resolve to the stabilized module in the `x` package.
2021-04-25 21:15:02 +09:00
Andrew Kelley
015cd79f89 stage2: implement caching for ZIR code
Notably this exposed an issue with the language having to do with the
secret safety tag on untagged unions. How can we have our cake and eat
it too? Not solved in this commit. I will file a language proposal to
tackle this issue soon.

Fixes a compile error in `std.fs.File.readvAll`.
2021-04-25 00:02:58 -07:00
Shachaf Ben-Kiki
33da465079 Use a directEnumArray lookup table instead of a switch 2021-04-24 23:03:48 -07:00
Shachaf Ben-Kiki
01aa74a93f parser: Use an operator precedence table
Instead of having one function per precedence level, mirroring the BNF grammar,
this uses the "precedence climbing" algorithm with a table of operator
precedences (and a few special cases that don't fit into the table as it is).

This is a first pass -- it's probably possible to put more of the parser
into this form, e.g. to support prefix/suffix operators with precedence, if
necessary, or just to simplify the code more.

It may also be possible to speed this up by putting more useful information
into the tokens during tokenization, to avoid the extra branch on the token in
operInfo.
2021-04-24 22:40:41 -07:00
Michael Dusan
37b05742ff ci: drone disable debug test suite for aarch64
Temporary workaround for #8597 until upstream fix lands.

- add `zig build -Dskip-debug` option
- build a release-fast build.exe
- disable test suite build modes { debug, release-small, release-safe }
- enable passing test-* components
- use parallel pipeline steps for tests
2021-04-25 00:02:36 -04:00
Andrew Kelley
ff2ec0dc5a AstGen: implement @Vector 2021-04-24 17:44:07 -07:00
Andrew Kelley
e018e64a53 stage2: move overflow builtin ZIR instructions to Extended
make some more room in our ZIR enum tag space
2021-04-24 17:31:15 -07:00
Andrew Kelley
6951889f6e Merge pull request #8608 from LemonBoy/fix-8602
translate-c: Prevent mistranslation of fp literals
2021-04-24 19:55:13 -04:00
Andrew Kelley
15e891823e AstGen: parser ensures all suspend have blocks
See #8603.
2021-04-24 14:41:27 -07:00
Andrew Kelley
1592206965 AstGen: implement await and resume
based on @Vexu's code from before
2021-04-24 14:39:44 -07:00
LemonBoy
cf98dfbe22 Remove translate-c test using long double literal
Removed until the rendering logic is adapted to deal with 80bit (and
bigger) floats, those are used sparingly in the wild so it's not much of
a loss.
2021-04-24 20:35:04 +02:00
Andrew Kelley
e86cee258c Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted the change that makes `suspend;` illegal in the
parser.
2021-04-24 10:44:41 -07:00
Matt Knight
8530b6b724 fix import path 2021-04-24 13:35:55 -04:00
Frank Denis
7a793a9b9d ed25519: use double-base multiplication for signature verification
This makes single signature verification about 60% faster.

Also check that R is not the identity point.
2021-04-24 13:35:36 -04:00
Andrew Kelley
29e5e98eed Merge pull request #8606 from LemonBoy/suspend-block
stage1: Require a block after suspend
2021-04-24 13:34:33 -04:00
LemonBoy
7c3896e6cd translate-c: Prevent mistranslation of fp literals
When trying to retrieve 80bit fp values from clang using
getValueAsApproximateDouble we'd eventually hit the ceiling value and
return infinity, an invalid value for a fp literal.

Add some logic to prevent this error and warn the user.

Closes #8602
2021-04-24 18:42:23 +02:00
LemonBoy
eabf378a56 zig fmt: Automagically fix block-less suspend exprs 2021-04-24 15:37:55 +02:00
LemonBoy
0aede1a8fc stage1: Require a block after suspend
Closes #8603
2021-04-24 10:25:43 +02:00
Andrew Kelley
224fbb23c4 stage2: better error reporting for LazySrcLoc.entire_file
instead of crashing the compilation, uses a plain error message
2021-04-23 23:51:27 -07:00
Andrew Kelley
27fa4bc2be AstGen: support struct init with ref result location 2021-04-23 23:40:10 -07:00
Jakub Konka
4ec6d174ad zld: new approach at handling static inits 2021-04-24 08:13:53 +02:00
Jakub Konka
b00d08b667 zld: add temp debug info fix by setting mtime=0 2021-04-24 08:13:53 +02:00
Jakub Konka
b03983b450 zld: analyze static initializers 2021-04-24 08:13:53 +02:00
Jakub Konka
4f7765de7c zld: common section should be writable 2021-04-24 08:13:53 +02:00
Andrew Kelley
d2b06c2612 stage2: remove call_none and call_none_chkused ZIR
These are unproven optimizations and we need some more room in the
`Zir.Inst.Tag` enum for some more syntax.
2021-04-23 22:43:20 -07:00
Andrew Kelley
6b98384e20 stage2: remove dead ZIR instructions
clearing up some enum tag space for future added instructions
2021-04-23 22:40:57 -07:00
Al Hoang
762d4a959c update haiku system constants 2021-04-23 23:40:42 -05:00
Al Hoang
914d57a1a6 support output collection for haiku 2021-04-23 23:39:13 -05:00
Al Hoang
7a78b92fa0 header path detection for haiku 2021-04-23 23:37:35 -05:00
Andrew Kelley
fbfae832ea AstGen: emit nosuspend function calls
Inside a nosuspend block, emit function calls as nosuspend calls.
Also inside a comptime block, emit function calls as comptime calls.
Also emit `async foo()` calls as async calls.

Remove compile error for `nosuspend` block inside `suspend` block.
Instead of implicitly treating every `suspend` block also as a
`nosuspend` block (which would make sense), we leave suspension points
as compile errors, to hint to the programmer about accidents. Of course
they may then assert `nosuspend` by introducing a block within their
suspend block.

To make room in `Zir.Inst.Tag` I moved `typeof_peer` and `compile_log`
to `Extended`.
2021-04-23 21:12:29 -07:00
Andrew Kelley
49be88859d AstGen: implement nosuspend expressions
Also implement ZIR error notes
2021-04-23 20:31:12 -07:00
Andrew Kelley
9a271347fe AstGen: implement suspend blocks 2021-04-23 20:09:56 -07:00
Andrew Kelley
b40a8efb9a stage2: implement anyframe, anyframe->T and fix assembly
* AstGen: implement `anyframe_literal` and `anyframe_type`.
 * Introduce `makeSubBlock` to avoid redundant AstGen code for GenZir
   scopes. Allows adding/removing a field without possibility of
   accidentally introducing a bug of forgetting to set the new field.
 * Add to GenZir `nosuspend_node` and `suspend_node` in preparation for
   implementing `suspend` blocks and `nosuspend` blocks.
 * AstGen: fix assembly to support clobbers, multiple outputs, and
   outputs without `->` syntax.
   - `asm` and `asm_volatile` move to `Extended` enum with `small` being
     repurposed for a few things. This frees up 2 ZIR tags, 1 of which
     is used in this commit and 1 is leftover.
 * AstGen: fix `simple_types` incorrectly having multiple conflicting
   values for "undefined" and "null".
   - Also add "anyframe" to `simple_types`.
 * Add `anyframe_type` to type.zig, value.zig and `Zir.Inst.Ref`.
   - Also add i128 and u128 types to `Zir.Inst.Ref` and `simple_types`.
 * Sema/Zir: Fix incorrect math causing the function body to be messed
   up for Extended-encoded functions.
 * Zir: support `i32` fields for "extra" payloads.
2021-04-23 18:35:21 -07:00
Andrew Kelley
a279f18bce Merge pull request #8599 from LemonBoy/unsigned-neg
stage1: Allow wrapping negation on unsigned ints at comptime
2021-04-23 16:59:01 -04:00
Hadron67
e86a1df9f2 std.atomic: load should take const pointer to Self 2021-04-23 22:39:49 +02:00
Andrew Kelley
dfb34c3155 Merge pull request #8586 from LemonBoy/ppc32-touchups
A few more PPC32 touch-ups
2021-04-23 15:12:38 -04:00
Andrew Kelley
183ee0965f AstGen: compile error for unable to infer array size 2021-04-23 11:14:11 -07:00
LemonBoy
9ac5f98200 std: Remove unneeded workaround
Now that -% works on unsigned integers at comptime this (clever) hack is
not not needed anymore.
2021-04-23 19:19:44 +02:00
LemonBoy
cc8e49283d stage1: Allow wrapping negation on unsigned ints at comptime
Closes #7951
Closes #8574
2021-04-23 19:15:52 +02:00
Andrew Kelley
0262dda9b8 std: remove comptime const 2021-04-22 23:52:52 -07:00
Andrew Kelley
715abe8ebe AstGen: implement integers bigger than u64
also get rid of the `optional_type_from_ptr_elem` instruction.
2021-04-22 23:47:31 -07:00
Andrew Kelley
2d290d6f82 stage2: write out builtin.zig before spawning AstGen tasks
Otherwise it's possible for AstGen to get FileNotFound when trying to
eager-load `import("builtin")`.
2021-04-22 22:35:18 -07:00
Andrew Kelley
a830ebe718 ZIR: fix text printing of field_ptr_type
Thanks @g-w1
2021-04-22 22:18:53 -07:00
Andrew Kelley
8df4bb7c96 stage2: fix builtin.zig for zig test 2021-04-22 19:48:12 -07:00
jacob gw
ce41ddcd23 std: fix potential bug in parseInt 2021-04-22 22:42:46 -04:00
Andrew Kelley
93d1c2d6d4 std: fix compile errors caught by stage2 AstGen
Follow-up from 507a8096d2
2021-04-22 19:32:57 -07:00
Andrew Kelley
8dd7378013 delete packed enums from the language
No need for any such thing. Instead, provide an integer tag type for the
enum.
2021-04-22 19:21:50 -07:00
Andrew Kelley
329a359974 AstGen: implement align and linksection on globals 2021-04-22 19:21:33 -07:00
Andrew Kelley
507a8096d2 std: fix compile errors caught by stage2 AstGen
* `comptime const` is redundant
 * don't use `extern enum`; specify a tag type.
   `extern enum` is only when you need tags to alias. But aliasing tags
   is a smell. I will be making a proposal shortly to remove `extern enum`
   from the language.
 * there is no such thing as `packed enum`.
 * instead of `catch |_|`, omit the capture entirely.
 * unused function definition with missing parameter name
 * using `try` outside of a function or test
2021-04-22 18:07:46 -07:00
Andrew Kelley
7c453b91b8 AstGen: implement @extern builtin 2021-04-22 16:31:51 -07:00
Andrew Kelley
41efdc73b9 langref: add docs for @extern 2021-04-22 16:24:14 -07:00
Andrew Kelley
3d637e6dd2 AstGen: fix @export
Make it properly use `std.builtin.ExportOptions`.
2021-04-22 16:07:58 -07:00
Andrew Kelley
130ad08001 AstGen: implement function prototypes 2021-04-22 14:24:22 -07:00
Andrew Kelley
389020009a AstGen: implement alignment on locals 2021-04-21 22:43:57 -07:00
Andrew Kelley
ea00ddfe37 AstGen: implement comptime locals 2021-04-21 20:42:49 -07:00
Andrew Kelley
8ee0cbe50a AstGen: fix switch result location elision
It was eliding wrong instructions for nested break from labeled block
2021-04-21 19:49:58 -07:00
Andrew Kelley
570ed7b3bf AstGen: implement @bitCast for other result location types 2021-04-21 19:11:36 -07:00
Andrew Kelley
4cfea2fbd5 AstGen: fix @floatCast having wrong arity
It's not time for #5909 yet.
2021-04-21 19:10:54 -07:00
LemonBoy
6cd71931cb stage1: Unbreak build on FreeBSD
It turns out that the endianness-detection header delivered with the
softfloat library is extremely brittle and gives wrong results when
targeting FreeBSD (long story short, _BIG_ENDIAN is always defined there
and that breaks the #if defined() chain).

Use our own endianness detection header to work around any potential
problem.
2021-04-21 22:07:55 +02:00
LemonBoy
c5cc6b7082 compiler-rt: Export __extendhftf2 and __trunctfhf2
Even though LLVM12 doesn't make use of those intrinsics at the moment
let's export them anyway.
2021-04-21 19:02:13 +02:00
LemonBoy
e0d7cfce5f compiler-rt: Don't re-define PPC builtins in test mode
Prevent linking errors when `zig test`-ing the compiler_rt module for
powerpc-linux triples.
2021-04-21 19:00:57 +02:00
LemonBoy
89d0cc4d8c test: Add 32bit PowerPC to the test plan
Since MIPS is temporarily out of order due to some issues with LLD let's
add PPC32 to have at least one big-endian platform in the testing plan.
2021-04-21 16:31:30 +02:00
LemonBoy
e4f9a3041a std: Use stat definition with 32bit *time fields
We're not ready for Y38K yet.
2021-04-21 16:31:30 +02:00
LemonBoy
d82eb8dd40 std: Split syscall parameters for PowerPC targets 2021-04-21 16:31:29 +02:00
Andrew Kelley
d10ec6e70d AstGen: slightly better eager-allocating heuristic
Some early ensureCapacity calls to avoid needless reallocations.
2021-04-20 22:16:45 -07:00
Jakub Konka
c8753aceef macho: fix typos in consts defs 2021-04-21 06:49:34 +02:00
Andrew Kelley
a1ac2b95bb AstGen: implement union decls 2021-04-20 21:48:18 -07:00
Andrew Kelley
971f3d95f9 AstGen: implement size zero inferred length arrays 2021-04-20 18:32:43 -07:00
Andrew Kelley
c69a95f64b AstGen: fix store_to_block_ptr elision for switch statements
to make sure it matches the expected block
2021-04-20 17:58:04 -07:00
Andrew Kelley
a008fb0a71 std.fs: delete unused label
stage2 starting to catch problems with the standard library :)
2021-04-20 17:57:35 -07:00
Andrew Kelley
e9477048e5 AstGen: implement for loop payload 2021-04-20 17:52:35 -07:00
Andrew Kelley
30c9808391 AstGen: implement anytype parameters 2021-04-20 17:38:06 -07:00
Andrew Kelley
a62db38d90 AstGen: implement defer for break 2021-04-20 17:04:11 -07:00
Andrew Kelley
458c4b6fc6 AstGen: implement defer for continue 2021-04-20 17:04:11 -07:00
Andrew Kelley
a59bcae59f AstGen: basic defer implementation 2021-04-20 17:04:11 -07:00
jacob gw
b4aec0e31d stage2: make std.fmt.parseInt ignore _ 2021-04-20 17:08:05 -04:00
jacob gw
6b944492b5 stage2: fix compile error in codegen 2021-04-20 17:08:05 -04:00
Michael Dusan
0c6dfa6f0c target: drop ppc32 and prefer ppc
- original PR #7949 (incorrectly) patched a generated-file and changes
  have subsequently been lost/overwritten
- fix #7947 in a different way: drop `ppc32` because `ppc` already exists
2021-04-20 16:19:59 -04:00
Andrew Kelley
b4baa9eda2 AstGen: try fixups
Primarily this required fixing `setCondBrPayloadElideBlockStorePtr` to
not assume there would always be two `store_to_block_ptr` instructions
in each of the condbr prongs.
2021-04-20 11:16:50 -07:00
Frank Denis
10f2d62789 std/crypto: use finer-grained error sets in function signatures (#8558)
std/crypto: use finer-grained error sets in function signatures

Returning the `crypto.Error` error set for all crypto operations
was very convenient to ensure that errors were used consistently,
and to avoid having multiple error names for the same thing.

The flipside is that callers were forced to always handle all
possible errors, even those that could never be returned by a
function.

This PR makes all functions return union sets of the actual errors
they can return.

The error sets themselves are all limited to a single error.

Larger sets are useful for platform-specific APIs, but we don't have
any of these in `std/crypto`, and I couldn't find any meaningful way
to build larger sets.
2021-04-20 19:57:27 +02:00
Andrew Kelley
1e06a74348 Merge pull request #8542 from LemonBoy/floating-point-is-hard-my-dude
Floating point is hard my dude
2021-04-20 13:28:03 -04:00
jacob gw
ee3c1c763c stage2: astgen try 2021-04-20 13:16:08 -04:00
Veikka Tuominen
2ca26ffde7 Merge pull request #8582 from LemonBoy/more-libc-impl
Improve the libc implementation
2021-04-20 19:54:16 +03:00
Jakub Konka
d64c76e8f1 zld: fix parsing of weak symbols 2021-04-20 16:55:32 +02:00
Jakub Konka
7bc6554a58 zld: map __DATA,__common as __DATA_CONST,__common 2021-04-20 16:55:32 +02:00
Jakub Konka
e5b83056ae zld: resolve symbols as globals before resolving locals 2021-04-20 16:55:32 +02:00
Jakub Konka
8943a0aaaa zld: dedup initializers and finalizers 2021-04-20 16:55:32 +02:00
Jakub Konka
3e73a3c29b zld: treat priv extern as weak symbol 2021-04-20 16:55:32 +02:00
LemonBoy
a5a3ad5e10 c: Minor cleanup
* Remove superfluous "test_" prefix in test names
* Use aliased isNan everywhere
2021-04-20 15:44:54 +02:00
LemonBoy
a4e2539b09 c: Implement fmax and fmaxf 2021-04-20 15:44:21 +02:00
LemonBoy
fcfe25710b c: Implement fmin and fminf 2021-04-20 15:43:46 +02:00
LemonBoy
c7c77fb1b0 c: Add tests for generic_fmod implementation 2021-04-20 15:43:01 +02:00
LemonBoy
be551d85b7 translate-c: Group field access LHS if necessary 2021-04-20 15:16:25 +03:00
Evan Haas
63304a871e translate-c: group LHS of array access if necessary 2021-04-20 11:33:01 +03:00
Evan Haas
55e6bd10fe translate-c: use transCreateNodeInfixOp for pointer arithmetic 2021-04-20 11:33:01 +03:00
Andrew Kelley
e315120b79 AstGen: implement array initialization expressions 2021-04-19 23:23:24 -07:00
Andrew Kelley
693dbeeef2 stage2: make @alignCast accept 2 parameters
It is not yet time to implement #5909.
2021-04-19 18:46:45 -07:00
Andrew Kelley
4630e3891c AstGen: implement inline asm output 2021-04-19 18:44:59 -07:00
Andrew Kelley
a136c093bf zig astgen: print instruction counts and byte sizes 2021-04-19 16:23:05 -07:00
Andrew Kelley
7f931a7522 AstGen: implement error set decls 2021-04-19 16:03:46 -07:00
Andrew Kelley
2083208f19 AstGen: implement functions with inferred error sets
This commit also reclaims +2 ZIR instruction tags by moving the
following to `extended`:
 * func_var_args
 * func_extra
 * func_extra_var_args
The following ZIR instruction tag is added:
 * func_inferred
2021-04-19 15:03:41 -07:00
Andrew Kelley
22015c1b3b std.MultiArrayList: ensureUnusedCapacity/ensureTotalCapacity
Same as c8ae581fef, but for
MultiArrayList.
2021-04-19 15:02:37 -07:00
Isaac Freund
e2cc02717e Fix .gitattributes rules that should be recursive
These are currently incorrect according to the gitattributes(5) and
gitignore(5) man pages. However, it seems github ended up treating them
as we intended due to a bug until recently when that bug was fixed.
2021-04-19 16:55:12 -04:00
Andrew Kelley
27d4bea9a4 AstGen: implement if optional, if error union 2021-04-19 12:25:16 -07:00
Andrew Kelley
3dadccec45 AstGen: implement while optional and while error union 2021-04-19 12:02:11 -07:00
Andrew Kelley
3f60481be4 AstGen: implement the remaining struct init ResultLoc forms 2021-04-19 11:09:00 -07:00
Hubert Jasudowicz
d605f02756 std: Add process_vm_readv/writev wrappers 2021-04-19 16:12:28 +02:00
Andrew Kelley
ae495de54d AstGen: implement all the builtin functions 2021-04-18 22:38:41 -07:00
joachimschmidt557
fbda9991f4 stage2 codegen: Fix silent bug in reuseOperand 2021-04-17 20:57:26 -04:00
Isaac Freund
4081e0a475 zig fmt: bypass auto indentation for // zig fmt: on
Currently an indented `// zig fmt: on` will be indented an additional
time on every run of zig fmt.
2021-04-17 20:10:20 -04:00
Andrew Kelley
5a3045b5de AstGen: implement overflow arithmetic builtins 2021-04-17 13:00:10 -07:00
Isaac Freund
8e6865c8ee std/build: fix linker_allow_shlib_undefined
The relevant flags were renamed in 01a1365 but updating std.build
was overlooked.
2021-04-17 15:17:54 +02:00
Frank Denis
9f6b56ab4b Merge pull request #8555 from chivay/pidfd
std: Add pidfd wrappers
2021-04-17 15:03:25 +02:00
jacob gw
afb9f695b1 stage2: add support for zig cc assembler -mcpu option 2021-04-17 02:00:07 -04:00
Andrew Kelley
8cf0ef2779 AstGen: implement simple enums and decls for enums 2021-04-16 22:21:26 -07:00
Andrew Kelley
0409d433ba AstGen: fix compile error using wrong node/token function 2021-04-16 19:49:19 -07:00
Andrew Kelley
e13fc6b119 stage2: make @import relative to the current file
previously, it was incorrectly relative to the package directory
2021-04-16 19:45:58 -07:00
Andrew Kelley
415ef1be51 AstGen: fix function decl astgen
it was using the wrong scope and other mistakes too
2021-04-16 19:45:24 -07:00
Andrew Kelley
dd5a1b1106 build.zig: add a way to skip installing lib/ files 2021-04-16 18:58:27 -07:00
Andrew Kelley
9375ad0d3b AstGen: implement global var decls
And fix bug with using `ensureCapacity` when I wanted
`ensureUnusedCapacity`.
2021-04-16 17:57:51 -07:00
Andrew Kelley
c8ae581fef std: deprecate ensureCapacity, add two other capacity functions
I've run into this footgun enough times, nearly every time I want
`ensureUnusedCapacity`, not `ensureCapacity`. This commit deprecates
`ensureCapacity` in favor of `ensureTotalCapacity` and introduces
`ensureUnusedCapacity`.
2021-04-16 17:56:30 -07:00
Andrew Kelley
5ff45b3f44 stage2: use import list from ZIR to queue up more AstGen tasks 2021-04-16 17:28:28 -07:00
Andrew Kelley
a271f12a14 AstGen: store list of imports 2021-04-16 16:20:29 -07:00
Hubert Jasudowicz
5134fb72ef std: Add pidfd wrappers 2021-04-17 01:13:16 +02:00
Andrew Kelley
edd75d03e3 ZIR: rename decl_val and decl_ref to remove redundant suffix 2021-04-16 15:52:26 -07:00
Andrew Kelley
adc2aed587 AstGen: require @import operand to be string literal
See #2206
2021-04-16 15:50:28 -07:00
Andrew Kelley
333a577d73 AstGen: put decls into blocks to be evaluated independently 2021-04-16 15:34:09 -07:00
Isaac Freund
01a1365857 Rename --(no-)allow-shilb-undefined to -f(no-)allow-shilb-undefined
This breaks with GNU ld but is consistent with our naming convention for
all the rest of the flags.
2021-04-17 00:03:35 +02:00
Andrew Kelley
01b4bf34ea stage2: AstGen improvements
* AstGen: represent compile errors in ZIR rather than returning
   `error.AnalysisFail`.
 * ZIR: remove decl_ref and decl_val instructions. These are replaced by
   `decl_ref_named` and `decl_val_named`, respectively, which will
   probably get renamed in the future to the instructions that were just
   deleted.
 * AstGen: implement `@This()`, `@fence()`, `@returnAddress()`, and
   `@src()`.
 * AstGen: struct_decl improved to support fields_len=0 but have decls.
 * AstGen: fix missing null bytes after compile error messages.
 * SrcLoc: no longer depend on `Decl`. Instead have an explicit field
   `parent_decl_node` which is an absolute AST Node index.
 * Module: `failed_files` table can have null value, in which case the
   key, which is a `*Scope.File`, will have ZIR errors in it.
 * ZIR: implement text rendering of struct decls.
 * CLI: introduce debug_usage and `zig astgen` command which is enabled
   when the compiler is built in debug mode.
2021-04-16 14:48:10 -07:00
daurnimator
99e7ba24b1 Add LibExeObjStep.linker_allow_shlib_undefined field to set --allow-shlib-undefined 2021-04-16 22:51:51 +02:00
daurnimator
0e687d125b Add --(no-)allow-shlib-undefined to supported zig linking flags 2021-04-16 22:51:51 +02:00
Andrew Kelley
140d9df99b Merge pull request #8506 from LemonBoy/test-c-file
build: Test the c.zig file too
2021-04-16 13:03:52 -04:00
joachimschmidt557
5edabb3990 stage2 register manager: Add functions for allocating multiple registers 2021-04-16 13:03:10 -04:00
Manuel Floruß
2cd49d20e8 Fix std.os.windows.user32.messageBoxW
Arguments to `selectSymbol` were passed in the wrong order.
2021-04-16 13:01:25 -04:00
Andrew Kelley
235aa8c078 ci: drone: don't skip stage2 tests
the stalls seem to be happening for a different reason
2021-04-16 09:57:31 -07:00
Mahdi Khanalizadeh
d1a41feddc linux: fix number of arguments for tgkill syscall 2021-04-16 17:09:15 +02:00
gracefu
cfeb412a42 stage2 x86_64: fix incorrect comment in genX8664BinMath
Co-authored-by: joachimschmidt557 <joachim.schmidt557@outlook.com>
2021-04-16 15:21:17 +08:00
gracefu
dc13662725 stage2 x86_64: force 64 bit mode when loading address of GOT
Co-authored-by: joachimschmidt557 <joachim.schmidt557@outlook.com>
2021-04-16 15:21:17 +08:00
gracefu
1e63e8d8b6 stage2 x86_64: fix codegen ensureCapacity bug for function calls
Co-authored-by: joachimschmidt557 <joachim.schmidt557@outlook.com>
2021-04-16 15:21:17 +08:00
gracefu
62e755623f stage2 x86_64: bugfix abi_size == 64 should be abi_size == 8 2021-04-16 15:21:17 +08:00
gracefu
b004c3da15 stage2 x86_64: try to fix RIP-relative offset to GOT for macho 2021-04-16 15:21:17 +08:00
gracefu
0409f9e024 stage2 x86_64: simplify inst encoder to a set of dumb helper fns 2021-04-16 15:21:17 +08:00
gracefu
613f39eb62 stage2 x86_64: fix comptime integer multiplication when rhs=0
Co-authored-by: joachimschmidt557 <joachim.schmidt557@outlook.com>
2021-04-16 15:21:17 +08:00
gracefu
c4b83ea021 stage2 x86_64: implement integer mul
This was also an experiment to see if it were easier to implement a new
feature when using the instruction encoder.

Verdict: It's not that much easier, but I think it's certainly much more
readable, because the description of the Instruction annotates what each
field means. Right now, precise knowledge of x86_64 instructions is
still required because things like when to set the 64-bit flag, how to
read x86_64 instruction references, etc. are still not automatically
done for you.

In the future, this interface might make it sligtly easier to write an
assembler for x86_64, by abstracting the bit-fiddling aspects of
instruction encoding.
2021-04-16 15:21:17 +08:00
gracefu
5bd464e386 stage2 x86_64: use abi size to determine 64-bit operation
From my very cursory reading, it seems that the register manager doesn't
distinguish between registers that are physically the same but have
different sizes.

In that case, this means that during codegen, we can't rely on
`reg.size()` when determining the width of the operations we have to
perform. Instead, we must use some form of `ty.abiSize(self.target.*)`
to determine the size of the type we're operating with. If this size is
64 bits, then we should enable 64-bit operation.

This fixed a bug in the codegen for spilling instructions, which was
overwriting the previous stack entry with zeroes. See the modified test
case in this commit.
2021-04-16 15:21:17 +08:00
gracefu
36df1526da stage2 x86_64: refactor codegen to use inst encoder
There are parts of it that I didn't modify because the byte
representation was important (e.g. we need to know what the exact
byte position where we store the address into the offset table is)
2021-04-16 15:21:17 +08:00
gracefu
e1959ccd4e stage2 x86_64: add instruction encoder helper fn 2021-04-16 15:21:16 +08:00
Andrew Kelley
cf57e8223f AstGen: implement comptimeDecl, usingnamespaceDecl, testDecl 2021-04-15 20:55:54 -07:00
Andrew Kelley
8387307807 AstGen: implement global variable decls 2021-04-15 20:34:21 -07:00
Evan Haas
d4d21dd46d translate-c: better handling of int -> enum casts
In std.meta.cast when casting to an enum type from an integer type, first
do a C-style cast from the source value to the tag type of the enum.
This ensures that we don't get an error due to the source value not being
representable by the enum.

In transCCast() use std.meta.cast instead of directly emitting the cast
operation since the enum's underlying type may not be known at translation
time due to an MSVC bug, see https://github.com/ziglang/zig/issues/8003

Fixes #6011
2021-04-15 22:46:22 -04:00
Andrew Kelley
7818586a2b fix new references to std.builtin that should have been std.Target 2021-04-15 19:14:54 -07:00
Andrew Kelley
f37451a63a stage2: fix zir.zig => Zir.zig in CMakeLists.txt 2021-04-15 19:12:05 -07:00
Andrew Kelley
3114115348 stage2: preliminary reworking for whole-file-AstGen
See #8516.

 * AstGen is now done on whole files at once rather than per Decl.

 * Introduce a new wait group for AstGen tasks. `performAllTheWork`
   waits for all AstGen tasks to be complete before doing Sema,
   single-threaded.
   - The C object compilation tasks are moved to be spawned after
     AstGen, since they only need to complete by the end of
     the function.

With this commit, the codebase compiles, but much more reworking is
needed to get things back into a useful state.
2021-04-15 19:06:39 -07:00
Andrew Kelley
9088d40e83 stage2: rename zir to Zir
since it now uses top level fields
2021-04-15 19:06:39 -07:00
Andrew Kelley
0170a242bb stage2: move zir.Code to become root level fields of zir.zig
next commit will do the rename
2021-04-15 19:06:39 -07:00
Andrew Kelley
798ad631f3 stage2 start.zig: slight simplification
fewer required language features to allow this to work
2021-04-15 19:06:39 -07:00
Andrew Kelley
6dba9bc6fc stage2: implement @bitSizeOf 2021-04-15 19:06:39 -07:00
Andrew Kelley
df983b30d2 stage2: implement comptime division 2021-04-15 19:06:39 -07:00
Andrew Kelley
69645e2817 stage2: implement @sizeOf 2021-04-15 19:06:39 -07:00
Andrew Kelley
0e50a0c1e5 stage2: implement non-trivial enums 2021-04-15 19:06:39 -07:00
Andrew Kelley
bcfebb4b2b stage2: improvements aimed at std lib integration
* AstGen: emit decl lookup ZIR instructions rather than directly
   looking up decls in AstGen. This is necessary because we want to
   reuse the same immutable ZIR code for multiple generic instantiations
   (and comptime function calls).
 * AstGen: fix using members_len instead of fields_len for struct decls.
 * structs: the struct_decl ZIR instruction is now also a block. This is
   so that the type expressions, default field value expressions, and
   alignment expressions can be evaluated in a scope that contains the
   decls from the struct namespace itself.
 * Add "std" and "builtin" packages to the builtin package.
 * Don't try to build glibc, musl, or mingw-w64 when using `-ofmt=c`.
 * builtin.zig is generated without `usingnamespace`.
 * builtin.zig takes advantage of `std.zig.fmtId` for CPU features.
 * A first pass at implementing `usingnamespace`. It's problematic and
   should either be deleted, or polished, before merging this branch.
 * Sema: allow explicitly specifying the namespace in which to look up
   Decls. This is used by `struct_decl` in order to put the decls from
   the struct namespace itself in scope when evaluating the type
   expressions, default value expressions, and alignment expressions.
 * Module: fix `analyzeNamespace` assuming that it is the top-level root
   declaration node.
 * Sema: implement comptime and runtime cmp operator.
 * Sema: implement peer type resolution for enums and enum literals.
 * Pull in the changes from master branch:
   262e09c482.
 * ZIR: complete out simple_ptr_type debug printing
2021-04-15 19:06:39 -07:00
Andrew Kelley
429cd2b5dd std: change @import("builtin") to std.builtin 2021-04-15 19:06:39 -07:00
Andrew Kelley
a4bb7c8bb1 stage2: remove redundant source hash 2021-04-15 19:06:39 -07:00
Andrew Kelley
f458192e56 stage2: entry point via std lib and proper updated file detection
Instead of Module setting up the root_scope with the root source file,
instead, Module relies on the package table graph being set up properly,
and inside `update()`, it does the equivalent of `_ = @import("std");`.
This, in term, imports start.zig, which has the logic to call main (or
not). `Module` no longer has `root_scope` - the root source file is no
longer special, it's just in the package table mapped to "root".

I also went ahead and implemented proper detection of updated files.
mtime, inode, size, and source hash are kept in `Scope.File`.
During an update, iterate over `import_table` and stat each file to find
out which ones are updated.

The source hash is redundant with the source hash used by the struct
decl that corresponds to the file, so it should be removed in a future
commit before merging the branch.

 * AstGen: add "previously declared here" notes for variables shadowing
   decls.
 * Parse imports as structs. Module now calls `AstGen.structDeclInner`,
   which is called by `AstGen.containerDecl`.
   - `importFile` is a bit kludgy with how it handles the top level Decl
     that kinda gets merged into the struct decl at the end of the
     function. Be on the look out for bugs related to that as well as
     possibly cleaner ways to implement this.
 * Module: factor out lookupDeclName into lookupIdentifier and lookupNa
 * Rename `Scope.Container` to `Scope.Namespace`.
 * Delete some dead code.

This branch won't work until `usingnamespace` is implemented because it
relies on `@import("builtin").OutputMode` and `OutputMode` comes from a
`usingnamespace`.
2021-04-15 19:06:39 -07:00
Andrew Kelley
ccdf55310b stage2: properly model miscellaneous failed tasks
with error messages that go away after updates
2021-04-15 19:01:55 -07:00
Andrew Kelley
2b2920f599 ci: drone: disable stage2 tests
See #8545
2021-04-15 16:20:43 -07:00
LemonBoy
bd4421befe compiler-rt: Don't pass f16 around as arguments
Fixes some failures on AArch64.
f16 was a mistake.
2021-04-15 21:52:08 +02:00
Andrew Kelley
c795e82cbc ci: windows: update to llvm 12 msvc tarball 2021-04-15 12:40:22 -07:00
Andrew Kelley
c49fe52cb1 ci: update macos tarball to llvm 12 2021-04-15 11:27:02 -07:00
Andrew Kelley
68e69aae2b build.zig: omit LLVMTableGen from llvm libs 2021-04-15 10:58:53 -07:00
Andrew Kelley
2a6ec2e155 build.zig: update llvm libs 2021-04-15 10:43:39 -07:00
LemonBoy
5bc1dc59e6 compiler-rt: Implement __trunctfhf2 2021-04-15 18:23:09 +02:00
LemonBoy
b29677dd12 compiler-rt: Implement __extendhftf2 2021-04-15 18:21:58 +02:00
LemonBoy
7a4dad7e87 stage1: More precise serialization of f16 values
Taking a detour trough a f64 is dangerous as the softfloat library
doesn't like converting sNaN values.

The error went unnoticed as an exception is raised by the library but
the stage1 compiler doesn't give a damn.
2021-04-15 18:17:31 +02:00
LemonBoy
2d00f17d15 test: Add test to ensure signed zeros are properly computed
Ensure everything's ok at comptime and runtime.
2021-04-15 18:17:21 +02:00
LemonBoy
8e0b2f0e52 compiler-rt: Fix typo in implementation of fp truncation ops
The problem went unnoticed for years, yay.
2021-04-15 18:14:25 +02:00
LemonBoy
f9481402f0 stage1: Fix negation for zero floating point values
Toggling the sign by computing 0-x doesn't really work for zero values.
2021-04-15 18:12:11 +02:00
Andrew Kelley
a38042e3ac ci: windows: proper flags to zig build 2021-04-15 02:02:36 -07:00
Andrew Kelley
fa633a658f ci: windows: try the dev kit strategy 2021-04-15 01:44:17 -07:00
Andrew Kelley
4a1d3465cc ci: windows: ranlib take 2 2021-04-15 01:22:42 -07:00
Andrew Kelley
3266f326de ci: windows: better -DCMAKE_RANLIB option 2021-04-15 01:14:33 -07:00
Andrew Kelley
04b8354702 freebsd: disable failing test
See #8538
2021-04-15 00:59:40 -07:00
Andrew Kelley
996193c228 ci: freebsd: don't try to compile with zig cc 2021-04-15 00:51:26 -07:00
Andrew Kelley
a680c7ba98 ci: windows: use llvm-ar.exe from the tarball 2021-04-15 00:41:30 -07:00
Andrew Kelley
c59241bda0 ci: better handle of -mcpu 2021-04-15 00:18:21 -07:00
Andrew Kelley
553fbeba82 ci: better target triple and mcpu cmake args 2021-04-14 23:49:16 -07:00
Andrew Kelley
85755c51d5 ci: freebsd: set the target triple 2021-04-14 23:35:51 -07:00
Andrew Kelley
df319db058 ci: windows: install git 2021-04-14 23:18:03 -07:00
Andrew Kelley
3967823f3a ci: freebsd: pass -DZIG_USE_LLVM_CONFIG=OFF 2021-04-14 23:17:08 -07:00
Andrew Kelley
ee42178b43 ci: aarch64-linux: disable run-translated-c tests
See #8537
2021-04-14 23:10:51 -07:00
Andrew Kelley
45eb9554c4 ci: windows: try using zig-bootstrap to build zig 2021-04-14 23:03:16 -07:00
Andrew Kelley
406353103a ci: freebsd: update to llvm 12 2021-04-14 22:59:34 -07:00
Andrew Kelley
1438c324a4 ci: update drone CI to llvm 12 2021-04-14 21:18:23 -07:00
Andrew Kelley
391a40d601 ci: update linux to llvm12 tarball 2021-04-14 20:35:33 -07:00
Michael Dusan
6a7f21d1b8 ci: macos-aarch64 update dep tarballs for llvm12 2021-04-14 19:43:17 -07:00
lithdew
81adcd533e os/posix: handle ECONNRESET for write/writev 2021-04-14 16:40:06 -07:00
Andrew Kelley
5a3ea9bece Merge remote-tracking branch 'origin/llvm12'
Happy LLVM 12 Release Day.

Please note that the llvm 12 tag does not include the latest commit in
the release/12.x branch, which is in fact a bug fix for a regression
that is causing a failure in Zig's test suite.

Zig master branch is tracking release/12.x, and will be enabling the
test that is fixed by that commit.
2021-04-14 14:41:57 -07:00
LemonBoy
2ebd6bd706 std: Fix sqrt for u0/u1 input types 2021-04-14 17:53:27 +02:00
LemonBoy
ebf97627fd build: Test the c.zig file too
* Add some more tests for the sqrt/sqrtf implementations.
  The idea is to cross-check the software impl with the HW one whenever
  possible.
* Fix a broken test, oops.
2021-04-14 17:53:26 +02:00
Frank Denis
1fada37466 Merge pull request #8518 from akvadrako/doc-field-align
Update doc for struct field alignment.
2021-04-14 10:56:37 +02:00
Evan Haas
e761e0ac18 translate-c: wrap switch statements in a while (true) loop
This allows `break` statements to be directly translated from the original C.
Add a break statement as the last statement of the while loop to ensure we
don't have an infinite loop if no breaks / returns are hit in the switch.

Fixes #8387
2021-04-13 11:45:03 -07:00
Jakub Konka
36a33c99e3 Merge pull request #8517 from ziglang/zld-archive-fix
zld: fix symbol resolution from interdependent static archives
2021-04-13 17:12:26 +02:00
Devin Bayer
ca3aa02206 Update doc for struct field alignment. 2021-04-13 14:53:44 +02:00
Jakub Konka
461543a5fd zld: fix symbol resolution from interdep archives
Fixes symbol resolution if an archive occurring later in the linker
line depends on a object embedded within the archive that occurred
before.
2021-04-13 13:36:08 +02:00
Jakub Konka
65e4725aba Add standalone test for interdep C archives
Tests a scenario where the linker line has the following:

```
main.o libA.a libB.a
```

where `main.o` pulls a symbol from `libB.a`, which in turn is
dependent on a symbol from `libA.a`.
2021-04-13 13:32:59 +02:00
Jakub Konka
a5bbc66f10 zld: cleanup redundant changes 2021-04-13 10:56:03 +02:00
Jakub Konka
db30033de2 zld: rebase to new naming conv for aarch64 2021-04-13 10:56:03 +02:00
Jakub Konka
1119970d22 zld: add x86_64 relocs 2021-04-13 10:56:03 +02:00
Jakub Konka
b1f9db75f3 zld: save locals per TU 2021-04-13 10:56:03 +02:00
Jakub Konka
3b7c9dd6bd zld: differentiate between static and global in stabs 2021-04-13 10:56:03 +02:00
Jakub Konka
717d382871 zld: streamline tags for Symbol 2021-04-13 10:56:03 +02:00
Jakub Konka
b377e0b370 zld: fix indirect symtab 2021-04-13 10:56:03 +02:00
Jakub Konka
b0a4e1fa46 zld: fix rebase vs bind for GOT entries 2021-04-13 10:56:03 +02:00
Jakub Konka
6e3f82ef28 zld: fix parsing debug info 2021-04-13 10:56:03 +02:00
Jakub Konka
65c27d51f6 zld: limit exports to just main entrypoint 2021-04-13 10:56:03 +02:00
Jakub Konka
421102ba72 zld: move parsing debug info into object 2021-04-13 10:56:03 +02:00
Jakub Konka
dc7cff8ebc zld: add prelim support for locals 2021-04-13 10:56:03 +02:00
Jakub Konka
23bb6fa9f4 zld: flush MachO 2021-04-13 10:56:03 +02:00
Jakub Konka
db44a7803f zld: resolve target addresses for relocs 2021-04-13 10:56:03 +02:00
Jakub Konka
b667fe2c62 zld: resolve stubs and GOT entries 2021-04-13 10:56:03 +02:00
Jakub Konka
46cc214f2d zld: migrate parts of main to new relocs 2021-04-13 10:56:03 +02:00
Jakub Konka
6a866f1a96 zld: preprocess relocs on arm64 2021-04-13 10:56:03 +02:00
Jakub Konka
4e676ecbb5 zld: allocate addresses for global symbols 2021-04-13 10:56:03 +02:00
Jakub Konka
d5c2f8ed32 zld: store a single global symtab 2021-04-13 10:56:03 +02:00
Jakub Konka
1b5bceec91 zld: start work on reloc preprocessing 2021-04-13 10:56:03 +02:00
Jakub Konka
04659f5b82 zld: allocate segments based on worst-case and upper-limit 2021-04-13 10:56:03 +02:00
Jakub Konka
116ea1bf2c zld: assume remaining undefs are from libSystem 2021-04-13 10:56:03 +02:00
Jakub Konka
b0105029ca zld: refactor object and archive parsing 2021-04-13 10:56:03 +02:00
Jakub Konka
988b184d03 zld: redo symbol resolution in objects
Store only globals and undefs at the linker level, while all locals
stay scoped to the actual object file they were defined in. This is
fine since the relocations referencing locals will always be resolved
first using the local symbol table before checking for the reference
within the linker's global symbol table.

This also paves the way for proper symbol resolution from within static
and dynamic libraries.
2021-04-13 10:56:03 +02:00
Andrew Kelley
262e09c482 stage1: resolve builtin types and values via std.builtin
rather than via `@import("builtin")`. This helps avoid the need for
`usingnamespace` used in builtin.zig or in std.builtin.
2021-04-12 15:54:28 -07:00
Michael Dusan
cc186dac65 test-stack-traces: enable elf/dwarf platforms 2021-04-12 17:18:56 -04:00
Michael Dusan
28ae498254 dwarf: fix LineNumberProgram check
- on first iteration populate `prev_` fields and do nothing else

closes #8421
2021-04-12 17:18:56 -04:00
Andrew Kelley
c4c7cb252a Merge pull request #8502 from xackus/std-docs
std docs: @This() in generic types
2021-04-12 11:37:00 -07:00
Jakub Konka
d6d27d51ef CI: update brew before installing pkgs 2021-04-12 18:42:51 +02:00
Michael Dusan
0fa1a2cb73 Revert "dwarf: fix LineNumberProgram check"
- needed/needs to go through review process

This reverts commit 746f65f8b3.
2021-04-12 06:55:12 -04:00
Michael Dusan
746f65f8b3 dwarf: fix LineNumberProgram check
- tolerate out-of-order DW_AT_ranges

closes #8421
2021-04-12 06:12:00 -04:00
xackus
ab991cab84 std docs: @This() in generic types 2021-04-12 09:31:45 +02:00
Andrew Kelley
d2d4df4074 Merge pull request #8477 from joachimschmidt557/stage2-arm
stage2 codegen: Set MCValue of register arguments to their stack copies
2021-04-11 19:00:25 -07:00
Andrew Kelley
c5e662d860 Merge pull request #8497 from LemonBoy/some-ppc-fixes
Improve Improve PowerPC support
2021-04-11 18:59:31 -07:00
Michael Dusan
93cf9560b1 Merge remote-tracking branch 'origin/master' into llvm12 2021-04-11 17:40:19 -04:00
xackus
7857ad78db std docs: update var to anytype 2021-04-11 22:59:30 +02:00
LemonBoy
44f8ce690d std: Fix typo in sqrt implementation
The code initializes twice `t` instead of `t1`, leaving the latter
uninitialized. The problem manifested itself by corrupting the LSBs of
the result in unpredictable ways.
2021-04-11 21:27:39 +02:00
LemonBoy
8d94dc625b compiler-rt: Introduce PowerPC-specific f128 helpers
For historical reasons IEEE f128 ops use `kf` instead of `tf` in their
names, there's no functional change.
2021-04-11 21:26:22 +02:00
LemonBoy
9bebdc77d6 std: Fix TLS definitions for 32bit PowerPC targets
Correct some silly errors and add the missing piece to set the thread
pointer (r2).
2021-04-11 21:26:22 +02:00
xackus
89c41f30c3 zig fmt 2021-04-11 20:16:17 +02:00
Andrew Kelley
82a31aac9b Merge pull request #8483 from fengb/powerpc
Improve PowerPC support
2021-04-11 10:12:02 -07:00
LemonBoy
d97981f6fd std: Make a test-case independent of the target endianness 2021-04-11 18:38:04 +02:00
xackus
a5007d819a std.meta: add isError 2021-04-11 16:26:29 +02:00
Michael Dusan
cab1d5c1a3 azure: OnMasterSuccess dependsOn BuildMacOS_arm64 2021-04-11 05:17:18 -04:00
joachimschmidt557
4fe575f47b stage2 ARM: Add fibonacci test 2021-04-11 10:19:36 +02:00
joachimschmidt557
a6ddc12b33 stage2 codegen: Set MCValue of register arguments to their stack copy 2021-04-11 10:19:35 +02:00
Michael Dusan
c676c21824 ci: remove superfluous linefeed from macos arm64 2021-04-11 01:33:17 -04:00
Benjamin Feng
073d8e55c3 Initialize the ppc stack frame correctly 2021-04-10 22:47:22 -05:00
Benjamin Feng
2e85eb2bf8 Rename time32 syscalls to match rest of stdlib 2021-04-10 22:47:22 -05:00
Benjamin Feng
ae3a0ff2d1 _start assembly for ppc 2021-04-10 22:47:22 -05:00
Benjamin Feng
b409accc96 Copy over ppc clone from musl 2021-04-10 22:47:22 -05:00
Benjamin Feng
df910b33f4 Add ppc Linux bits 2021-04-10 22:47:22 -05:00
Michael Dusan
d99dc21b9f test: overhaul stack_trace testing
- limit expected-output to main source file;
  ie. tolerate changes to start.zig
- when mode != .Debug the function name is now symbolically represented;
  ie. tolerate changes in llvm optimizer effects on the callstack
- cleanup how test cases are specified
- add test case predicates for excluding by arch, os or custom fn
2021-04-10 23:20:06 -04:00
Michael Dusan
75f86dab3f macos: add aarch64 (arm64) to downloads page 2021-04-10 19:33:17 -07:00
Isaac Freund
5b9ea5dd1e zig fmt: fix line comment detection
Previously hasComment() would consider a string literal "//" to be a
line comment. Fix this by only searching the bytes between tokens.
2021-04-10 23:10:24 +02:00
Carlos Zúñiga
ecd38c70cc Fix langref.html anchor navigation 2021-04-10 12:51:39 -07:00
Meghan Denny
ab43f2376e lib/std: remove empty init from HashMapUnmanaged 2021-04-10 12:49:02 -07:00
Lewis Gaul
ecf555c693 zig fmt: render array init on one line if no trailing comma
Continue to insert a trailing comma if there is a comment or multiline
string literal present.
2021-04-10 16:39:26 +02:00
Andrew Kelley
86b31394c9 Merge pull request #8482 from mshockwave/dev-llvm-newpm
Switch to new LLVM PassManager
2021-04-09 17:21:06 -07:00
Min-Yih Hsu
52d871844c llvm new-pm: Build O0 pipeline in the correct way
Use `PassBuilder::buildO0DefaultPipeline` to build pipeline for -O0
in replacement of `PassBuilder::buildPerModuleDefaultPipeline`. This
affects both normal and LTO settings.

Two redundant Passes - which were added by accident - were also removed
from LTO pipeline.
2021-04-09 16:51:35 -07:00
Min-Yih Hsu
6b3eaa62e8 Revert "Revert back to the old LLVM PassManager"
This reverts commit 09008125e7.
2021-04-09 16:51:35 -07:00
jacob gw
0d92bd474f stage2: fix case where public variables did not work 2021-04-09 11:54:38 -07:00
Andrew Kelley
b3f5d4dc4c stage2: fix regression from previous commit
I forgot to build, sorry about that.
2021-04-09 10:38:44 -07:00
Andrew Kelley
7c4c5495be stage2: fix stderr deadlock and slightly wrong tty coloring 2021-04-09 10:34:10 -07:00
Andrew Kelley
f75cdd1acd Merge pull request #8470 from ziglang/stage2-start
stage2: blaze the trail for std lib integration
2021-04-09 10:15:46 -07:00
Andrew Kelley
952032b40c Merge pull request #8439 from Luukdegram/wasm-mem
stage2: wasm - "Hello world"
2021-04-09 10:08:21 -07:00
jacob gw
afe5862111 stage2: add error for private decls accessed from other files 2021-04-09 10:05:15 -07:00
LemonBoy
bfc8500390 testing: Avoid @import-ing builtins module
Use std.builtins instead.
2021-04-09 10:04:16 -07:00
LemonBoy
b0e905a30d testing: Avoid printing expected line twice
When the line has trailing whitespace we already print it with a
carriage return symbol at the end, don't print it one more time.
2021-04-09 10:04:16 -07:00
LemonBoy
1943c2dc68 testing: Use indexOfScalar instead of indexOf 2021-04-09 10:04:16 -07:00
LemonBoy
5ebcd8ccaf zig fmt: Fix rendering of arrays with single row
rowSize used to return null if all the elements were placed on the same
line as the right brace, making the rendering logic skip the whole set
of elements.

Given the usage of rowSize let's just drop the null and always return
the number of elements.

Fixes #8423
2021-04-09 10:03:45 -07:00
Luuk de Gram
eaaf75c157 Fix memory cleanup and update unplugging to avoid infinite loop 2021-04-09 09:24:52 +02:00
Andrew Kelley
cc525bc002 Merge pretty printing compile errors branch 2021-04-09 00:20:26 -07:00
Andrew Kelley
9a2de796bd stage2: clean up pretty printing compile errors 2021-04-09 00:19:44 -07:00
jacob gw
0f105ea324 stage2: fix bug where a parser error would break errors
A parser error would deinit the tree, but the tree is needed for the
node locations. This removes the offending code written before node
locations.
2021-04-08 23:17:36 -07:00
jacob gw
99ec511c4c stage2: pretty print compilation errors 2021-04-08 23:17:36 -07:00
g-w1
c6791d87d4 stage2: delete allowing input (and output) zir from the pipeline (#8471)
Remove -femit-zir as we aren't going to need it. Also remove zir test code
This removes a TODO that asserts the file is not zir.
2021-04-09 02:11:33 -04:00
Andrew Kelley
23db96931e AstGen: implement @typeInfo builtin 2021-04-08 22:38:13 -07:00
Andrew Kelley
6e05d53e88 AstGen: implement struct init with ResultLoc.ty 2021-04-08 22:33:40 -07:00
Sreehari S
906ac7b2f9 fix unannotated fall-through bug in case 2021-04-08 22:26:35 -07:00
Andrew Kelley
91e1414b50 stage2: implement array access to a global array 2021-04-08 21:56:42 -07:00
Andrew Kelley
6d616d8257 update stack trace test cases to new start.zig line offsets 2021-04-08 21:56:19 -07:00
Sreehari S
9ebdbca379 callconv: add SysV 2021-04-08 21:00:53 -07:00
Andrew Kelley
1b702f8ddb stage2: fix the memory leaks 2021-04-08 20:52:02 -07:00
Andrew Kelley
61b868f9a5 stage2: simplify Decl src_node field
Also fix "previous definition here" error notes to be correct.
2021-04-08 20:37:19 -07:00
Andrew Kelley
482b995a49 stage2: blaze the trail for std lib integration
This branch adds "builtin" and "std" to the import table when using the
self-hosted backend.

"builtin" gains one additional item:

```
pub const zig_is_stage2 = true; // false when using stage1 backend
```

This allows the std lib to do conditional compilation based on detecting
which backend is being used. This will be removed from builtin as soon
as self-hosted catches up to feature parity with stage1.
Keep a sharp eye out - people are going to be tempted to abuse this.
The general rule of thumb is do not use `builtin.zig_is_stage2`. However
this commit breaks the rule so that we can gain limited start.zig support
as we incrementally improve the self-hosted compiler.

This commit also implements `fullyQualifiedNameHash` and related
functionality, which effectively puts all Decls in their proper
namespaces. `fullyQualifiedName` is not yet implemented.

Stop printing "todo" log messages for test decls unless we are in test
mode.

Add "previous definition here" error notes for Decl name collisions.

This commit does not bring us yet to a newly passing test case.

Here's what I'm working towards:

```zig
const std = @import("std");

export fn main() c_int {
    const a = std.fs.base64_alphabet[0];
    return a - 'A';
}
```

Current output:

```
$ ./zig-cache/bin/zig build-exe test.zig
test.zig:3:1: error: TODO implement more analyze elemptr
zig-cache/lib/zig/std/start.zig:38:46: error: TODO implement structInitExpr ty
```

So the next steps are clear:
 * Sema: improve elemptr
 * AstGen: implement structInitExpr
2021-04-08 19:05:05 -07:00
xackus
c28d1fe173 std docs: fix layout broken by the banner 2021-04-09 00:36:59 +02:00
Luuk de Gram
ff5774d93d Refactor link/wasm.zig to use offset table
This refactor inserts an offset table into wasm's data section
where each offset points to the actual data region.
This means we can keep offset indexes consistant and do not
have to perform any computer to determine where in the data section
something like a static string exists. Instead during runtime
it will load the data offset onto the stack.
2021-04-08 22:47:08 +02:00
Luuk de Gram
47f3642788 Cleanup 2021-04-08 22:47:08 +02:00
Luuk de Gram
9fd1dab582 Handle incremental compilation correctly 2021-04-08 22:47:08 +02:00
Luuk de Gram
1bd5552fc1 Calculate data length to ensure correct pointer offsets 2021-04-08 22:47:08 +02:00
Luuk de Gram
00b2e31589 Basic "Hello world" working 2021-04-08 22:47:08 +02:00
Andrew Kelley
9f744f19e7 Merge pull request #8464 from gracefuu/grace/wasm-ops
stage2 wasm: Add division and bitwise/boolean ops &, |, ^, and, or
2021-04-08 13:41:49 -07:00
joachimschmidt557
d7a89f9876 stage2 AArch64: Add conditional branch instructions 2021-04-08 13:39:11 -07:00
Michael Dusan
000c0845b1 freebsd: disable failing stack traces test cases due to LLVM12 changes 2021-04-08 14:48:27 -04:00
Andrew Kelley
b9e508c410 stage2: revert to only has_decl and export ZIR support
Reverting most of the code from the previous commits in this branch.
Will pull in the code with modifications bit by bit.
2021-04-08 11:29:31 -07:00
Timon Kruiper
a483e38df6 stage2: fix bug where invalid ZIR was generated
The following code caused an assertion to be hit:
```
pub fn main() void {
    var e: anyerror!c_int = error.Foo;
    const i = e catch 69;
    assert(69 - i == 0);
}
```
2021-04-08 14:23:18 +02:00
Timon Kruiper
ac14b52e85 stage2: add support for start.zig
This adds a simplified start2.zig that the current stage2 compiler is
able to generate code for.
2021-04-08 14:23:18 +02:00
Timon Kruiper
e85cd616ef stage2: implement builtin function hasDecl 2021-04-08 14:23:18 +02:00
Timon Kruiper
a97efbd185 stage2: add support for root pkg
Fix some infinite recursions, because the code assumed that packages
cannot point to each other. But this assumption does not hold anymore.
2021-04-08 14:23:18 +02:00
Timon Kruiper
fb16cb9183 stage2: add initial support for builtin pkg
We currently emit a simplified builtin2.zig that is able to be parsed
and correctly interpreted in stage2.
2021-04-08 14:23:17 +02:00
Timon Kruiper
91e416bbf0 stage2: add a simplified export builtin call
std.builtin.ExportOptions is not yet supported, thus the second argument
of export is now a simple string that specifies the exported symbol
name.
2021-04-08 14:22:56 +02:00
Timon Kruiper
272fe0cbfe stage2: fix bug in ZIR gen of global comptime block
A global comptime block did not end with a break_inline instruction
which caused an assertion to be hit.
2021-04-08 14:20:40 +02:00
Andrew Kelley
ab5a445d25 Merge pull request #8459 from joachimschmidt557/stage2-regalloc
Stage2 Register Manager: add getReg function
2021-04-08 00:01:46 -07:00
xackus
2d2316f5c0 translate-c: fix meta.cast to ?*c_void 2021-04-08 08:33:26 +03:00
Andrew Kelley
d4f61f9842 Merge pull request #8449 from ziglang/stage2-enums
stage2: implement simple enums
2021-04-07 22:29:28 -07:00
Andrew Kelley
7595915775 stage2: add remaining enum compile error test cases 2021-04-07 22:24:52 -07:00
Andrew Kelley
57aa289fde Sema: fix switch validation '_' prong on wrong type 2021-04-07 22:19:17 -07:00
Andrew Kelley
e730172e47 stage2: fix switch validation of handling all enum values
There were several problems, all fixed:
 * AstGen was storing field names as references to the original
   source code bytes. However, that data would be destroyed when the
   source file is updated. Now, it correctly stores the field names in
   the Decl arena for the enum. The same fix applies to error set field
   names.
 * Sema was missing a memset inside `analyzeSwitch`, leaving the "seen
   enum fields" array with undefined memory. Now that they are all
   properly set to null, the validation works.
 * Moved the "enum declared here" note to the end. It looked weird
   interrupting the notes for which enum values were missing.
2021-04-07 22:02:45 -07:00
Andrew Kelley
b67378fb08 Sema: @intToEnum error msg includes a "declared here" hint 2021-04-07 21:04:55 -07:00
Andrew Kelley
a62e19ec8e AstGen: fix incorrect source loc for duplicate enum tag 2021-04-07 20:50:57 -07:00
Andrew Kelley
12087d4cba stage2: fix incremental compilation handling of parse errors
Before, incremental compilation would crash when trying to emit compile
errors for the update after introducing a parse error.

Parse errors are handled by not invalidating any existing semantic
analysis. However, only the parse error must be reported, with all the
other errors suppressed. Once the parse error is fixed, the new file can
be treated as an update to the previously-succeeded update.
2021-04-07 20:36:01 -07:00
Andrew Kelley
4996c2b6a9 stage2: fix incremental compilation Decl deletion logic
* `analyzeContainer` now has an `outdated_decls` set as well as
   `deleted_decls`. Instead of queuing up outdated Decls for re-analysis
   right away, they are added to this new set. When processing the
   `deleted_decls` set, we remove deleted Decls from the
   `outdated_decls` set, to avoid deleted Decl pointers from being in
   the work_queue. Only after processing the deleted decls do we add
   analyze_decl work items to the queue.

 * Module.deletion_set is now an `AutoArrayHashMap` rather than `ArrayList`.
   `declareDeclDependency` will now remove a Decl from it as appropriate.
   When processing the `deletion_set` in `Compilation.performAllTheWork`,
   it now assumes all Decl in the set are to be deleted.

 * Fix crash when handling parse errors. Currently we unload the
   `ast.Tree` if any parse errors occur. Previously the code emitted a
   LazySrcLoc pointing to a token index, but then when we try to resolve
   the token index to a byte offset to create a compile error message,
   the  ast.Tree` would be unloaded. Now we use
   `LazySrcLoc.byte_abs` instead of `token_abs` so the error message can
   be created even with the `ast.Tree` unloaded.

Together, these changes solve a crash that happened with incremental
compilation when Decls were added and removed in some combinations.
2021-04-07 19:54:28 -07:00
Andrew Kelley
8f28e26e7a Sema: implement switch validation for enums 2021-04-07 16:39:10 -07:00
Michael Dusan
341dc03b63 netbsd: minor fixes to allow stage1 to build 2021-04-07 16:26:21 -07:00
Andrew Kelley
ccdba774c8 AstGen: fix ZIR struct encoding
off by one error in the bits that describe defaults/field alignments
as soon as we have tests for struct field alignment and default values,
there will be coverage for this.
2021-04-07 15:02:46 -07:00
gracefu
6dc35efe49 Sema: fix typo bug for boolean ops (and, or) 2021-04-08 05:27:00 +08:00
gracefu
e4a60b63f2 stage2 wasm: Add bitwise/boolean ops &, |, ^, and, or 2021-04-08 05:27:00 +08:00
gracefu
4c71942f84 stage2: Add .div to ir.zig 2021-04-08 05:26:56 +08:00
Andrew Kelley
015599d1ef C backend: enumerate all the types in renderType
Now that we're close to supporting all the types, get rid of the `else`
prong and explicitly list out those types that are not yet implemented.

Thanks @g-w1
2021-04-07 13:17:23 -07:00
Andrew Kelley
090834380c Type: use isPtrLikeOptional instead of isAbiPtr
Thanks @Vexu
2021-04-07 13:06:21 -07:00
Andrew Kelley
e32898b0de AstGen: fix switch expressions with all prongs noreturn 2021-04-07 12:59:50 -07:00
Andrew Kelley
18119aae30 Sema: implement comparison analysis for non-numeric types 2021-04-07 12:15:05 -07:00
Andrew Kelley
d9c25ec672 zir: use node union field for alloc_inferred
Previously we used `un_node` and passed `undefined` for the operand, but
this causes illegal behavior when printing ZIR code.
2021-04-07 11:34:23 -07:00
Andrew Kelley
4e8fb9e6a5 Sema: DRY up enum field analysis and add "declared here" notes 2021-04-07 11:26:07 -07:00
Andrew Kelley
bcc371618f AstGen: fix @breakpoint ZIR
Previously it relied on the breakpoint ZIR instruction being void, but
that's no longer how things work.
2021-04-07 10:24:57 -07:00
joachimschmidt557
4ff5a3cd94 stage2 regalloc: Add unit test for getReg 2021-04-07 15:15:14 +02:00
Michael Dusan
2871d32be7 test: fix std.time timing tests to skip on failure 2021-04-07 08:33:32 -04:00
jacob gw
01a39fa1d4 stage2: coerce enum_literal -> enum 2021-04-07 07:19:11 -04:00
Andrew Kelley
19cf987198 C backend: implement Enum types and values
They are lowered directly as the integer tag type, with no typedef.
2021-04-06 23:19:46 -07:00
Andrew Kelley
acf9151008 stage2: implement field access for Enum.tag syntax 2021-04-06 22:36:28 -07:00
Andrew Kelley
2adeace905 std: modernize zig parser perf test
use the file size formatting functions
2021-04-06 22:34:48 -07:00
Andrew Kelley
f253822415 stage2: do not set clang_passthrough_mode for zig run
Thanks to @g-w1 for discovering this bug.

closes #8450
2021-04-06 19:50:53 -07:00
Andrew Kelley
b40d36c90b stage2: implement simple enums
A simple enum is an enum which has an automatic integer tag type,
all tag values automatically assigned, and no top level declarations.
Such enums are created directly in AstGen and shared by all the
generic/comptime instantiations of the surrounding ZIR code. This
commit implements, but does not yet add any test cases for, simple enums.

A full enum is an enum for which any of the above conditions are not
true. Full enums are created in Sema, and therefore will create a unique
type per generic/comptime instantiation. This commit does not implement
full enums. However the `enum_decl_nonexhaustive` ZIR instruction is
added and the respective Type functions are filled out.

This commit makes an improvement to ZIR code, removing the decls array
and removing the decl_map from AstGen. Instead, decl_ref and
decl_val ZIR instructions index into the `owner_decl.dependencies`
ArrayHashMap. We already need this dependencies array for incremental
compilation purposes, and so repurposing it to also use it for ZIR decl
indexes makes for efficient memory usage.

Similarly, this commit fixes up incorrect memory management by removing
the `const` ZIR instruction. The two places it was used stored memory in
the AstGen arena, which may get freed after Sema. Now it properly sets
up a new anonymous Decl for error sets and uses a normal decl_val
instruction.

The other usage of `const` ZIR instruction was float literals. These are
now changed to use `float` ZIR instruction when the value fits inside
`zir.Inst.Data` and `float128` otherwise.

AstGen + Sema: implement int_to_enum and enum_to_int. No tests yet; I expect to
have to make some fixes before they will pass tests. Will do that in the
branch before merging.

AstGen: fix struct astgen incorrectly counting decls as fields.

Type/Value: give up on trying to exhaustively list every tag all the
time. This makes the file more manageable. Also found a bug with
i128/u128 this way, since the name of the function was more obvious when
looking at the tag values.

Type: implement abiAlignment and abiSize for structs. This will need to
get more sophisticated at some point, but for now it is progress.

Value: add new `enum_field_index` tag.
Value: add hash_u32, needed when using ArrayHashMap.
2021-04-06 18:17:37 -07:00
joachimschmidt557
ac2211118f stage2 regalloc: Add getReg and getRegWithoutTracking 2021-04-06 21:14:00 +02:00
Andrew Kelley
ec212c82be Merge pull request #8416 from gracefuu/grace/wasm-ops
stage2 wasm codegen: refactor Opcode, add `sub` and `mul` operators
2021-04-06 11:48:40 -07:00
Evan Haas
8de14a98a6 translate-c: Add support for vector expressions
Includes vector types, __builtin_shufflevector, and __builtin_convertvector
2021-04-06 11:22:27 -07:00
Michael Holmes
38d8aab4d2 std/build: fix ?[:0]const u8 build options
As per the other string types, `?[:0]const u8` needs its own case
as otherwise it will raise an error about using `{}` with slices.

There's no reasonable workaround for this, as you would have to
either discount the use of the empty string value or manually
rework the string to be sentinel-terminated at runtime. It's
useful for passing build options to code making use of C libraries
that make strong use of sentinel-terminated arrays for strings.
2021-04-06 11:09:54 -07:00
LemonBoy
10c2b36444 stage1: Work around a small problem in LLVM API
The missing initializer for a single field in the TargetOptions class
was enough to turn the stack protectors into hot garbage.

Fixes #8408
2021-04-06 11:02:18 -07:00
LemonBoy
89df41e5d8 stage2: Default AVR generic cpu to avr2
The avr1 target is a very minimal subset of the AVR ISA, quoting the GCC
manual:

> This ISA is implemented by the minimal AVR core and supported for
> assembler only.

Default to avr2 as GCC and Clang do.
2021-04-06 10:18:11 -07:00
lithdew
2bfc6d14d5 os/linux: return error on EALREADY for connect() and getsockoptError()
When a connected socket file descriptor on Linux is re-acquired
    after being closed, through fuzz testing, it appears that a
    subsequent attempt to establish a connection with the file
    descriptor causes EALREADY to be reported.

    Instead of panicking, choose to return error.ConnectionPending
    to allow for users to handle this fairly rare case.
2021-04-06 11:30:20 +02:00
gracefu
ec84742c89 stage2 wasm codegen: refactor to use wasm.buildOpcode 2021-04-05 16:19:52 +08:00
gracefu
3648e43dda std/wasm: add buildOpcode to help construction of Opcodes 2021-04-05 14:44:00 +08:00
gracefu
869fc06c57 stage2 wasm: codegen mul op 2021-04-05 14:37:04 +08:00
gracefu
d1244d3608 stage2 wasm: codegen sub op 2021-04-05 14:37:04 +08:00
Edward Dean
83a2665772 Fixed error types for GetSeekPosError 2021-04-04 17:04:46 -07:00
Lewis Gaul
7302b096bd Tidy-up in json test module (#8431)
* Switch json testing 'roundTrip()' to use FixedBufferStream, improve error handling, remove comptime from param

* Add 'try' to calls to roundTrip() that can now return an error

* Remove comptime from params in json testing, replace expect(false) with letting error propagate

* Add 'try' to calls to ok() that can now return an error

Co-authored-by: Lewis Gaul <legaul@cisco.com>
2021-04-04 19:27:47 -04:00
Hannu Hartikainen
c9ffb6f734 std docs: enhance search browser history UX
Before this change every keypress in the search field causes a browser
history entry, which makes navigating back annoying.

On first keypress in the search field, a new history entry is created.
On subsequent keypresses, the most recent history entry is replaced.
Therefore a typical history after searching and navigating to an entry
might look like

1. documentation root
2. search page "print"
3. docs for `std.debug.print`


Co-authored-by: Žiga Željko <ziga.zeljko@gmail.com>
2021-04-04 16:25:47 -07:00
Andrew Kelley
545830c0ff LLVM sub-arch triple: remove TODO comment
See #6542 for more details. Upon investigation, this change is not
needed.
2021-04-04 16:10:54 -07:00
Andrew Kelley
0fee4b55a8 glibc: update ABI files to 2.33 2021-04-04 12:04:02 -07:00
Andrew Kelley
0e2da11379 glibc: update headers to 2.33
This introduces csky support.
2021-04-04 12:04:02 -07:00
Andrew Kelley
4d729ebc87 glibc: update ABI files to 2.33 2021-04-04 11:57:41 -07:00
Andrew Kelley
4d4bb69d7b glibc: update headers to 2.33
This introduces csky support.
2021-04-04 11:54:47 -07:00
Andrew Kelley
b25476bf12 glibc: add support for csky architecture 2021-04-04 11:52:40 -07:00
Vincent Rischmann
5ce4524027 os/bits/linux: add IPv6 socket options 2021-04-04 20:43:41 +03:00
xackus
e4563860fe translate-c: fix calls with no args in macros 2021-04-04 20:43:13 +03:00
Lewis Gaul
74fd7107e8 Switch std.json to use an ordered hashmap 2021-04-04 10:16:59 +02:00
Frank Denis
6fc822a948 Merge pull request #8410 from antlilja/remove-undefined-math
Make sqrt and log functions undefined for signed integer types
2021-04-03 19:27:37 +02:00
antlilja
d4dc2eb807 Compile error for signed integer math
Output compile errors when signed integer types are used on functions
where the answer might've been a complex number but that functionality hasn't
been implemented.

This applies to sqrt, log, log2, log10 and ln.

A test which used a signed integer was also changed to use an unsigned
integer instead.
2021-04-03 13:09:20 +02:00
Andrew Kelley
2f07d76eee stage2: implement Type.onePossibleValue for structs 2021-04-02 21:17:23 -07:00
Andrew Kelley
d47f0abd5b stage2: Sema: implement validate_struct_init_ptr 2021-04-02 21:06:09 -07:00
Andrew Kelley
97d7fddfb7 stage2: progress towards basic structs
Introduce `ResultLoc.none_or_ref` which is used by field access
expressions to avoid unnecessary loads when the field access itself
will do the load. This turns:

```zig
p.y - p.x - p.x
```

from

```zir
  %14 = load(%4) node_offset:8:12
  %15 = field_val(%14, "y") node_offset:8:13
  %16 = load(%4) node_offset:8:18
  %17 = field_val(%16, "x") node_offset:8:19
  %18 = sub(%15, %17) node_offset:8:16
  %19 = load(%4) node_offset:8:24
  %20 = field_val(%19, "x") node_offset:8:25
```

to

```zir
  %14 = field_val(%4, "y") node_offset:8:13
  %15 = field_val(%4, "x") node_offset:8:19
  %16 = sub(%14, %15) node_offset:8:16
  %17 = field_val(%4, "x") node_offset:8:25
```

Much more compact. This requires `Sema.zirFieldVal` to support both
pointers and non-pointers.

C backend: Implement typedefs for struct types, as well as the following
TZIR instructions:
 * mul
 * mulwrap
 * addwrap
 * subwrap
 * ref
 * struct_field_ptr

Note that add, addwrap, sub, subwrap, mul, mulwrap instructions are all
incorrect currently and need to be updated to properly handle wrapping
and non wrapping for signed and unsigned.

C backend: change indentation delta to 1, to make the output smaller and
to process fewer bytes.

I promise I will add a test case as soon as I fix those warnings that
are being printed for my test case.
2021-04-02 19:11:51 -07:00
Andrew Kelley
4bab90512d disable failing stack traces test cases due to LLVM12 changes 2021-04-02 16:33:38 -07:00
Andrew Kelley
e2a7c01331 disable failing MIPS tests due to LLVM12 regressions
See #8155
2021-04-02 16:33:07 -07:00
joachimschmidt557
43d364afef stage2 AArch64: Add ldrh and ldrb instructions 2021-04-02 14:46:30 -07:00
Andrew Kelley
09008125e7 Revert back to the old LLVM PassManager
See #8418

This reverts commit ba1bea2fe8.
This reverts commit 94383d14df.
This reverts commit 0d53a2bff0.
2021-04-02 14:35:45 -07:00
Andrew Kelley
12e2523730 docgen: correct the progress bar
It wasn't showing progress for non-code nodes.
2021-04-02 13:57:16 -07:00
Andrew Kelley
ba1bea2fe8 zig_llvm.cpp: remove dead code 2021-04-02 12:10:39 -07:00
Andrew Kelley
a0e89c9b46 Merge remote-tracking branch 'origin/master' into llvm12 2021-04-02 12:09:38 -07:00
Min-Yih Hsu
94383d14df llvm new-pm: Add missing pipeline option and Passes
- Enable MergeFunctionsPass in non-debug build.
 - Verify input and output IR when the assertion is turned on.
 - Add AlwaysInlinePass in debug build.
 - Add more comments.
2021-04-02 12:04:49 -07:00
Min-Yih Hsu
0d53a2bff0 llvm new-pm: Port LLVM 11.x-based changes to LLVM 12.x
Now zig will use new PM for optimization by default.
2021-04-02 12:04:49 -07:00
joachimschmidt557
228a1ce3e8 stage2 register_manager: Add unit tests for tryAllocReg and allocReg 2021-04-02 12:01:52 -07:00
joachimschmidt557
4efbcad26d stage2 codegen: Extract register management code into separate file 2021-04-02 12:01:52 -07:00
Andrew Kelley
fc9c1b4e4a Merge pull request #8028 from mguaypaq/nosuspend-allow
stage1: allow async and resume inside nosuspend blocks
2021-04-02 11:59:34 -07:00
Mathieu Guay-Paquet
f270bef9a4 docs: document the nosuspend keyword (#7972)
* docs: document the nosuspend keyword

* Specify that resuming from suspend is allowed in nosuspend

* Fix the description of the requirements of nosuspend

* Make use of nosuspend in some example code.

This is mainly motivated by the incorrect claim that "there would be
no way to collect the return value of amain, if it were something
other than void".
2021-04-02 14:57:42 -04:00
Loris Cro
354c14d6a2 make visited links readable in the stdlib docs warning bar 2021-04-02 20:22:02 +02:00
Loris Cro
4fef1d2982 added warning banner to stdlib docs 2021-04-02 20:13:55 +02:00
Andrew Kelley
d780848ae4 Merge pull request #7792 from zanderxyz/zanderxyz/priority-dequeue
std: Add Priority Dequeue
2021-04-02 10:52:23 -07:00
Woze Parrot
833f258297 put async frame in correct addrspace 2021-04-02 10:39:56 -07:00
Frank Denis
45db0e93a9 Merge pull request #8412 from g-w1/fix-docgen-test-release
docgen: fix typo
2021-04-02 18:40:55 +02:00
jacob gw
cdc5921073 docgen: fix typo
zig test test.zig-OReleaseFast -> zig test test.zig -OReleaseFast
2021-04-02 12:08:52 -04:00
Michael Dusan
cc435dab2f test: fix io_uring timing test to skip on failure 2021-04-02 07:12:09 -04:00
Andrew Kelley
8ebfdc14f6 stage2: implement structs in the frontend
New ZIR instructions:
 * struct_decl_packed
 * struct_decl_extern

New TZIR instruction: struct_field_ptr

Introduce `Module.Struct`. It uses `Value` to store default values and
abi alignments.

Implemented Sema.analyzeStructFieldPtr and zirStructDecl.

Some stuff I changed from `@panic("TODO")` to `log.warn("TODO")`.
It's becoming more clear that we need the lazy value mechanism soon;
Type is becoming unruly, and some of these functions have too much logic
given that they don't have any context for memory management or error
reporting.
2021-04-01 22:39:09 -07:00
Andrew Kelley
c66b48194f stage2: AstGen and ZIR printing for struct decls 2021-04-01 19:27:17 -07:00
Andrew Kelley
09000c3f77 zig cc: copy .pdb files from zig-cache/ when appropriate
closes #8407
2021-04-01 16:33:29 -07:00
Andrew Kelley
50bcfb8c90 stage2: implement struct init syntax with ptr result loc 2021-04-01 11:58:55 -07:00
lithdew
59035ae3e9 os: handle ECONNRESET for connect() syscall 2021-04-01 14:18:49 +02:00
Andrew Kelley
070a28e493 Merge pull request #8266 from ziglang/zir-memory-layout
rework ZIR memory layout; overhaul source locations
2021-03-31 23:11:15 -07:00
Andrew Kelley
c9e31febf8 stage2: finish implementation of LazySrcLoc 2021-03-31 23:00:00 -07:00
Andrew Kelley
b27d052676 stage2: finish source location reworkings in the branch
* remove the LazySrcLoc.todo tag
 * finish updating Sema and AstGen, remove the last of the
   `@panic("TODO")`.
2021-03-31 21:36:32 -07:00
Andrew Kelley
e8143f6cbe stage2: compile error for duplicate switch value on sparse 2021-03-31 18:39:34 -07:00
Andrew Kelley
cec766f73c stage2: compile error for duplicate switch value on boolean 2021-03-31 18:30:23 -07:00
jacob gw
fedc9ebd26 stage2: cbe: restore all previously passing tests! 2021-03-31 18:09:45 -07:00
Andrew Kelley
3cebaaad1c astgen: improved handling of coercion
GenZir struct now has rl_ty_inst field which tracks the result location
type (if any) a block expects all of its results to be coerced to.

Remove a redundant coercion on const local initialization with a
specified type.

Switch expressions, during elision of store_to_block_ptr instructions,
now re-purpose them to be type coercion when the block has a type in the
result location.
2021-03-31 18:05:37 -07:00
Andrew Kelley
08eedc962d Sema: fix else case code generation for switch 2021-03-31 16:17:47 -07:00
Andrew Kelley
abd06d8eab stage2: clean up RangeSet and fix swapped Sema switch logic for lhs/rhs 2021-03-31 15:39:04 -07:00
Andrew Kelley
e272c29c16 Sema: implement switch validation for ranges 2021-03-31 15:06:03 -07:00
joachimschmidt557
1b657e6e41 stage2 codegen: Make sure function return value is in a callee
preserved register
2021-03-31 23:27:50 +02:00
joachimschmidt557
e088a17f56 stage2 AArch64: implement strb and strh 2021-03-31 23:26:49 +02:00
Andrew Kelley
c7b09be8de AstGen: improve switch expressions
* use the proper result location strategy even when there are noreturn
   prongs in the switch expression
 * when using break_operand strategy, actually omit the
   store_to_block_ptr instructions rather than eliding them.
 * for both strategies, properly handle noreturn prongs.
2021-03-31 12:37:20 -07:00
Andrew Kelley
549af582e7 AstGen: switch expressions properly handle result locations 2021-03-30 23:57:22 -07:00
Andrew Kelley
2a1dd174cd stage2: rework AstGen for switch expressions
The switch_br ZIR instructions are now switch_block instructions. This
avoids a pointless block always surrounding a switchbr in emitted ZIR
code.

Introduce typeof_elem ZIR instruction for getting the type of the
element of a pointer value in 1 instruction.

Change typeof to be un_node, not un_tok.

Introduce switch_capture ZIR instructions for obtaining the capture
value of switch prongs.

Introduce Sema.resolveBody for when you want to extract a *Inst out of a
block and you know that there is only going to be 1 break from it.

What's not working yet: AstGen does not correctly elide
store instructions when it turns out that the result location does not
need to be used as a pointer.

Also Sema validation code for duplicate switch items is not yet
implemented.
2021-03-30 21:28:36 -07:00
Andrew Kelley
195ddab2be Sema: implement switch expressions
The logic for putting ranges into the else prong is moved from AstGen to
Sema. However, logic to emit multi-items the same as single-items cannot
be done until TZIR supports mapping multiple items to the same block of
code. This will be simple to represent when we do the upcoming TZIR memory
layout changes.

Not yet implemented in this commit is the validation of duplicate
values. The trick is going to be emitting error messages with accurate
source locations, without adding extra source nodes to the ZIR
switch instruction.

This will be done by computing the respective AST node based on the
switch node (which we do have available), only when a compile error
occurs and we need to know the source location to attach the message to.
2021-03-29 21:59:08 -07:00
Matthew Borkowski
501b4aff99 Add tests for the fill functions of the Isaac64, Pcg, Sfc64, and Xoroshiro128 PRNGs 2021-03-29 09:22:06 +02:00
Matthew Borkowski
a5cc5f7854 Fix typo in Pcg.zig's fill function
When filling the last (len % 4) bytes of a buffer, the random number n was only being shifted right by 4 bits for each byte instead of 8. A random u16, for example, would always have its middle two nybbles be equal when generated this way. For comparison, Isaac64.zig, Sfc64.zig, and Xoroshiro128.zig all correctly shift right by 8 bits for each of the last bytes in their nearly identical fill functions.
2021-03-29 09:22:06 +02:00
Andrew Kelley
623d5f442c stage2: guidance on how to implement switch expressions
Here's what I think the ZIR should be. AstGen is not yet implemented to
match this, and the main implementation of analyzeSwitch in Sema is not
yet implemented to match it either.

Here are some example byte size reductions from master branch, with the
ZIR memory layout from this commit:

```
switch (foo) {
  a => 1,
  b => 2,
  c => 3,
  d => 4,
}
```

184 bytes (master) => 40 bytes (this branch)

```
switch (foo) {
  a, b => 1,
  c..d, e, f => 2,
  g => 3,
  else => 4,
}
```

240 bytes (master) => 80 bytes (this branch)
2021-03-28 23:12:26 -07:00
Andrew Kelley
b85ef2300f Merge remote-tracking branch 'origin/master' into llvm12 2021-03-28 21:42:56 -07:00
Andrew Kelley
281a7baaea Merge remote-tracking branch 'origin/master' into zir-memory-layout
Wanted to make sure those new test cases still pass.

Also grab that CI fix so we can get those green check marks.
2021-03-28 19:42:43 -07:00
Andrew Kelley
8f469c1127 stage2: fix error sets 2021-03-28 19:40:21 -07:00
jacob gw
0005b34637 stage2: implement sema for @errorToInt and @intToError 2021-03-28 18:22:01 -07:00
Andrew Kelley
175adc0bd7 ci: update msys2 installer 2021-03-28 17:49:28 -07:00
Andrew Kelley
bb5cfbcb72 Merge pull request #8305 from jedisct1/base64
std/base64: cleanups & support url-safe and other non-padded variants
2021-03-28 17:11:07 -07:00
Isaac Freund
f80f8a7a78 AstGen: pass *GenZir as the first arg, not *Module
This avoids the unnecessary scope.getGenZir() virtual call for both
convenience and performance.
2021-03-28 22:42:17 +02:00
Isaac Freund
d5d88087dd translate-c: fix typo made in prior commit 2021-03-28 22:29:37 +02:00
Isaac Freund
d123a5ec67 AstGen: scope result location related functions 2021-03-28 19:53:38 +02:00
Isaac Freund
402f87a213 stage2: rename WipZirCode => AstGen, astgen.zig => AstGen.zig 2021-03-28 19:10:10 +02:00
Jonathan Knezek
bbe6a0dddd Add a test & fix for std.fmt.fmtDuration 2021-03-28 15:44:15 +02:00
Frank Denis
6993087edc Remove the base64 unsafe decoder 2021-03-28 14:32:34 +02:00
Frank Denis
99bed37fc7 Add more variants 2021-03-28 14:32:34 +02:00
Frank Denis
b8c019ef49 std/base64: cleanups & support url-safe and other non-padded variants
This makes a few changes to the base64 codecs.

* The padding character is optional. The common "URL-safe" variant, in
particular, is generally not used with padding. This is also the case for
password hashes, so having this will avoid code duplication with bcrypt,
scrypt and other functions.
* The URL-safe variant is added. Instead of having individual constants
for each parameter of each variant, we are now grouping these in a
struct. So, `standard_pad_char` just becomes `standard.pad_char`.
* Types are not `snake_case`'d any more. So, `standard_encoder` becomes
`standard.Encoder`, as it is a type.
* Creating a decoder with ignored characters required the alphabet and
padding. Now, `standard.decoderWithIgnore(<ignored chars>)` returns a
decoder with the standard parameters and the set of ignored chars.
* Whatever applies to `standard.*` obviously also works with `url_safe.*`
* the `calcSize()` interface was inconsistent, taking a length in the
encoder, and a slice in the encoder. Rename the variant that takes a
slice to `calcSizeForSlice()`.
* In the decoder with ignored characters, add `calcSizeUpperBound()`,
which is more useful than the one that takes a slice in order to size
a fixed buffer before we have the data.
* Return `error.InvalidCharacter` when the input actually contains
characters that are neither padding nor part of the alphabet. If we
hit a padding issue (which includes extra bits at the end),
consistently return `error.InvalidPadding`.
* Don't keep the `char_in_alphabet` array permanently in a decoder;
it is only required for sanity checks during initialization.
* Tests are unchanged, but now cover both the standard (padded) and
the url-safe (non-padded) variants.
* Add an error set, rename `OutputTooSmallError` to `NoSpaceLeft`
to match the `hex2bin` equivalent.
2021-03-28 14:32:34 +02:00
Evan Haas
ab9324e604 translate-c: intcast compound assignment operand if different-sized integer
Use transCCast to cast the RHS of compound assignment if necessary.
2021-03-28 15:21:12 +03:00
lithdew
c8d721aa42 array_hash_map: decrement entries slice len after popping from entries in pop() to prevent oob 2021-03-28 11:02:37 +02:00
Jakub Konka
54b42a7596 azure: run pacman with -Sy 2021-03-28 11:01:57 +02:00
Andrew Kelley
68f4eb0f67 stage2: fully implement Type.eql for pointers
Also fixed abiAlignment - for pointers it was returning the abi
alignment inside the type, rather than of the pointer itself. There is
now `ptrAlignment` for getting the alignment inside the type of
pointers.
2021-03-27 23:55:19 -07:00
LemonBoy
75080e351a std: Detect AMD Zen3 CPU family
Easy peasy lemon squeezy.
2021-03-27 12:23:40 -07:00
Andrew Kelley
95cc457d97 stage2: enable passing tests 2021-03-26 23:54:36 -07:00
Andrew Kelley
1f5617ac07 stage2: implement bitwise expr and error literals 2021-03-26 23:46:37 -07:00
Andrew Kelley
da731e18c9 stage2: implement source location: .node_offset_var_decl_ty 2021-03-26 18:35:15 -07:00
Andrew Kelley
a72bfd00cf astgen: fix continue expressions 2021-03-26 18:26:39 -07:00
Isaac Freund
a217ad59c7 astgen: fix result location for sliced objects 2021-03-26 23:39:29 +01:00
Isaac Freund
22338d7816 astgen: implement float literals 2021-03-26 15:46:50 +01:00
Isaac Freund
d8ee8794e1 astgen: implement more builtin functions 2021-03-26 15:20:11 +01:00
Isaac Freund
5eea13f5cc astgen: implement slicing 2021-03-26 11:46:42 +01:00
Andrew Kelley
b2deaf8027 stage2: improve source locations of Decl access
* zir.Code: introduce a decls array. This is so that `decl_val` and
   `decl_ref` instructions can refer to a Decl with a u32 and therefore
   they can also store a source location. This is needed for proper
   compile error reporting.
 * astgen uses a hash map to avoid redundantly adding a Decl to the
   decls array.
 * fixed reporting "instruction illegal outside function body" instead
   of the desired message "unable to resolve comptime value".
 * astgen skips emitting dbg_stmt instructions in comptime scopes.
 * astgen has some logic to avoid adding unnecessary type coercion
   instructions for common values.
2021-03-25 23:45:17 -07:00
Andrew Kelley
4bfcd105ef stage2: fix @compileLog. 2021-03-25 20:11:23 -07:00
Andrew Kelley
4fd3a2e8e8 astgen: fix var decl source locations 2021-03-25 19:39:30 -07:00
Andrew Kelley
b9c5a1fdf5 astgen: fix for loop expressions
also rename the ZIR instruction `deref_node` to `load`.
2021-03-25 19:25:26 -07:00
Michael Dusan
9f01598a49 zig build: use ZIG_GLOBAL_CACHE_DIR
- move ZIG_GLOBAL_CACHE_DIR to `introspect`
- cleanup some dead fields from stage1 codegen
2021-03-25 22:05:21 -04:00
Jakub Konka
f1e324216d zld: parse archive's table of contents 2021-03-25 22:48:04 +01:00
Andrew Kelley
399bb2e154 astgen: fix array access 2021-03-25 13:03:54 -07:00
lithdew
4ce212739b os/linux: handle ECONNRESET for recv 2021-03-25 12:41:51 -07:00
Veikka Tuominen
df0f7f4692 translate-c: stop creating unnamed decls for typedefs child types 2021-03-25 16:59:26 +02:00
Sreehari S
5c28b8cd11 boot_services: implement locateDevicePath 2021-03-25 16:45:43 +02:00
Andrew Kelley
31023de6c4 stage2: implement inline while
Introduce "inline" variants of ZIR tags:
 * block => block_inline
 * repeat => repeat_inline
 * break => break_inline
 * condbr => condbr_inline

The inline variants perform control flow at compile-time, and they
utilize the return value of `Sema.analyzeBody`.

`analyzeBody` now returns an Index, not a Ref, which is the ZIR index of
a break instruction. This effectively communicates both the intended
break target block as well as the operand, allowing parent blocks to
find out whether they, in turn, should return the break instruction up the
call stack, or accept the operand as the block's result and continue
analyzing instructions in the block.

Additionally:
 * removed the deprecated ZIR tag `block_comptime`.
 * removed `break_void_node` so that all break instructions use the same Data.
 * zir.Code: remove the `root_start` and `root_len` fields. There is now
   implied to be a block at index 0 for the root body. This is so that
   `break_inline` has something to point at and we no longer need the
   special instruction `break_flat`.
 * implement source location byteOffset() for .node_offset_if_cond
   .node_offset_for_cond is probably redundant and can be deleted.

We don't have `comptime var` supported yet, so this commit adds a test
that at least makes sure the condition is required to be comptime known
for `inline while`.
2021-03-25 00:55:36 -07:00
Andrew Kelley
12d18a36e5 stage2: enable passing tests 2021-03-24 20:58:38 -07:00
Andrew Kelley
01bfd835bb stage2: clean up break / noreturn astgen
* Module.addBreak and addBreakVoid return zir.Inst.Index not Ref
   because Index is the simpler type and we never need a Ref for these.
 * astgen: make noreturn stuff return the unreachable_value and avoid
   unnecessary calls to rvalue()
 * breakExpr: avoid unnecessary access into the tokens array
 * breakExpr: fix incorrect `@intCast` (previously this unsafely
   casted an Index to a Ref)
2021-03-24 20:45:14 -07:00
Timon Kruiper
ea42ab34ab stage2: add block test cases llvm backend 2021-03-24 19:54:03 -07:00
Timon Kruiper
522707622e astgen: implement breaking from a block 2021-03-24 19:54:03 -07:00
Andrew Kelley
d73a4940e0 stage2: cleanups from previous commits
Change some ZIR instructions from un_tok to un_node. Idea here is to
avoid needlessly accessing the tokens array.

Go ahead and finish the catch code in orelseCatchExpr. Otherwise it
would be an easy mistake to get the scopes wrong when updating that
code and introduce a bug.

Delete a function that is now dead code.
2021-03-24 16:14:11 -07:00
Timon Kruiper
3543373fd4 stage2: add passing optional test case in LLVM backend 2021-03-24 15:48:18 -07:00
Timon Kruiper
2c99fbb672 astgen: implement orelse 2021-03-24 15:48:18 -07:00
Andrew Kelley
0c6581e01d stage2: fix memory leak when updating a function 2021-03-24 15:46:06 -07:00
Andrew Kelley
180dae4196 stage2: further cleanups regarding zir.Inst.Ref
* Introduce helper functions on Module.WipZirCode and zir.Code
 * Move some logic around
 * re-introduce ref_start_index
 * prefer usize for local variables + `@intCast` at the end.
   Empirically this is easier to optimize.
 * Avoid using mem.{bytesAsSlice,sliceAsBytes} because it incurs an
   unnecessary multiplication/division which may cause problems for the
   optimizer.
 * Use a regular enum, not packed, for `Ref`. Memory layout is
   guaranteed for enums which specify their tag type. Packed enums have
   ABI alignment of 1 byte which is too small.
2021-03-24 15:36:23 -07:00
Isaac Freund
0c601965ab stage2: make zir.Inst.Ref a non-exhaustive enum
This provides us greatly increased type safety and prevents the common
mistake of using a zir.Inst.Ref where a zir.Inst.Index was expected or
vice-versa. It also increases the ergonomics of using the typed values
which can be directly referenced with a Ref over the previous zir.Const
approach.

The main pain point is casting between a []Ref and []u32, which could be
alleviated in the future with a new std.mem function.
2021-03-24 19:11:44 +01:00
Isaac Freund
3bf72f2b3a std.build: make Builder.install_prefix non optional
This is useful for build.zig files to check in some cases, for example
to adhere to the convention of installing config to /etc instead of
/usr/etc on linux when using the /usr prefix. Perhaps std.build will
handle such common cases eventually, but that is not yet the case.
2021-03-24 12:29:50 +01:00
Andrew Kelley
a1afe69395 stage2: comment out failing test cases; implement more things
* comment out the failing stage2 test cases
   (so that we can uncomment the ones that are newly passing with
   further commits)
 * Sema: implement negate, negatewrap
 * astgen: implement field access, multiline string literals, and
   character literals
 * Module: when resolving an AST node into a byte offset, use the
   main_tokens array, not the firstToken function
2021-03-23 23:13:01 -07:00
Andrew Kelley
13ced07f23 stage2: fix while loops
also start to form a plan for how inline while loops will work
2021-03-23 21:37:10 -07:00
Andrew Kelley
bf7c3e9355 astgen: fixups regarding var decls and rl_ptr 2021-03-23 16:47:41 -07:00
Andrew Kelley
be673e6793 stage2: implement inttype ZIR
also add i128 and u128 to const inst list
2021-03-23 16:12:26 -07:00
Andrew Kelley
aa46a705ad astgen: finishThenElseBlock: fix putting store_to_block_ptr in wrong block 2021-03-23 15:32:25 -07:00
Andrew Kelley
af73f79490 stage2: fix comptimeExpr and comptime function calls 2021-03-23 13:25:58 -07:00
Andrew Kelley
866be099f8 stage2: add helper functions to clean up astgen Ref/Index 2021-03-23 12:54:18 -07:00
Timon Kruiper
830143905e Sema: use correct LazySrcLoc for resolvePeerTypes 2021-03-23 11:56:06 -07:00
Timon Kruiper
7194baed66 astgen: implement typeof 2021-03-23 11:56:06 -07:00
Timon Kruiper
99cf9f8bf1 astgen: fix an issue where the alloc wasnt elided 2021-03-23 11:49:12 -07:00
Timon Kruiper
982df37135 stage2: handle void value in genRet in LLVM backend 2021-03-23 11:42:46 -07:00
Timon Kruiper
d73b0473a1 stage2: rename fail to todo in LLVM backend
This way we don't have to pass src to every function and we can simply
use the first node as the lazy source location for all the todo
errors.
2021-03-23 11:42:46 -07:00
Isaac Freund
668148549a stage2: fix two return types to be Ref not Index
We currently have no type safety between zir.Inst.Ref, zir.Inst.Index,
and plain u32s.
2021-03-23 11:58:43 +01:00
Timon Kruiper
f3e8073e05 astgen: implement assign operations 2021-03-23 11:40:55 +01:00
Andrew Kelley
d24be85be8 stage2: fix if expressions 2021-03-22 23:47:13 -07:00
Andrew Kelley
749c3f014b Merge pull request #8339 from Luukdegram/wasm-control-flow
stage2: Wasm control flow
2021-03-22 19:52:31 -07:00
Andrew Kelley
568f333681 astgen: improve the ensure_unused_result elision 2021-03-22 18:57:46 -07:00
Andrew Kelley
2f391df2a7 stage2: Sema improvements and boolean logic astgen
* add `Module.setBlockBody` and related functions
 * redo astgen for `and` and `or` to use fewer ZIR instructions and
   require less processing for comptime known values
 * Sema: rework `analyzeBody` function. See the new doc comments in this
   commit. Divides ZIR instructions up into 3 categories:
   - always noreturn
   - never noreturn
   - sometimes noreturn
2021-03-22 17:29:56 -07:00
Isaac Freund
9f0b9b8da1 stage2: remove all async related code
The current plan is to avoid using async and related features in the
stage2 compiler so that we can bootstrap before implementing them.

Having this untested and incomplete code in the codebase increases
friction while working on stage2, in particular when preforming
larger refactors such as the current zir memory layout rework.

Therefore remove all async related code, leaving only error messages
in astgen.
2021-03-23 00:23:41 +01:00
Dimenus
240b15381d fix calculation in ensureCapacity 2021-03-22 11:58:44 -07:00
Luuk de Gram
4b854b75d2 Fix getNot and add test cases 2021-03-22 19:56:38 +01:00
Luuk de Gram
803f9e5dd0 Implement more instructions for more control flow support 2021-03-22 19:56:35 +01:00
Jakub Konka
3b48ea874e zld: naively handle static initializers in C++ 2021-03-22 17:14:53 +01:00
Isaac Freund
f3770dcc30 astgen: implement pointer types 2021-03-22 16:03:00 +01:00
Isaac Freund
8111453cc1 astgen: implement array types 2021-03-22 14:54:13 +01:00
Evan Haas
dce612ac2b translate-c: Ensure assignments are within a block when necessary
Ensures that if an assignment statement is the sole statement within a
C if statement, for loop, do loop, or do while loop, then when translated
it resides within a block, even though it does not in the original C.

Fixes the following invalid translation:

`if (1) if (1) 2;` -> `if (true) if (true) _ = @as(c_int, 2);`

To this:
```zig
    if (true) if (true) {
        _ = @as(c_int, 2);
    };
```

Fixes #8159
2021-03-22 10:48:08 +02:00
Carlos Zúñiga
187af14599 Fixed typo in user32
Use CreateWindowExW instead of RegisterClassExW as the type of pfnCreateWindowExW.
2021-03-22 10:43:04 +02:00
Andrew Kelley
4f3071a817 cleanups from previous commit 2021-03-21 20:18:13 -07:00
jacob gw
7a55671b89 zir-memory-layout: astgen: varDecl 2021-03-21 20:10:27 -07:00
Andrew Kelley
5769c963e0 Sema: implement arithmetic 2021-03-21 19:23:12 -07:00
Jakub Konka
ba8ac46e1f stage1: add cmake flag for enabling logging
Now that we ship our own linker for MachO by default in both stage1
and stage2, we need a way to enable logs for verbose debugging.
This commit adds `ZIG_ENABLE_LOGGING` cmake option which is equivalent
to stage2's `-Dlog` flag.

To enable it when building stage1 with cmake, add:

```
cmake .. -DZIG_ENABLE_LOGGING=on
```
2021-03-21 18:03:55 -07:00
Andrew Kelley
07c204393f Sema: no explicit coercion needed for inline asm args
These are now done with result locations.
2021-03-21 17:55:31 -07:00
Isaac Freund
72bcdb639f astgen: implement bool_and/bool_or 2021-03-22 00:51:25 +01:00
Joris Hartog
5e40560367 Specify type in autoHash error message
This commit simply specifies the type which `autoHash` can't hash in the
compile error.

Closes #7970.
2021-03-21 23:07:02 +02:00
Isaac Freund
4cfd5f6a30 astgen: implement simple binary operators 2021-03-21 20:32:39 +01:00
Isaac Freund
310a44d5be zir: add negate/negate_wrap, implement astgen
These were previously implemented as a sub/sub_wrap instruction with a
lhs of 0. Making this separate instructions however allows us to save
some memory as there is no need to store a lhs.
2021-03-21 20:32:39 +01:00
Andrew Kelley
7800ae05a2 astgen: fix not detecting volatile asm
if only we could have compile errors for unused locals
2021-03-20 22:48:36 -07:00
Andrew Kelley
7598a00f34 stage2: fix memory management of ZIR code
* free Module.Fn ZIR code when destroying the owner Decl
 * unreachable_safe and unreachable_unsafe are collapsed into one ZIR
   instruction with a safety flag.
 * astgen: emit an unreachable instruction for unreachable literals
 * don't forget to call deinit on ZIR code
 * astgen: implement some builtin functions
2021-03-20 22:40:08 -07:00
Nuno Leiria
0d96a284e8 std: Add reset to TokenIterator 2021-03-20 22:01:09 -07:00
Andrew Kelley
d8692b8bdb astgen: implement string literals 2021-03-20 21:59:28 -07:00
Andrew Kelley
8bad5dfa72 astgen: implement inline assembly 2021-03-20 21:48:35 -07:00
Andrew Kelley
260c610708 ZIR: move some un_tok tags to un_node instead
Idea here is to prefer un_node to un_tok in order to avoid unnecessary
calls to `tree.firstToken`.
2021-03-20 17:18:44 -07:00
Andrew Kelley
50010447bd astgen: implement function calls 2021-03-20 17:09:06 -07:00
jacob gw
907142a036 zir-memory-layout: remove all absolute src consts
this is to prevent future bugs
2021-03-20 15:56:59 -07:00
jacob gw
12eeb18a26 zir-memory-layout: astgen: more instructions 2021-03-20 15:56:59 -07:00
Timon Kruiper
a710368054 stage2: restructure LLVM backend
The LLVM backend is now structured into 3 different structs, namely
Object, DeclGen and FuncGen. Object represents an object that is
generated by the LLVM backend. DeclGen is responsible for generating
a decl and FuncGen is responsible for generating llvm instructions
from tzir in a function.
2021-03-20 15:10:44 -07:00
Jakub Konka
3913332145 Fix digest format specifier after std.fmt updates 2021-03-20 15:09:45 -07:00
Michael Dusan
e35f325dd1 azure: produce macos arm64 binaries
new pipeline `BuildMacOS_arm64`
  - `vmImage: 'macOS-10.15' `

new `macos_arm64_script`
  - switch from using `make` to `ninja`
  - select xcode 12.4
  - set zig-cache env variables
  - build host-zig binary with xcode, link against llvm for x86_64 (target macos 10.15)
  - build arm64-zig binary with xcode and host-zig, link against llvm for arm64 (target macos 11.0)
  - ad-hoc codesign arm64 binary with linker
  - use host-zig for docgen
  - use host-zig for experimental std lib docs
  - sync final `release/` hierarchy with `linux_script`
  - use gnu-tar for good-practices (set owner, set sort)

enhance `CMakeLists.txt`
  - do not build `zig0` when cross-compiling
  - disable `BYPRODUCTS` directive `zig1.o` to avoid `ninja` error

see #8265
2021-03-20 22:50:51 +01:00
Andrew Kelley
56677f2f2d astgen: support blocks
We are now passing this test:

```zig
export fn _start() noreturn {}
```

```
test.zig:1:30: error: expected noreturn, found void
```

I ran into an issue where we get an integer overflow trying to compute
node index offsets from the containing Decl. The problem is that the
parser adds the Decl node after adding the child nodes. For some things,
it is easy to reserve the node index and then set it later, however, for
this case, it is not a trivial code change, because depending on tokens
after parsing the decl determines whether we want to add a new node or
not.

Possible strategies here:

1. Rework the parser code to make sure that Decl nodes are before
   children nodes in the AST node array.

2. Use signed integers for Decl node offsets.

3. Just flip the order of subtraction and addition. Expect Decl Node
   index to be greater than children Node indexes.

I opted for (3) because it seems like the simplest thing to do. We'll
want to unify the logic for computing the offsets though because if the
logic gets repeated, it will probably get repeated wrong.
2021-03-19 23:15:18 -07:00
Andrew Kelley
937c43ddf1 stage2: first pass at repairing ZIR printing 2021-03-19 19:33:11 -07:00
Jakub Konka
f6ba810f27 zld: apply offset for DICE in archive 2021-03-19 23:37:16 +01:00
Andrew Kelley
0357cd8653 Sema: allocate inst_map with arena where appropriate 2021-03-19 15:31:50 -07:00
Andrew Kelley
81a935aef8 stage2: fix some math oopsies and typos 2021-03-19 15:19:47 -07:00
Andrew Kelley
132df14ee1 stage2: fix export source locations not being relative to Decl 2021-03-19 14:59:46 -07:00
jacob gw
a4f0ccdfe4 zir-memory-layout: astgen: literals and *, &
this was pretty low hanging fruit
2021-03-19 14:50:15 -07:00
jacob gw
c50397c268 llvm backend: use new srcloc
this allows to compile with ninja
2021-03-19 14:46:37 -07:00
jacob gw
e9810d9e79 zir-memory-layout: astgen: fill in identifier 2021-03-19 14:43:08 -07:00
LemonBoy
867ae506e3 std: Add syscall7 stub for Linux/MIPS
Some syscalls such as fadvise require an extra argument to comply with
the register pair alignment imposed by the ABI.

Wacky, isn't it?
2021-03-19 13:03:55 -07:00
Jakub Konka
652842637c zld: continue on invalid/missing debug info 2021-03-19 20:05:02 +01:00
Jakub Konka
d1b376cac9 zld: fix parsing archive/object name from header 2021-03-19 11:06:51 +01:00
Andrew Kelley
abdbc11c7e stage2: codegen: update asm IR to new names 2021-03-18 22:54:59 -07:00
Andrew Kelley
bd2154da3d stage2: the code is compiling again
(with a lot of things commented out)
2021-03-18 22:48:28 -07:00
Andrew Kelley
b2682237db stage2: get Module and Sema compiling again
There are some `@panic("TODO")` in there but I'm trying to get the
branch to the point where collaborators can jump in.

Next is to repair the seam between LazySrcLoc and codegen's expected
absolute file offsets.
2021-03-18 22:19:28 -07:00
Andrew Kelley
f5aca4a6a1 Merge remote-tracking branch 'origin/master' into zir-memory-layout
I need the enum arrays that were just merged into master.
2021-03-18 15:52:12 -07:00
Martin Wickham
96ae451bbe Add some enum utilities 2021-03-18 14:05:01 -07:00
Andrew Kelley
5e5b35f107 stage1: small memory optimization for simple pointer types
Avoid storing extra IR instruction data for simple pointer types.
2021-03-18 14:04:02 -07:00
Andrew Kelley
a6f5aa71ac stage1: small IR memory optimization on CheckSwitchProngs 2021-03-18 14:04:02 -07:00
Veikka Tuominen
ac7217e1f5 translate-c: preserve zero fractional part in float literals 2021-03-18 22:46:00 +02:00
jacob gw
7c6eb41619 cbe tests: fix test on windows
"\n" -> std.cstr.line_sep
2021-03-18 22:45:01 +02:00
Andrew Kelley
5cbb642525 stage1: small mem usage improvement for IR
move a boolean field to be represented implicitly with the enum tag.
Just borrowing one of the many strategies of stage2.

This simple change took the peak mem usage from std lib tests on
my machine from 8.21 GiB to 8.11 GiB.
2021-03-18 13:14:26 -07:00
Jakub Konka
17c066e925 Merge pull request #8282 from kubkon/zld
macho: upstream zld linker
2021-03-18 19:14:17 +01:00
Evan Haas
b54514d9dd translate-c: Use [N:0] arrays when initializer is a string literal (#8264)
* translate-c: Use [N:0] arrays when initializer is a string literal

Translate incomplete arrays as [N:0] when initialized by a string literal.
This preserves a bit more of the type information from the original C program.

Fixes #8215
2021-03-18 14:41:04 +02:00
root
75a7abb0c4 std: Fix std.fs.path.joinZ 2021-03-18 14:33:38 +02:00
Veikka Tuominen
bcc97bc1ed Merge pull request #8247 from Ersikan/fmt-fix-encoding
zig fmt: fix non-UTF-8 encoding #2820
2021-03-18 14:30:11 +02:00
Jakub Konka
f3b4f79c7f zld: temporarily disable testing shared lib linking 2021-03-18 11:10:31 +01:00
Jakub Konka
2cf1c1b96b macho: honor verbose_link when linking with zld 2021-03-18 11:10:09 +01:00
Jakub Konka
861ea64009 macho: remove now obsolete LLD fixups 2021-03-18 11:09:47 +01:00
Dimenus
dfeca48e35 @intCast takes two args 2021-03-17 22:58:52 -07:00
Andrew Kelley
66245ac834 stage2: Module and Sema are compiling again
Next up is reworking the seam between the LazySrcLoc emitted by Sema
and the byte offsets currently expected by codegen.

And then the big one: updating astgen.zig to use the new memory layout.
2021-03-17 22:54:56 -07:00
Jakub Konka
7516dfff83 zld: use zld when linking aarch64 by default and cross-comp 2021-03-18 00:37:13 +01:00
Jakub Konka
900658a85d rebase with master 2021-03-17 20:05:29 +01:00
Jakub Konka
1ec620be62 zld: fix GOT loads and indirection on x86_64 2021-03-17 19:59:57 +01:00
Jakub Konka
ac0c669473 zld: add/fix more issues
* fix debug info for static archives
* allow handling of empty object files
* fix some relocs for GOT loads
2021-03-17 19:59:13 +01:00
Jakub Konka
de209afbba zld: fix TLV initializers 2021-03-17 19:59:13 +01:00
Jakub Konka
349f878ecf zld: mimick Apple and add __DATA_CONST seg 2021-03-17 19:59:13 +01:00
Jakub Konka
62f43fbc06 zld: clean up use of commands.zig module 2021-03-17 19:59:13 +01:00
Jakub Konka
d484b3b3cb zld: use aarch64 for opcodes 2021-03-17 19:59:13 +01:00
Jakub Konka
dc34ac2b9e zld: fix incorrect offset calc for DICE 2021-03-17 19:59:13 +01:00
Jakub Konka
5d8944edc1 Revert log.warn hack 2021-03-17 19:59:13 +01:00
Jakub Konka
a1b0ec5277 zld: start bringing x64 up to speed 2021-03-17 19:59:13 +01:00
Jakub Konka
066c1386a3 zld: demote logs from warn to debug 2021-03-17 19:59:13 +01:00
Jakub Konka
b0ee480177 zld: merge and sort sections 2021-03-17 19:59:13 +01:00
Jakub Konka
44ebf48631 zld: fix handling of section alignment 2021-03-17 19:59:13 +01:00
Jakub Konka
7c22f4f851 zld: pass test-std and test-compiler-rt 2021-03-17 19:59:13 +01:00
Jakub Konka
7cbdbab376 zld: differentiate locals from globals 2021-03-17 19:59:13 +01:00
Jakub Konka
7e32947871 zld: add nop to reloc module 2021-03-17 19:59:13 +01:00
Jakub Konka
d2008db623 zld: bullet-proof stubs for long jumps 2021-03-17 19:59:13 +01:00
Jakub Konka
14590795b1 zld: cleanup section alignment when allocating 2021-03-17 19:59:13 +01:00
Jakub Konka
586c704212 zld: pass stage2 tests linked with zld! 2021-03-17 19:59:13 +01:00
Jakub Konka
e825a15b05 zld: replace ldr with add if indivisible 2021-03-17 19:59:13 +01:00
Jakub Konka
f52f23618d macho: start upstreaming zld 2021-03-17 19:59:13 +01:00
Jakub Konka
0f7b036eb7 Merge pull request #8281 from kubkon/macho-got-refactor
stage2+macho: refactor global offset table for incremental linker
2021-03-17 19:44:32 +01:00
Frank Denis
119fc318a7 std/crypto/chacha20: add round-reduced versions & cleanup internals
See https://eprint.iacr.org/2019/1492.pdf for justification.

8 rounds ChaCha20 provides a 2.5x speedup, and is still believed
to be safe.

Round-reduced versions are actually deployed (ex: Android filesystem
encryption), and thanks to the magic of comptime, it doesn't take much
to support them.

This also makes the ChaCha20 code more consistent with the Salsa20 code,
removing internal functions that were not part of the public API any more.

No breaking changes; the public API remains backwards compatible.
2021-03-17 11:25:51 -07:00
Andrew Kelley
587243c7a5 Merge pull request #8273 from jedisct1/pbkdf2-check
crypto/pbkdf2: simplify the check for the max number of iterations
2021-03-17 11:25:19 -07:00
Jakub Konka
e5234c0e9e macho: offset table part of GOT 2021-03-17 12:16:36 +01:00
Jakub Konka
b9fa80e588 macho: use latest bind functionality 2021-03-17 12:10:39 +01:00
Jakub Konka
1181543dad macho: extract writing stub helper preamble into fn 2021-03-17 12:10:39 +01:00
Jakub Konka
3df2ae1f9d macho: clean up writing of stub helper section 2021-03-17 12:10:39 +01:00
Jakub Konka
643b4898f5 macho: handle all jumps in stubs on aarch64 2021-03-17 12:10:39 +01:00
Jakub Konka
3019676440 macho: apply some renames to bring closer to zld 2021-03-17 12:10:39 +01:00
Ersikan
36db4b7cc4 test-cli: Remove temporary directory after tests 2021-03-17 10:27:41 +01:00
Ersikan
8942243f7a zig fmt: factorize source file reading and decoding
Now reading a source file and decoding it from UTF-16LE to UTF-8 is
done in a single function. Error messages are improved, and an error is
emitted when the source file has a BOM not supported (UTF-16BE, UTF-32).

Please note that the BOM of UTF-32 is composed of the same bytes as the
BOM of UTF-16 followed by a null character. Therefore a source file in
UTF-16LE starting with a null byte will be interpreted as an UTF-32, and
rejeted because of an invalid format. In pratice this is not a problem,
as the code would have been rejected later anyway because of the null
character.
2021-03-17 10:27:26 +01:00
Ersikan
a354000090 zig fmt: fix non-UTF-8 encoding #2820
Fixes #2820

After reading the source code, the first two bytes are inspected, and
if they correspond to a UTF-16 BOM in little-endian order, the source
code is converted to UTF-8.
2021-03-17 10:26:47 +01:00
Frank Denis
6d9b3e7b19 pbkdf2: use std.math.divCeil() 2021-03-17 10:11:47 +01:00
Andrew Kelley
38b3d4b00a stage2: work through some compile errors in Module and Sema 2021-03-17 00:56:08 -07:00
Evan Haas
f76bd56588 translate-c: fix __builtin_object_size
Previous code assumed `c_long` and `usize` were the same size.
Use `isize` instead.
2021-03-17 09:06:47 +02:00
Evan Haas
715370a10a translate-c: demote usage of un-implemented builtins 2021-03-17 09:06:47 +02:00
Andrew Kelley
4683de1e91 Merge pull request #8252 from tadeokondrak/llvm-bool
stage2 llvm bindings: use correct type for LLVMBool for ABI compat
2021-03-16 21:56:00 -07:00
Tadeo Kondrak
e8aa6f90d6 stage2 llvm bindings: use correct type for LLVMBool for ABI compat 2021-03-16 17:05:36 -06:00
Evan Haas
c558a1ae26 translate-c: Implement generic selection expressions
Enables translation of C code that uses the `_Generic` keyword
2021-03-17 00:07:33 +02:00
xackus
9a94415680 translate-c: improve std.meta.cast 2021-03-17 00:05:42 +02:00
jacob gw
83d0c2ed67 std: make all errors in os.zig public 2021-03-16 14:48:31 -07:00
jacob gw
e430f3f7e0 zir-memory-layout: fix @setEvalBranchQuota
also make emitBackwardBranch fail correctly
2021-03-16 14:47:54 -07:00
Frank Denis
f609c4ddb3 crypto/pbkdf2: use snake_case for variables like everywhere else 2021-03-16 19:08:38 +01:00
Frank Denis
d1b1e542a0 crypto/pbkdf2: simplify the check for the max number of iterations 2021-03-16 18:55:58 +01:00
Lewis Gaul
6787f163eb zig fmt: don't add trailing whitespace on switch case 2021-03-16 09:26:28 +01:00
LemonBoy
5ecf8bddae zig fmt: Respect line breaks in struct default value decls
Bring this in line with how variable declarations are handled.

Open a new indentation level for the initialization expression to handle
nested expressions like blocks.

Closes #7618
2021-03-16 09:22:16 +01:00
Andrew Kelley
099af0e008 stage2: rename zir_sema.zig to Sema.zig 2021-03-16 00:04:17 -07:00
Andrew Kelley
aef3e534f5 stage2: *WIP*: rework ZIR memory layout; overhaul source locations
The memory layout for ZIR instructions is completely reworked. See
zir.zig for those changes. Some new types:

 * `zir.Code`: a "finished" set of ZIR instructions. Instead of allocating
   each instruction independently, there is now a Tag and 8 bytes of
   data available for all ZIR instructions. Small instructions fit
   within these 8 bytes; larger ones use 4 bytes for an index into
   `extra`. There is also `string_bytes` so that we can have 4 byte
   references to strings. `zir.Inst.Tag` describes how to interpret
   those 8 bytes of data.
   - This is shared by all `Block` scopes.

 * `Module.WipZirCode`: represents an in-progress `zir.Code`. In this
   structure, the arrays are mutable, and get resized as we add/delete
   things. There is extra state to keep track of things. This struct is
   stored on the stack. Once it is finished, it produces an immutable
   `zir.Code`, which will remain on the heap for the duration of a
   function's existence.
   - This is shared by all `GenZir` scopes.

 * `Sema`: represents in-progress semantic analysis of a `zir.Code`.
   This data is stored on the stack and is shared among all `Block`
   scopes. It is now the main "self" argument to everything in the file
   that was previously named `zir_sema.zig`.
   Additionally, I moved some logic that was in `Module` into here.

`Module.Fn` now stores its parameter names inside the `zir.Code`,
instead of inside ZIR instructions. When the TZIR memory layout
reworking time comes, codegen will be able to reference this data
directly instead of duplicating it.

astgen.zig is (so far) almost entirely untouched, but nearly all of it
will need to be reworked to adhere to this new memory layout structure.

I have no benchmarks to report yet, as I am still working through
compile errors and fixing various things that I broke in this branch.

Overhaul of Source Locations:

Previously we used `usize` everywhere to mean byte offset, but sometimes
also mean other stuff. This was error prone and also made us do
unnecessary work, and store unnecessary bytes in memory.

Now there are more types involved into source locations, and more ways
to describe a source location.

 * AllErrors.Message: embrace the assumption that files always have less
   than 2 << 32 bytes.
 * SrcLoc gets more complicated, to model more complicated source
   locations.
 * Introduce LazySrcLoc, which can model interesting source locations
   with very little stored state. Useful for avoiding doing unnecessary
   work when no compile errors occur.

Also, previously, we had `src: usize` on every ZIR instruction. This is
no longer the case. Each instruction now determines whether it even cares
about source location, and if so, how that source location is stored.
This requires more careful work inside `Sema`, but it results in fewer
bytes stored on the heap, without compromising accuracy and power of
compile error messages.

Miscellaneous:

 * std.zig: string literals have more helpful result values for
   reporting errors. There is now a lower level API and a higher level
   API.
   - side note: I noticed that the string literal logic needs some love.
     There is some unnecessarily hacky code there.
 * cut & pasted some TZIR logic that was in zir.zig to ir.zig. This
   probably broke stuff and needs to get fixed.
 * Removed type/Enum.zig, type/Union.zig, and type/Struct.zig. I don't
   think this quite how this code will be organized. Need some more
   careful planning about how to implement structs, unions, enums. They
   need to be independent Decls, just like a top level function.
2021-03-16 00:03:22 -07:00
Anders Conbere
f16f25047c std: support optional getaddrinfo arguments 2021-03-16 01:10:32 +01:00
Lewis Gaul
aa1c780560 Add test for multi-line while cont expr with same-line then expr 2021-03-15 20:44:45 +01:00
Isaac Freund
48efa3bcb6 zig fmt: simplify and improve consistency of if/for/while handling
The main realization here was that getting rid of the early returns
in renderWhile() and rewriting the logic into a mostly unified execution
path took things from ~200 lines to ~100 lines and improved consistency
by deduplicating code.

Also add several test cases and fix a few issues along the way:

Fixes https://github.com/ziglang/zig/issues/6114
Fixes https://github.com/ziglang/zig/issues/8022
2021-03-15 14:55:34 +01:00
Lewis Gaul
b4db03d8bb zig fmt: fix extra newline before if nested in for
Add failing testcase to reproduce issue 8088

Tidy up renderWhile(), factoring out renderWhilePayload()

Ensure correct newline is used before 'then' token in while/for/if

Handle indents for 'if' inside 'for' or 'while'

Stop special-casing 'if' compared to 'for' and 'while'
2021-03-15 14:55:34 +01:00
Tadeo Kondrak
277b01a089 stage2 llvm bindings: rename LLVMBool to Bool 2021-03-14 22:32:26 -06:00
Michael Dusan
a502c160cd macho: fix various linker flags
fix drivers: zig {cc,c++}
  - `-dynamiclib` is an alias to `-shared`
  - associate `-dynamiclib` with zig `.shared` semantics

fix drivers: zig {cc,c++,build-lib,build-exe}
  - use `-dynamic` for {exe,dylib}
  - for dylib this fixes a regression
  - for exe this replaces incorrect use of `-static`
2021-03-14 17:26:24 -04:00
LemonBoy
27d07c6c4d std: Replace testing fns for floating-point values
Beside handling NaNs and other non-numeric values better we finally
offer the same pair of testing predicates in math and testing.
2021-03-14 17:23:47 -04:00
LemonBoy
d33f0d3375 docgen: Use Progress API
Really slow as usual but now looks slightly better.
2021-03-14 17:22:48 -04:00
Frank Denis
b98d7747fa Use a unified error set for std/crypto/*
This ensures that errors are used consistently across all operations.
2021-03-14 20:51:31 +01:00
Ersikan
f69305f865 stage2: Warn when using --debug-log without logging enabled
A warning is emitted when using the debug option --debug-log when the compiler
was not compiled using the build option -Dlog. Additionnaly, the scopes are not
added to log_scopes as they have no effect.
2021-03-14 17:48:02 +01:00
Andrew Kelley
a4316d5505 Merge remote-tracking branch 'origin/master' into llvm12 2021-03-13 14:35:03 -07:00
Andrew Kelley
4e9894cfc4 cmake build: allow overriding whether to use llvm-config
Previously, there was an option ZIG_PREFER_LLVM_CONFIG which would
override the default of not using llvm-config when cross compiling.

That option is now removed in favor of the more powerful
ZIG_USE_LLVM_CONFIG which defaults to OFF for cross compiling and ON for
native compilation. The option overrides the default.

This will be used in zig-bootstrap to improve support for native builds.
2021-03-13 14:30:56 -07:00
Michael Dusan
cc650abf09 lld: handle error instead of abort
closes #6675
2021-03-13 18:14:59 +01:00
Andrew Kelley
ce14bc7176 Merge pull request #8152 from LemonBoy/fix-riscv-ret
stage1: Follow the C ABI for return types
2021-03-12 20:12:36 -05:00
Dave Gauer
95eb711ca8 langref: Use "single-item pointer" and "many-item pointer" (#8217)
These terms give short, descriptive names for the two pointer
types which reflect the names used in src/type.zig.
2021-03-12 20:10:55 -05:00
Andrew Kelley
1f34c03ac1 Merge remote-tracking branch 'origin/master' into llvm12 2021-03-12 18:05:27 -07:00
LemonBoy
8ebb18d9da std: Use more common escape sequences in Progress
This should fix the badly-rendered progress message when run in
Terminal.app.
2021-03-12 19:31:59 -05:00
Isaac Freund
b83ef595a5 std/linux: sync io_uring library with liburing
liburing commit: 1bafb3ce5f

As stated in the liburing commit message, this fixes a regression,
reverting code that was added specutively to avoid a syscall in some
cases.
2021-03-12 22:22:06 +01:00
Andrew Kelley
f950489ed9 Merge pull request #8174 from LemonBoy/progress-line-wrap
std: Better handling of line-wrapping in Progress
2021-03-12 15:45:11 -05:00
Jakub Konka
a745e704f6 macos: add missing x86_64 libc headers 2021-03-12 18:05:50 +01:00
LemonBoy
b0724a350f Handle some weird edge cases of Win32 API
Sometimes the viewport srWindow may report an invalid rectangle where
the top row is below the bottom one.
2021-03-12 17:14:50 +01:00
LemonBoy
b5a50a26eb Fix many thinkos
Somehow I forgot to save after copy-pasting some code and changing it.
2021-03-12 15:08:48 +01:00
Sébastien Marie
89e522b935 make std.c.getErrno() return same type as _errno() aka c_int
adjust std.os.unexpectedErrno() to be correct for all std.os.system.errno (c_int, u12, usize, ...)
2021-03-12 15:04:36 +01:00
LemonBoy
36c4037144 stage1: Add tests for C ABI integer return types 2021-03-12 11:50:56 +01:00
LemonBoy
7813068e21 stage1: Follow the C ABI for return types
The current implementation of the target C ABI rules is hopelessly bad,
let's tack some more rules on top in order to prevent some
miscompilations.

Truth to be told the same rule should be applied also to parameters, but
I really can't stand stage1.
2021-03-12 11:50:56 +01:00
LemonBoy
3010bfb08a Fix Progress printing on Windows systems
The cursor must be restored after the line is printed, not before.
Take into account the visible viewport to correctly compute the terminal
size.
2021-03-12 10:15:38 +01:00
Michael Dusan
868253a9c9 re-enable behavior/vector test for aarch64
- issue fixed in llvmorg-12.0.0-rc3

closes #8130
2021-03-12 02:00:29 -05:00
Andrew Kelley
e9a038c33b Merge pull request #7934 from Vexu/stage2-cbe
Stage2 cbe: optionals and errors
2021-03-11 22:02:35 -05:00
Isaac Freund
a5cb4ab95e parser: disallow ptr modifiers on array types 2021-03-12 00:18:30 +01:00
LemonBoy
482424e2b1 std: Handle empty MultiArrayList in items()
Closes #8211
2021-03-12 00:17:35 +01:00
Andrew Kelley
4fc6f631e0 Merge pull request #8126 from xackus/translate_c_int_literal_promotion
translate-c: promote int literals to bigger types
2021-03-11 14:32:37 -05:00
joachimschmidt557
bdb917006c stage2 tzir: Add wrapping integer arithmetic instructions 2021-03-11 14:31:21 -05:00
Andrew Kelley
b1a22fdbab Merge pull request #8193 from kivikakk/elf-expose-em
elf: expose machine field in ELF header
2021-03-11 14:30:06 -05:00
Asherah Connor
24e5959840 elf: make EM non-exhaustive 2021-03-11 10:09:51 +11:00
Asherah Connor
c5eb15526d expose machine field in ELF header 2021-03-10 16:26:41 +11:00
LemonBoy
f2b96782ec stage2: Fix glibc lookup path for MIPS crt files
Add some more rules to let the compiler find the correct startup files
for the selected target and ABI.
2021-03-09 18:20:34 -05:00
LemonBoy
1a5d0cea15 stage2: Use correct ELF emulation for mips64
The n32 ABI requires a different emulation string than n64.
2021-03-09 18:20:34 -05:00
Loris Cro
a033735c8d update to latest fetch-them-macos-headers 2021-03-09 22:43:16 +01:00
Loris Cro
767eb2d469 update to latest fetch-them-macos-headers 2021-03-09 22:15:01 +01:00
Evan Haas
c760532be0 translate-c: Add compound literal support 2021-03-08 10:09:12 +02:00
Isaac Freund
b988815bf0 parser: fix parsing/rendering of a[b.. :c] slicing
The modification to the grammar in the comment is in line with the
grammar in the zig-spec repo.

Note: checking if the previous token is a colon is insufficent to tell
if a block has a label, the identifier must be checked for as well. This
can be seen in sentinel terminated slicing: `foo[0..1:{}]`
2021-03-08 01:37:28 +01:00
Evan Haas
d01bb21173 translate-c: Explicitly cast decayed array to pointer with @ptrCast
This enables translation of code that uses pointer arithmetic with arrays
2021-03-08 00:35:17 +02:00
Veikka Tuominen
fc62ff77c3 stage2: error union payload must also be a valid variable type 2021-03-08 00:33:59 +02:00
jacob gw
d9e46a4b90 stage2: fix memory leak in the cbe 2021-03-08 00:33:59 +02:00
jacob gw
30ffa052f2 stage2 cbe: add error union and error union operations 2021-03-08 00:33:59 +02:00
jacob gw
6467ef6d3b cbe: add error comparison support 2021-03-08 00:33:59 +02:00
Veikka Tuominen
0a7be71bc2 stage2 cbe: non pointer optionals 2021-03-08 00:33:56 +02:00
Veikka Tuominen
cfc19eace7 stage2 cbe: errors 2021-03-08 00:33:07 +02:00
Veikka Tuominen
c22f010fdd stage2 cbe: regular optional types 2021-03-08 00:33:07 +02:00
Veikka Tuominen
ca20d0ea26 stage2 cbe: pointer like optionals 2021-03-08 00:32:52 +02:00
jacob gw
5d215cc76b stage2 Elf linker: fill in bswapAllFields
I moved it to std.elf since it could be used there and added test
2021-03-07 23:18:26 +02:00
LemonBoy
4fc2e92876 std: Better handling of line-wrapping in Progress
In order to update the printed progress string the code tried to move
the cursor N cells to the left, where N is the number of written bytes,
and then clear the remaining part of the line.
This strategy has two main issues:
 - Is only valid if the number of characters is equal to the number of
   written bytes,
 - Is only valid if the line doesn't get too long.

The second point is the main motivation for this change, when the line
becomes too long the terminal wraps it to a new physical line. This
means that moving the cursor to the left won't be enough anymore as once
the left border is reached it cannot move anymore.

The wrapped line is still stored by the terminal as a single line,
despite now taking more than a single one when displayed. If you try to
resize the terminal you'll notice how the contents are reflowed and are
essentially illegible.

Querying the cursor position on non-Windows systems (plot twist,
Microsoft suggests using VT escape sequences on newer systems) is
extremely cumbersome so let's do something different.

Before printing anything let's save the cursor position and clear the
screen below the cursor, this way we ensure there's absolutely no trace
of stale data on screen, and after the message is printed we simply
restore it.
2021-03-07 15:23:20 +01:00
Veikka Tuominen
2d286100ef stage1: add tests for nosuspend async/resume 2021-03-07 15:30:59 +02:00
Jonathan Knezek
0447a2c041 Implement fmtDuration using Formatter (#8137)
* Implement fmtDuration using Formatter

Deprecate Duration, duration

* fmtDuration: Fixed ns remainder

* fmtDuration: Fixed visibility; removed [Dd]uration
2021-03-07 15:00:15 +02:00
LemonBoy
72664df491 std: Deprecate the B and Bi format specifiers
Following #8007 and #8137 let's get rid of the last weird format.
2021-03-07 14:58:45 +02:00
LemonBoy
e47b754b28 std: Prevent null pointer deref in mem.len{,Z}
Closes #8140
2021-03-07 14:58:45 +02:00
Evan Haas
6d69a29d75 translate-c: Support compound assignment of pointer and signed int
This handles `ptr += idx` and `ptr -= idx` when `idx` is a
signed integer expression.
2021-03-07 14:54:04 +02:00
Evan Haas
874c63f89c translate-c: translate align attribute for block scoped variables 2021-03-07 14:53:33 +02:00
Josh Wolfe
a7c0234eee docgen --skip-code-tests 2021-03-07 14:52:52 +02:00
Vincent Rischmann
272ae0ca0d fix parsing of assignment with 'inline for' and 'inline while' 2021-03-06 17:39:54 -08:00
Andrew Kelley
34cb5934dd Merge pull request #7910 from Vexu/stage2-async
Stage2: astgen async stuff, implement var args functions
2021-03-06 13:35:48 -08:00
Veikka Tuominen
8c6e7fb2c7 stage2: implement var args 2021-03-06 15:55:29 +02:00
Veikka Tuominen
17e6e09285 stage2: astgen async 2021-03-06 15:01:25 +02:00
Meghan
9f722f43ac std/special: init-exe,lib make import(std) its own decl (#8160)
std/special: init-exe,lib make import(std) its own decl
2021-03-05 19:13:05 -08:00
Isaac Freund
ef3adbdb36 zig fmt: fix lastToken() for container_decl_arg 2021-03-05 21:33:27 +01:00
xackus
eda1b53723 strip the leading zero from octal literals 2021-03-05 21:21:23 +01:00
xackus
eee43a65ae add tests 2021-03-05 21:21:23 +01:00
xackus
b4ef6fa09d fix test-translate-c 2021-03-05 21:04:27 +01:00
Maciej Walczak
5f53b77c2b remove redundant cast
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-03-05 21:04:27 +01:00
xackus
679910ecec translate-c: promote int literals to bigger types 2021-03-05 21:04:27 +01:00
Veikka Tuominen
9cd038d73a std: fix memory leak in MultiArrayList 2021-03-05 10:52:40 -08:00
Evan Haas
291edafa1b translate-c: enable pointer arithmetic with signed integer operand
Given a pointer operand `ptr` and a signed integer operand `idx`

`ptr + idx` and `idx + ptr` -> ptr + @bitCast(usize, @intCast(isize, idx))
`ptr - idx` -> ptr - @bitCast(usize, @intCast(isize, idx))

Thanks @LemonBoy for pointing out that we can take advantage of wraparound
to dramatically simplify the code.
2021-03-05 14:16:40 +02:00
cryptocode
02737d535a Reject bare +/- input when parsing floats 2021-03-05 13:11:20 +01:00
Andrew Kelley
434fce2146 zig fmt: recovery: missing while rbrace
Previously, this test case resulted in zig fmt entering an endless loop.
2021-03-04 20:54:09 -07:00
Andrew Kelley
bccef44196 Merge remote-tracking branch 'origin/master' into llvm12
Syncing with master branch because I want to re-run
update_clang_options.zig in the llvm12 branch.
2021-03-04 18:23:11 -07:00
Andrew Kelley
041212a41c zig cc: fix handling of -MM flag
Clang docs say:
> Like -MMD, but also implies -E and writes to stdout by default.

Previously, Zig handled this option by forwarding it directly to Clang,
and disabling depfiles. However this did not adhere to Clang's documented
behavior of these flags.

Now, in addition to being forwarded directly to Clang, `-MM` also
sets c_out_mode = .preprocessor, just like `-E`.

Another issue I noticed is that Zig did not recognize the aliases for
-MG, -MM, or -MMD. The aliases are now recognized.
2021-03-04 18:14:00 -07:00
Andrew Kelley
98b24aa47f stage2: support environment variables for verbose options
The presence of ZIG_VERBOSE_LINK now enables --verbose-link.
The presence of ZIG_VERBOSE_CC now enables --verbose-cc.

These are useful when debugging usage of `zig cc` which does not have
CLI flags for these options, since they are not valid C compiler flags.
2021-03-04 17:37:53 -07:00
Andrew Kelley
ffb2568a9f Merge pull request #7763 from kivikakk/zig-elf-parse
std.elf: expose parsing decoupled from std.fs.File
2021-03-04 11:56:31 -08:00
daurnimator
34ca6b7b44 std: add io.Writer.writeStruct
We have readStruct, add writeStruct for symmetry
2021-03-03 22:45:45 +01:00
Andrew Kelley
fcd25065ef stage2: fix merge conflict with previous commit
The compiler failed to build from source; this fixes it.
2021-03-03 13:18:13 -07:00
jacob gw
2ebeb0dbf3 stage2: remove error number from error set map
This saves memory since it is already stored in module
as well as allowing for better threading.
Part 2 of what is outlined in #8079.
2021-03-03 11:49:54 -08:00
Veikka Tuominen
904f774563 translate-c: fix c tokenizer giving invalid tokens 2021-03-03 11:33:14 -08:00
Josh Wolfe
7fbe9e7d60 update docs and grammar to allow CRLF line endings (#8063) 2021-03-03 14:30:46 -05:00
Andrew Kelley
5bd9a64516 Merge pull request #7778 from g-w1/stage2-merge-errors
stage2: error set merging with tests
2021-03-02 23:19:22 -08:00
Andrew Kelley
3995783207 astgen: fix crash looking for wrong token in error sets
Fixes a regression from #7920.
2021-03-03 00:17:36 -07:00
Veikka Tuominen
ad3f7e0cf0 fix small inconsistency 2021-03-02 23:53:10 -07:00
g-w1
8b100792eb stage2: error set merging with tests
I had to come up with creative tests because we don't have error set type equality yet.
2021-03-02 23:53:05 -07:00
Andrew Kelley
4b57fb5f23 Merge pull request #7741 from FireFox317/optionals-llvm
stage2: add support for optionals in the LLVM backend
2021-03-02 21:03:50 -08:00
Andrew Kelley
713f113822 stage2: improve orelse implementation
* Now it supports being an lvalue (see additional lines in the test
   case).
 * Properly handles a pointer result location (see additional lines in
   the test case that assign the result of the orelse to a variable
   rather than a const).
 * Properly sets the result location type when possible, so that type
   inference of an `orelse` operand expression knows its result type.
2021-03-02 21:59:23 -07:00
Michael Dusan
0c06a1885f disable failing behavior tests with llvm 12
- consolidate into single code block

    See #8130
    See #8131
2021-03-02 20:14:10 -08:00
Timon Kruiper
6aa1ea9c59 stage2: fixup some formatting errors ({x} -> {s})
These were missed in cd7c870bd8
2021-03-02 19:02:55 -07:00
Timon Kruiper
ed6757ece6 stage2: add a test for for loops in LLVM backend 2021-03-02 19:02:55 -07:00
Timon Kruiper
d4ec0279d3 stage2: add support for optionals in the LLVM backend
We can now codegen optionals! This includes the following instructions:
- is_null
- is_null_ptr
- is_non_null
- is_non_null_ptr
- optional_payload
- optional_payload_ptr
- br_void

Also includes a test for optionals.
2021-03-02 19:02:55 -07:00
Isaac Freund
3ad9cb8b47 zig fmt: allow and trim whitespace around zig fmt: (off|on)
Currently `//  zig fmt: off` does not work as there are two spaces
after the `//` instead of one. This can cause confusion, so allow
arbitrary whitespace before the `zig fmt: (off|on)` in the comment but
trim this whitespace to the canonical single space in the output.
2021-03-03 01:06:09 +01:00
Andrew Kelley
8ca299ddbe disable failing behavior tests with llvm 12
See #8130
2021-03-02 16:54:46 -07:00
Andrew Kelley
84f3b3dff2 re-enable behavior tests: translate-c macros
These were temporarily disabled in
dd973fb365 and we forgot re-enable
them until now.
2021-03-02 16:32:52 -07:00
Andrew Kelley
934b170d67 Revert "update i386 assembly to satisify llvm12"
This reverts commit 6af6c3c979.
2021-03-02 15:03:19 -07:00
Andrew Kelley
c10a2d7649 stage2: use std.zig.fmtId for builtin.zig source 2021-03-02 15:00:10 -07:00
Andrew Kelley
70d100b1e2 update to latest std Thread API 2021-03-02 14:59:34 -07:00
Andrew Kelley
68c00122b1 x86: detect and set 16bit_mode and 32bit_mode CPU features 2021-03-02 14:49:28 -07:00
Vincent Rischmann
3dd8396a55 os/linux: fix IO_Uring.timeout
According to the io_uring PDF (https://kernel.dk/io_uring.pdf) the
timeout struct must be 64 bits on both 32 and 64 bit architectures.
2021-03-02 14:13:11 +02:00
Andrew Kelley
f296c95599 Merge pull request #8120 from joachimschmidt557/stage2-arm
stage2 ARM: implement basic integer multiplication
2021-03-01 19:11:37 -08:00
Andrew Kelley
f9c9b92175 Merge pull request #7946 from koachan/sparc64-framefixes
SPARCv9: Handle various stack frame related quirks.
2021-03-01 19:10:36 -08:00
Andrew Kelley
a20169a610 zig fmt the std lib 2021-03-01 20:04:28 -07:00
Martin Wickham
7613e51a57 Add some bit set variants 2021-03-01 18:52:15 -08:00
daurnimator
1f861ecc95 Bring back ZIG_SKIP_INSTALL_LIB_FILES 2021-03-01 16:23:10 -08:00
Isaac Freund
7b5b7bda87 parser: fix infinite loop on missing comma in param list 2021-03-01 16:09:57 -08:00
joachimschmidt557
278bd60732 stage2 ARM: Add tests for basic integer multiplication 2021-03-02 00:34:41 +01:00
LemonBoy
cd7c870bd8 std: Deprecate 'x'/'X'/'e'/'E' special cases for u8 slices
Let's follow the road paved by the removal of 'z'/'Z', the Formatter
pattern is nice enough to let us remove the remaining four special cases
and declare u8 slices free from any special casing!
2021-03-01 15:33:10 -08:00
joachimschmidt557
345ac53836 stage2 ARM: Implement basic integer multiplication 2021-03-02 00:14:56 +01:00
Timon Kruiper
939f334221 cmake: update findllvm.cmake file to include llvm12 libraries 2021-03-01 12:51:25 -08:00
Andrew Kelley
584cb2e4fb Merge remote-tracking branch 'origin/master' into llvm12 2021-03-01 12:09:26 -07:00
LemonBoy
bee7db77fe std: Replace lastIndexOf with lastIndexOfScalar
This may work around the miscompilation in LLVM 12.
2021-03-01 11:08:16 -08:00
Timon Kruiper
24215df8c5 zig c++: fix compilation that includes any c++ std library file
LLVM 12 included a patch that changed the way availability annotations
are specified. We now have to define the _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
flag to make sure that we tell the c++ headers that we don't use
visibility annotations.

Related LLVM patch: D90843
2021-03-01 11:02:20 -08:00
fancl20
baab1b2f31 std: Add std.fs.path.joinZ (#7974)
* std: Add std.fs.path.joinZ

* Merge std.fs.path.join and std.fs.path.joinZZ tests
2021-03-01 10:38:56 +02:00
Evan Haas
45d220cac6 translate-c: add <assert.h> support
Implement __builtin_expect so C code that uses assert() can be translated.
2021-03-01 10:34:23 +02:00
Michael Dusan
85eb05e9a8 tools/update_cpu_features: fix usage() 2021-02-28 22:47:29 -08:00
Andrew Kelley
72404db31f stage1: update to LLVM 12 sret callsite requirements
Without this, the LLVM IR that zig generates cannot be compiled by LLVM.
2021-02-28 22:01:13 -07:00
Andrew Kelley
6af6c3c979 update i386 assembly to satisify llvm12
Without this, LLVM 12 says:
error: ambiguous instructions require an explicit suffix (could be
'retw', or 'retl')
2021-02-28 21:59:45 -07:00
Andrew Kelley
9550db33cb Merge pull request #8097 from LemonBoy/thread-spawn-order
std: Swap arguments in Thread.spawn
2021-02-28 20:42:34 -08:00
Frank Denis
a5a3ad4f95 std/crypto: add AES-OCB
OCB has been around for a long time.

It's simpler, faster and more secure than AES-GCM.

RFC 7253 was published in 2014. OCB also won the CAESAR competition
along with AEGIS.

It's been implemented in OpenSSL and other libraries for years.

So, why isn't everybody using it instead of GCM? And why don't we
have it in Zig already?

The sad reason for this was patents. GCM was invented only to work
around these patents, and for all this time, OCB was that nice
thing that everybody knew existed but that couldn't be freely used.

That just changed. The OCB patents are now abandoned, and OCB's
author just announced that OCB was officially public domain.
2021-02-28 20:40:49 -08:00
jacob gw
58b14d01ae stage2: remove value field from error
This saves memory and from what I have heard allows threading
to be easier.
2021-02-28 22:01:13 +02:00
daurnimator
1f17221bc4 std: add sendmsg 2021-02-28 21:57:43 +02:00
Evan Haas
294ee1bbc9 translate-c: add limited OffsetOfExpr support
Add support for OffsetOfExpr that contain exactly 1 component, when that component
is a field.

For example, given:

```c
struct S {
  float f;
  double d;
};
struct T {
  long l;
  int i;
  struct S s[10];
};
```

Then:
```c
offsetof(struct T, i)       // supported
offsetof(struct T, s[2].d)  // not supported currently
```
2021-02-28 21:56:57 +02:00
Frank Denis
0423f0f7d8 std/crypto/aes: fix AES {encrypt,decrypt}Wide
These functions are  not used by anything yet, but run the last
round only once.
2021-02-28 21:55:58 +02:00
Frank Denis
b959029f88 std/crypto/benchmark: update format strings
Use the s formatter to format strings.
2021-02-28 21:55:24 +02:00
LemonBoy
d3d3e55fae langref: Update usage of Thread.spawn() 2021-02-28 17:01:30 +01:00
LemonBoy
566adc2510 std: Swap arguments in Thread.spawn
Beside the new order being consistent with the ThreadPool API and making
more sense, this shuffling allows to write the context argument type in
terms of the startFn arguments, reducing the use of anytype (eg. less
explicit casts when using comptime_int parameters, yay).

Sorry for the breakage.

Closes #8082
2021-02-28 14:03:19 +01:00
Andrew Kelley
4b1fe8e492 glibc: clang 12 assembler regression workaround
Our glibc stub assembly file looked something like this:

```
.globl _Exit_2_2_5
.type _Exit_2_2_5, %function;
.symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5
.hidden _Exit_2_2_5
_Exit_2_2_5:
```

With clang 12, the shared objects this produced stopped having any
exported symbols. When I removed the `.hidden` directive, it resolved
the issue, however, there are now unwanted exports:

```
$ readelf -W --dyn-syms libc.so.6 | grep sys_errlist
   139: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist_GLIBC_2_3
   147: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist_GLIBC_2_4
   395: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist_GLIBC_2_2_5
   487: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist_GLIBC_2_2_5
  1266: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@@GLIBC_2.12
  1267: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@GLIBC_2.2.5
  1268: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@GLIBC_2.3
  1269: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@GLIBC_2.4
  2137: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@@GLIBC_2.12
  2138: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@GLIBC_2.2.5
  2139: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@GLIBC_2.3
  2140: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@GLIBC_2.4
  2156: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist_GLIBC_2_3
  2161: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist_GLIBC_2_4
```

Every line here without an `@` symbol is an unwanted export. Before, the
unwanted ones had LOCAL HIDDEN linkage.

As a mitigation, I did two things:

 * Added `_GLIBC_` to the unwanted exports so that they would not
   conflict with anything.
 * Made the default export (the `@@` one) the bare symbol name. This
   appears to reduce the unwanted exports to only symbols that have more
   than one symbol (which is still quite many).

This will unblock progress on this branch, however, there is now a new
issue to solve, that the provided glibc stub .so files have too many
symbols exported. We will have to find a way to avoid this.
2021-02-28 00:53:05 -07:00
Andrew Kelley
ab36a162d0 update ARM target CPU features
This completes the process. All target CPU features are now
auto-generated by the tools/update_cpu_features.zig script, which
contains all the overrides.

Invoking this tool against LLVM 12rc2 now produces an empty git diff.
2021-02-27 21:10:00 -07:00
Andrew Kelley
85ab1b01e7 tools/update_cpu_features: add a "flatten" feature
and use it to clean up aarch64 target CPU features
2021-02-27 17:26:06 -07:00
Andrew Kelley
e02acc0288 tools/update_cpu_features: better patching API
With this change, added & modified cpus & features participate in the
same pruning system, and sorting takes into account the zig name, not
the pre-modified llvm name.

The modified target files in this commit are due to the improved
sorting and pruning.

The script now fully supports extra cpus & features.
2021-02-27 15:57:01 -07:00
Michael Dusan
e65b6d99ac std.zig.fmtEscapes: update impacted test 2021-02-27 12:53:49 -07:00
Michael Dusan
9082d76168 std.zig.fmtEscapes: update impacted test 2021-02-27 11:53:08 -08:00
Michael Dusan
6fe2fb6cdb std.Target.Abi: add gnuilp32 2021-02-27 11:53:08 -08:00
daurnimator
d4af35b3fe HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
Andrew Kelley
280195038a std.Target: add powerpcle 2021-02-27 02:51:35 -07:00
Andrew Kelley
9e8943736e Merge remote-tracking branch 'origin/master' into llvm12 2021-02-27 02:25:58 -07:00
Andrew Kelley
d91605e27e tools/update_cpu_features: consistent naming of neoverse cpus 2021-02-27 02:25:15 -07:00
Andrew Kelley
02bda72d91 update amdgpu target CPU features 2021-02-27 01:54:07 -07:00
Andrew Kelley
a9f19221e9 update RISC-V target CPU features 2021-02-27 01:49:35 -07:00
Andrew Kelley
490654c332 std.ascii: add lessThanIgnoreCase and orderIgnoreCase
For sorting ascii strings, case insensitively.
2021-02-27 01:21:01 -07:00
Andrew Kelley
4a548002af translate-c: upgrade to new std.zig.fmtEscapes API
fixes regressions from previous commit
2021-02-27 01:20:19 -07:00
Andrew Kelley
50a5fc98dc update most target CPU features to llvm12
The tools/update_cpu_features script is coming along, and generates
correct information for all these targets. The remaining targets are:

 * arm
 * aarch64
 * amdgpu
 * riscv

I will commit them once the issues with the updater tool are resolved.
2021-02-27 01:05:53 -07:00
Andrew Kelley
59b4facd34 update x86 CPU features 2021-02-27 00:54:40 -07:00
Andrew Kelley
45739725c1 tools/update_cpu_features: prune redundant features
When a CPU feature implies that another one must be present, avoid
redundantly specifying the other one.
2021-02-27 00:50:23 -07:00
Andrew Kelley
3f844cba0b std.zig.fmt escaped string formatting recognizes single quote style
This introduces {'} to indicate escape for a single-quoted string,
and {} to indicate escape for a double quoted string.

Without this, there would be unnecessary \' inside double quoted
strings, and unnecessary \" inside single quoted strings.

Motivated by the llvm12 branch, in the new tool I am writing for
updating target CPU features.
2021-02-27 00:27:53 -07:00
Andrew Kelley
03de5ec6dd tools/update_cpu_features: handle ISAs with no features
These are represented by not having a file for them.
2021-02-26 23:52:04 -07:00
Andrew Kelley
a804944c7d tools/update_cpu_features: branch quota where necessary
also avoid unnecessary escaping of single quotes inside double quoted
strings (depends on a master branch commit that will be merged into this
branch in a future commit)
2021-02-26 23:21:05 -07:00
Andrew Kelley
2733ca91b2 introduce tools/update_cpu_features.zig
This replaces the previous target cpu features tool, taking advantage of
llvm-tblgen --dump-json instead of trying to use python to parse the .td
files.

This is an initial version that has the basics working, including a
simple feature override system, as well as multi-threaded processing.

Follow-up commits will do clean ups to make the diff of the newly generated
source files against previous versions be as desired.
2021-02-26 21:16:04 -07:00
Andrew Kelley
3519b74c06 zig cc: update clang command line options to LLVM 12 rc2 2021-02-26 15:00:41 -07:00
Michael Dusan
659f712ae8 llvm12: sync with llvmorg-12.0.0-rc2
- update lib/include
- update lib/libcxx
- update lib/libcxxabi
- update lib/libunwind
- (no changes) src/libcxx.zig
- (no changes) src/libunwind.zig
2021-02-26 13:44:33 -08:00
LemonBoy
b706b9bce7 stage1: Fix emission of sret annotation for LLVM
LLVM12 deprecated `sret` and replaced it with the `sret(<Ty>)` form.

Closes #8075
2021-02-26 12:48:27 -08:00
Andrew Kelley
431801707f Revert "stage1: upgrade to new LLVM sret attribute requirement"
This reverts commit 685b5c26b7.

@LemonBoy has a better patch, so reverting this to merge that one.
2021-02-26 13:47:33 -07:00
Andrew Kelley
685b5c26b7 stage1: upgrade to new LLVM sret attribute requirement
LLVM 12 requires sret attributes to have the struct type as a parameter,
and provides no C function for supplying it. Therefore, we must add
another C++ wrapper API for adding the sret attribute.

Fixes ability to build from source in the llvm12 branch.
2021-02-26 13:32:04 -07:00
Evan Haas
0816981561 translate-c: add typeof support 2021-02-25 22:33:42 -08:00
Andrew Kelley
70e935db5b translate-c: fix botched merge conflict
Previous commit failed to correctly solve the translate-c merge
conflict; this commit fixes it.
2021-02-25 21:27:56 -07:00
Andrew Kelley
0b58b61799 Merge remote-tracking branch 'origin/master' into llvm12
Conflicts:
 * src/clang.zig
 * src/llvm.zig
   - this file got moved to src/llvm/bindings.zig in master branch so I
     had to put the new LLVM arch/os enum tags into it.
 * lib/std/target.zig, src/stage1/target.cpp
   - haiku had an inconsistency with its default target ABI, gnu vs
     eabi. In this commit we make it gnu in both places to match the
     latest changes by @hoanga.
 * src/translate_c.zig
2021-02-25 21:04:23 -07:00
Michael Dusan
dc325669e3 fix to compile against 12.0.0-rc2 2021-02-25 19:41:30 -08:00
Andrew Kelley
fd208d9d59 stage2: implement the error_value AST tag 2021-02-25 18:21:22 -07:00
Andrew Kelley
4360f45d7f std.os: remove special case for haiku
This is an accident from a merge conflict introduced in
7edb204edf.

The new pipe2 code I believe is supposed to work for all posix-like
systems. If haiku needs special handling here, it should be
re-introduced.
2021-02-25 17:42:14 -07:00
g-w1
153c97ac9e improve stage2 to allow catch at comptime:
* add error_union value tag.
* add analyzeIsErr
* add Value.isError
* add TZIR wrap_errunion_payload and wrap_errunion_err for
  wrapping from T -> E!T and E -> E!T
* add anlyzeInstUnwrapErrCode and analyzeInstUnwrapErr
* add analyzeInstEnsureErrPayloadVoid:
* add wrapErrorUnion
* add comptime error comparison for tests
* tests!
2021-02-25 16:41:16 -08:00
Andrew Kelley
7edb204edf Merge pull request #7546 from hoanga/haiku-support
initial support for haiku
2021-02-25 16:00:00 -08:00
Andrew Kelley
37a1d08de2 haiku: minor fixups
* no isHaiku() function since there is not more than one os tag that
   this applies to.
 * clean up some control flow into a switch
 * add some TODO comments to investigate panics that suspiciously look
   like they should be compile errors (see #363)
2021-02-25 16:54:32 -07:00
Al Hoang
96a08c1698 initial support for haiku defer debug 2021-02-25 16:41:42 -07:00
Al Hoang
c17396691c initial support for haiku sync update
* add cpu count
* use haiku find_directory
* add definitions and exports for building in haiku
2021-02-25 16:41:42 -07:00
Al Hoang
6b0372229d initial support for haiku continue clean up
* remove unused definitions
* setup os specific blocks
2021-02-25 16:41:42 -07:00
Al Hoang
025635c3f8 initial support for haiku past stage0 2021-02-25 16:41:42 -07:00
joachimschmidt557
297eabd4ac stage2 ARM: Save callee-saved registers
Add a new allocated_registers bitmap to keep track of all callee-saved
registers allocated during generation of this function.

Function(.arm).gen uses this data to generate instructions in the
function prologue and epilogue to push and pop these registers
respectively.
2021-02-25 22:27:19 +02:00
Hubert Jasudowicz
3c0238e731 std/build: Add support for LTO configuration 2021-02-25 22:25:42 +02:00
Evan Haas
4f11a88b9f translate-c: Add support for pointer subtraction
When two pointers are subtracted, both shall point to elements of the
same array object, or one past the last element of the array object;
the result is the difference of the subscripts of the two array elements.

The size of the result is implementation-defined, and its type
(a signed integer type) is ptrdiff_t defined in the <stddef.h> header.
If the result is not representable in an object of that type,
the behavior is undefined.

See C Standard, §6.5.6 [ISO/IEC 9899:2011]

Fixes #7216
2021-02-25 22:24:11 +02:00
LemonBoy
53cc63f0c9 std: Clear old memory on free
Re-enable the clear-on-free step, it was previously disabled due to
translate-c using freed memory.
2021-02-25 22:20:30 +02:00
Andrew Kelley
449f4de382 zig fmt src/ 2021-02-24 21:54:23 -07:00
Andrew Kelley
9b8a94265a zig fmt: fix extern function with missing param name
Regressed in d7049fc8e0.
2021-02-24 21:50:57 -07:00
Andrew Kelley
5f35dc0c0d zig fmt the std lib 2021-02-24 21:29:23 -07:00
Andrew Kelley
d7049fc8e0 Merge pull request #7920 from ziglang/ast-memory-layout
Rework AST memory layout for better memory usage and performance
2021-02-24 18:49:07 -08:00
Andrew Kelley
9ada7638a5 zig fmt: function with labeled block as return type 2021-02-24 16:42:46 -07:00
Andrew Kelley
c79ee1fc8d build.zig: expose a strip option 2021-02-24 16:36:27 -07:00
Andrew Kelley
8e6c2b7a47 Merge remote-tracking branch 'origin/master' into ast-memory-layout 2021-02-24 15:08:23 -07:00
Andrew Kelley
38441b5eab MultiArrayList: use @memcpy as a workaround
Reverts bf642204b3 and uses a different
workaround, suggested by @LemonBoy.

There is either a compiler bug or a design flaw somewhere around here.
It does not have to block this branch, but I need to understand exactly
what's going on here and make it so that nobody ever has to run into
this problem again.
2021-02-24 12:49:12 -07:00
Isaac Freund
52c45bf44d zig fmt: rework single statement if/while/for indentation
This approach properly handles nesting unlike the approach in the
previous commit.
2021-02-24 17:28:29 +01:00
Josh Wolfe
8b9434871e Avoid concept of a "Unicode character" in documentation and error messages (#8059) 2021-02-24 08:26:13 -05:00
Isaac Freund
371b21bdfb zig fmt: fix comment indent after multiline single statement if/while/for 2021-02-24 13:46:11 +01:00
Isaac Freund
15c7c6ab97 zig fmt: handle comments in switch case value list 2021-02-24 12:29:17 +01:00
Isaac Freund
1b8eca030e zig fmt: fix firstToken() for switch_case 2021-02-24 12:14:15 +01:00
Andrew Kelley
db4c15be50 zig fmt: respect extra newline between fn and pub usingnamespace 2021-02-23 23:01:16 -07:00
Andrew Kelley
bf642204b3 std.MultiArrayList: add workaround for LLVM bug 2021-02-23 22:24:59 -07:00
Andrew Kelley
05f304807f zig fmt: add 3 more disabled failing test cases
Found by running `zig fmt` on the std lib.
2021-02-23 18:48:01 -07:00
Andrew Kelley
4420fe97be zig fmt: for loop with ptr payload and index 2021-02-23 18:33:13 -07:00
Andrew Kelley
988f1c6a6f zig fmt: fn proto end with anytype and comma
also

zig fmt: space after top level doc comment
2021-02-23 18:23:49 -07:00
Andrew Kelley
08107a555e zig fmt: fix inline assembly test cases
All zig fmt test cases are now passing again in this branch.
2021-02-23 17:19:01 -07:00
Andrew Kelley
bb89c619ed zig fmt: multiline string literals + array init 2021-02-23 17:00:33 -07:00
Andrew Kelley
6f4a1bafcf zig fmt: fn call with comments and multiline strings
forcing the parameters over multiple lines
2021-02-23 16:09:51 -07:00
Isaac Freund
4ee368c4b3 zig fmt: comments/line breaks in field access chain 2021-02-23 23:17:38 +01:00
Andrew Kelley
ca9259340d zig fmt now intentionally respects all empty line comments 2021-02-23 14:30:21 -07:00
Andrew Kelley
f041425e48 translate-c: fix using wrong slice and AST tag 2021-02-23 13:55:12 -07:00
Andrew Kelley
01e89c9171 translate-c: update to latest AST tag changes 2021-02-23 12:39:50 -07:00
Isaac Freund
b028a92a60 zig fmt: handle comments in array type/init/access 2021-02-23 19:56:56 +01:00
Isaac Freund
abfe213830 zig fmt: enable array init trailing comment insertion test
Modify the test case slightly to match similar modifications done in
5820bd0 and 0f24b61.
2021-02-23 19:40:34 +01:00
Isaac Freund
6b9f19a644 zig fmt: remove stray std.debug.print() 2021-02-23 19:18:36 +01:00
Isaac Freund
0f24b61ed5 zig fmt: insert trailing comma in struct init with comment 2021-02-23 19:17:11 +01:00
Isaac Freund
5820bd0e64 zig fmt: insert trailing comma in fn params with comment 2021-02-23 19:11:50 +01:00
Isaac Freund
5306b1a9ab zig fmt: container doc comments 2021-02-23 18:32:47 +01:00
johnLate
d9e46dceec std.Thread.Semaphore: Fix wrong variable name
Fixes ziglang#8052
2021-02-23 11:10:24 +02:00
Veikka Tuominen
1f62e87031 fix formatting in translate-c test case 2021-02-23 10:53:25 +02:00
Andrew Kelley
1e3a200ba6 zig fmt: array literal with hint
This regresses the test case of `zig fmt` deleting empty line comments.
Two open questions here:

 * What should the rules be about deleting empty line comments?
   It makes sense usually, but for array initization, empty line
   comments cause a line break, affecting the row/column alignment.
   Perhaps we should therefore respect all empty line comments?
   Or should we special case array initializations?

 * If we decide to special case some kinds of line comments to respect
   them (which is status quo!), how should that be implemented?
2021-02-22 23:25:12 -07:00
Andrew Kelley
1253903fef zig fmt: struct literal containing a multiline expression
I modified this test case to expect different results.

Now, the trailing comma on a list of struct fields is the only deciding
factor, not whether or not the field init expressions contain a newline.
2021-02-22 21:33:21 -07:00
Andrew Kelley
8379fff804 zig fmt: alignment in anonymous literal 2021-02-22 21:04:22 -07:00
Andrew Kelley
a6038f0375 zig fmt: function params should align nicely 2021-02-22 18:17:26 -07:00
Andrew Kelley
fec51ad7c5 zig fmt: while 2021-02-22 17:55:19 -07:00
Andrew Kelley
20cfa0b5b6 zig fmt: if condition has line break, no fn call comma 2021-02-22 17:34:30 -07:00
Andrew Kelley
ec987a7a46 zig fmt: if condition has line break but must not wrap 2021-02-22 16:39:50 -07:00
Andrew Kelley
b301999cd3 zig fmt: if condition wraps 2021-02-22 16:21:19 -07:00
Andrew Kelley
253906fb93 zig fmt: 2nd arg multiline string 2021-02-22 16:00:21 -07:00
Isaac Freund
45634851de zig fmt: fix firstToken() for extern fn_protos 2021-02-22 23:51:54 +01:00
Isaac Freund
550688f427 zig fmt: insert trailing comma in switches 2021-02-22 23:51:54 +01:00
Veikka Tuominen
4758e0c9a6 update docgen to use new ast 2021-02-22 21:52:22 +02:00
Veikka Tuominen
d83698ab54 translate-c: check for noreturn in switch in more cases 2021-02-22 21:52:22 +02:00
Isaac Freund
f3ee10b454 zig fmt: fix comments ending with EOF after decls
Achieve this by reducing the amount of special casing to handle EOF so
that the already correct logic for normal comments does not need to be
duplicated.
2021-02-22 18:32:37 +01:00
Veikka Tuominen
011bc1b84f translate-c: switch default should have an empty block not break 2021-02-22 19:26:19 +02:00
Isaac Freund
ce9b3ee0f9 parser: anytype is not a vaild return type 2021-02-22 17:38:09 +01:00
Isaac Freund
34c08a91d5 zig fmt: fix formatting of parser tests 2021-02-22 17:37:17 +01:00
Veikka Tuominen
928790364a zig fmt: correct Node.firstToken for .fn_decl, add error for missing container 2021-02-22 17:39:41 +02:00
Veikka Tuominen
69d5a106da render: handle comments ending in EOF 2021-02-22 16:59:44 +02:00
Veikka Tuominen
67dac2936c parser: warn on missing for loop payload, recover from invalid global error set access 2021-02-22 10:04:05 +02:00
Andrew Kelley
621ad241d6 zig fmt: if nested 2021-02-21 20:25:31 -07:00
Andrew Kelley
a17a5ca3a8 translate-c: fix fn_decl vs fn_proto
Regressed in 15603f403c.
2021-02-21 18:31:32 -07:00
Andrew Kelley
c6efb23796 zig fmt: rewrite inline functions as callconv(.Inline) 2021-02-21 18:20:46 -07:00
Andrew Kelley
878e99d580 parser: fix recovery for missing semicolons 2021-02-21 18:04:23 -07:00
Andrew Kelley
1247b7b9ef parser: modify another recovery test case
Zig no longer has `error` as the global error set; it is now a special
case keyword. The new parse error message is correct.
2021-02-21 18:00:37 -07:00
Andrew Kelley
79f1876367 parser: remove support for recovering from extra top level end curlies
After #35 is implemented,
we should be able to recover from this *at any indentation level*,
reporting a parse error and yet also parsing all the decls even
inside structs. Until then, I don't want to add any hacks to make
this work.
2021-02-21 17:57:04 -07:00
Andrew Kelley
2da2123128 parser: remove support for a recovery test case
I don't understand the idea here of this kind of recovery. If we
want to resurrect this test case we need some comments on it to explain
the purpose, example use cases, expected behavior, etc.
2021-02-21 17:37:39 -07:00
Andrew Kelley
866f7dc7d6 parser: support more recovery test cases 2021-02-21 17:37:10 -07:00
Andrew Kelley
15603f403c AST: use fn_proto not fn_decl for extern decls
saves a few bytes per extern function declaration
2021-02-21 16:01:22 -07:00
ducdetronquito
0aef1faa82 std.fifo.LinearFifo - Expose reader and writer type. 2021-02-22 00:22:46 +02:00
Ryan Greenblatt
36178caf3e Added support for passing write file args as build options (#7909)
* Added support for passing write file args as build options

* Fix missing fmtEscapes and unused format

* Actually fixed now, must be formatted

* remove addPathBuildOption
2021-02-21 12:26:46 +02:00
joachimschmidt557
9712e89265 stage2 codegen: Add Type argument to genSetReg 2021-02-21 12:23:36 +02:00
Veikka Tuominen
ef6aa3d027 Merge pull request #7960 from Luukdegram/wasm-extern
stage2: Add support for extern functions for the wasm backend
2021-02-21 12:22:01 +02:00
LemonBoy
057bf1afc9 std: Add more error checking in hexToBytes
Prevent the function from turning into an endless loop that may or may
not perform OOB accesses.
2021-02-21 12:19:03 +02:00
Asherah Connor
4272f07f66 std.os.uefi.Guid fixes (#8032)
* uefi: Guid.format compiles again

Also use "writer" nomenclature in argument name.

* uefi: add Guid.eql
2021-02-21 12:17:59 +02:00
Bill Nagel
cc5e5cca83 fix race condition in linuxWaitFd 2021-02-21 12:16:48 +02:00
jacob gw
1bd434fd18 std.Progress: improve support for "dumb" terminals 2021-02-21 12:12:17 +02:00
Tau
840331ee48 Rebase link(at) properly 2021-02-21 12:04:40 +02:00
Benjamin Graf
c70832bc41 replace ArrayList.shrinkAndFree by ArrayList.shrinkRetainingCapacity 2021-02-21 11:56:14 +02:00
Jonathan Marler
a448210fcf remove z/Z format specifier deprecations
The z/Z format specifiers were merged last October (4 months ago).  They were then deprecated in January (just over a month ago).  This PR removes them altogether.
2021-02-21 11:55:21 +02:00
rgreenblatt
f9be7471bc fix readable slice bug (and add tests) 2021-02-21 11:48:38 +02:00
data-man
340825a7af Add epoll_pwait2 Linux syscall 2021-02-21 11:47:13 +02:00
Andrew Kelley
88d0e77b97 parse: implement error for invalid bit range and alignment 2021-02-21 00:18:20 -07:00
rgreenblatt
a5dcd07382 fix unspecified fmt 2021-02-21 01:31:46 +02:00
Veikka Tuominen
4074e79748 translate-c: use global scope for typedef/record/enum type translation if needed
If the type is a reference to a global declaration that has not yet
been translated we need to use the global scope for translation
so that other functions can also reference it.
2021-02-20 13:32:07 +02:00
Andrew Kelley
669c2054a8 stage2: debug line nops supports bigger padding 2021-02-19 22:55:42 -07:00
Andrew Kelley
ed1e5cb3f6 stage2: fix a couple off by one errors
All stage2 tests are passing again in this branch.

Remaining checklist for this branch:
 * get the rest of the zig fmt test cases passing
   - re-enable the translate-c test case that is blocking on this
 * implement the 2 `@panic(TODO)`'s in parse.zig
 * use fn_proto not fn_decl for extern function declarations
2021-02-19 21:47:11 -07:00
Michael Dusan
153cd4da0c macos: fix cond to enable ZIG_SYSTEM_LINKER_HACK
closes #8037
2021-02-19 23:37:13 -05:00
Andrew Kelley
5b597a16c6 stage2: fix not setting up ZIR arg instruction correctly
This is a regression from when I briefly flirted with changing how arg
ZIR instructions work in this branch, and then failed to revert it
correctly.
2021-02-19 20:57:06 -07:00
Andrew Kelley
d8560edc29 stage2: fix incorrect ast.Tree.getNodeSource impl 2021-02-19 20:28:47 -07:00
Andrew Kelley
70761d7c52 stage2: remove incorrect newlines from log statements 2021-02-19 20:27:06 -07:00
Andrew Kelley
6959b177ef stage2: test harness: panic on OOM rather than assert
also add a prefix to test names for C backend
2021-02-19 20:26:48 -07:00
Andrew Kelley
8fee41b1d5 stage2: AST: clean up parse errors
* struct instead of tagged union
 * delete dead code
 * simplify parser code
 * remove unnecessary metaprogramming
2021-02-19 18:04:52 -07:00
Andrew Kelley
74878565e5 readme: update introduction link 2021-02-19 16:38:04 -07:00
Isaac Freund
95b95ea33e stage2: make same line doc comments a parse error
Allowing same line doc comments causes some ambiguity as to how
generated docs should represent the case in which both same line
and preceding line doc comments are present:

/// preceding line
const foobar = 42; /// same line

Furthermore disallowing these makes things simpler as there is now only
one way to add a doc comment to a decl or struct field.
2021-02-19 22:59:27 +01:00
Veikka Tuominen
6f6568b1fd translate-c: correctly add semicolon to if statements 2021-02-19 20:48:06 +02:00
Veikka Tuominen
d672c20b8a Merge pull request #7479 from ziglang/translate-c-ast
Make translate-c use intermediate AST
2021-02-19 13:03:29 +02:00
Veikka Tuominen
974a1c5525 translate-c: small fixes to avoid generating invalid code for macros 2021-02-19 12:50:42 +02:00
Andrew Kelley
914540ddb5 astgen: fix remaining compile errors
Now it builds and what remains in this branch is:
 * fix the stage2 compiler regressions from this branch
 * finish the rest of zig fmt test cases, get them passing
 * Merge in Vexu's translate-c AST branch & fix translate-c regressions
2021-02-19 00:04:31 -07:00
Andrew Kelley
9010bd8aec stage2: astgen: fix most of the remaining compile errors
more progress on converting astgen to the new AST memory layout.
only a few code paths left to update.
2021-02-18 20:09:29 -07:00
Veikka Tuominen
3aba1fa04f translate-c: ensure failed macros don't get defined multiple times 2021-02-19 01:52:27 +02:00
Veikka Tuominen
df5a8120df translate-c: small miscellaneous improvements 2021-02-18 21:34:31 +02:00
Andrew Kelley
29daf10639 stage2: fix a couple more compilation errors 2021-02-17 22:34:06 -07:00
Andrew Kelley
5a2620fcca stage2: fix some of the compilation errors in this branch 2021-02-17 22:22:10 -07:00
Andrew Kelley
c66481f9bc astgen: finish updating expressions to new mem layout
Now all that is left is compile errors and whatever regressions this
branch introduced.
2021-02-17 20:59:21 -07:00
Veikka Tuominen
7ca53bdfaa translate-c: improve switch translation 2021-02-17 22:11:26 +02:00
Evan Haas
3717bedb4e translate-c: Add test for using correct block label for StmtExpr
The previous iteration of translate-c used an incorrect block label
in the break statement for a translated C statement expression. This adds
a test to ensure the correct label is used in the new intermediate AST
version of translate-c.
2021-02-17 16:27:21 +02:00
Veikka Tuominen
d5fecbd0ba translate-c: support scoped typedef, enum and record decls
Closes #5256
2021-02-17 16:26:11 +02:00
Veikka Tuominen
e2974759dd translate-c: demote untranslatable declarations to externs 2021-02-17 14:11:49 +02:00
Mathieu Guay-Paquet
93f8110e5d Allow async in nosuspend scope
Starting an async function call is actually a synchronous operation,
since the caller is not awaiting on the callee for a return value.

This commit removes the compiler code which generates the error and
updates the relevant test case.

In the presence of CallModifierAsync, the callee is expected to
suspend, so it should not be changed to CallModifierNoSuspend.
2021-02-16 23:43:36 -05:00
Mathieu Guay-Paquet
c0cfbe98f3 Allow resume in nosuspend scope
Resuming a suspended async function call is actually a synchronous
operation.

This commit removes the compiler code which generates the error and
updates the relevant test case.
2021-02-16 21:51:19 -05:00
Isaac Freund
4b226286e8 zig fmt: get rid of Space.no_comment
Using this in its current state would be a bug as it could cause line
comments to be deleted or a `// zig fmt: (on|off)` directive to be
missed.

Removing it doesn't currently cause any test failures, if a reason for
its continued existence is discovered in the future another solution
will have to be found.
2021-02-17 00:03:39 +01:00
Isaac Freund
895fb2bd6d zig fmt: implement 'zig fmt: (on|off)' directives
With the new implementation, these now work anywhere in the source code
as opposed to only at the top level.
2021-02-16 23:20:53 +01:00
Isaac Freund
070e548acf std: remove io.AutoIndentingStream
This type is not widely applicable enough to be a public part of the
public interface of the std.

The current implementation in only fully utilized by the zig fmt
implementation, which could benefit by even tighter integration as
will be demonstrated in the next commit. Therefore, move the current
io.AutoIndentingStream to lib/std/zig/render.zig.

The C backend of the self hosted compiler also use this type currently,
but it does not require anywhere near its full complexity. Therefore,
implement a greatly simplified version of this interface in
src/codegen/c.zig.
2021-02-16 23:20:46 +01:00
Andrew Kelley
68e7726478 std.fs.net.Stream: add writev and writevAll
I noticed that the write function does not properly use non-blocking
I/O. This file needs to be reworked for evented I/O to properly take
advantage of non-blocking writes to network sockets.
2021-02-16 11:01:17 -07:00
Veikka Tuominen
9a826ccbe0 translate-c: elide some unecessary casts of literals 2021-02-16 16:40:43 +02:00
Veikka Tuominen
74e9d4ca82 translate-c: get all translate-c tests passing 2021-02-16 16:40:43 +02:00
Veikka Tuominen
78fba4e021 translate-c: get all run-translated-c tests passing 2021-02-16 16:40:43 +02:00
Veikka Tuominen
77a11e6873 translate-c: render records and enums 2021-02-16 16:40:43 +02:00
Veikka Tuominen
c0540967e9 translate-c: render array stuff 2021-02-16 16:40:43 +02:00
Veikka Tuominen
62162a0717 translate-c: render control flow 2021-02-16 16:40:42 +02:00
Veikka Tuominen
c4dfabf4dc translate-c: render macro functions, use cast type as return type
Closes #8004
2021-02-16 16:40:42 +02:00
Veikka Tuominen
f191251ddb translate-c: render functions 2021-02-16 16:40:42 +02:00
Veikka Tuominen
227f167958 translate-c: render binops and break/continue 2021-02-16 16:40:42 +02:00
Veikka Tuominen
685778c5a7 translate-c: render unary ops 2021-02-16 16:40:42 +02:00
Veikka Tuominen
1147ecc5fd translate-c: render variables and builtin calls 2021-02-16 16:40:42 +02:00
Veikka Tuominen
d7460db044 translate-c: render a bunch of simple nodes and calls 2021-02-16 16:40:39 +02:00
Veikka Tuominen
13a9db2085 translate-c: begin implementing ast.render 2021-02-16 16:40:06 +02:00
Veikka Tuominen
2a74a1ebaa translate-c: bunch of small fixes to get it compiling 2021-02-16 16:40:06 +02:00
Veikka Tuominen
66bbd75a83 translate-c: convert macro translation 2021-02-16 16:40:06 +02:00
Veikka Tuominen
c30c2f7c13 translate-c: convert assignment and conditional exprs 2021-02-16 16:40:05 +02:00
Veikka Tuominen
450b718b9e translate-c: convert field/array access, call, pre/postcrement 2021-02-16 16:40:05 +02:00
Veikka Tuominen
cadd4483be translate-c: convert switch 2021-02-16 16:40:05 +02:00
Veikka Tuominen
66dd64ec15 translate-c: convert most control flow 2021-02-16 16:40:05 +02:00
Veikka Tuominen
d8b9fca0b1 translate-c: convert casts and string/array init 2021-02-16 16:40:05 +02:00
Veikka Tuominen
5dac3683c9 translate-c: convert record and enum decls 2021-02-16 16:40:05 +02:00
Veikka Tuominen
bb867b071a translate-c: convert vardecl and typedef 2021-02-16 16:40:02 +02:00
Veikka Tuominen
f36849fed2 translate-c: convert function translation 2021-02-16 16:37:08 +02:00
Veikka Tuominen
7514c0ad0d translate-c: unary operator, integers and misc 2021-02-16 16:37:08 +02:00
Veikka Tuominen
f5041caa2e translate-c: more binaryoperator chagnes, blocks and unary type expressions 2021-02-16 16:37:07 +02:00
Veikka Tuominen
4c0c9b0755 translate-c: convert transBinaryOperator 2021-02-16 16:37:07 +02:00
Veikka Tuominen
d835f5cce5 translate-c: make Node more like Type 2021-02-16 16:37:07 +02:00
Veikka Tuominen
6ecec4c8b7 translate-c: translate C types to stage2 types 2021-02-16 16:37:07 +02:00
Veikka Tuominen
7051ef32bf translate-c: start creating intermediate AST 2021-02-16 16:37:07 +02:00
Andrew Kelley
4006a3afb3 astgen: update more expression types to new mem layout
additionally introduce a new file to centralize all the data about
builtin functions that we have, including:
 * enum tag identifying the builtin function
 * number of parameters.
 * whether the expression may need a memory location.
 * whether the expression allows an lvalue (currently only true for
   `@field`).
Now there is only one ComptimeStringMap that has this data as the value,
and we dispatch on the enum tag in order to asgen the builtin function.
In particular this simplifies the logic for checking the number of
parameters.

This removes some untested code paths from if and while, which need to
be restored with #7929 in mind.

After this there are only a handful left of expression types to rework
to the new memory layout, and then it will be only compile errors left
to solve.
2021-02-15 22:36:46 -07:00
Isaac Freund
bbf5a4d7c5 zig fmt: fix inferred error union return types 2021-02-15 13:54:48 +01:00
Andrew Kelley
c2b4d51749 astgen: update a handful of expression types to new mem layout
break, continue, blocks, bit_not, negation, identifiers, string
literals, integer literals, inline assembly

also gave multiline string literals a different node tag from regular
string literals, for code clarity and to avoid an unnecessary load from
token_tags array.
2021-02-13 21:40:12 -07:00
Isaac Freund
24798b84ad zig fmt: implement multiline string literals 2021-02-13 16:57:34 -08:00
Isaac Freund
75ba8d8db6 zig fmt: remove empty lines at start/end of block 2021-02-13 16:57:34 -08:00
Andrew Kelley
7630a5c566 stage2: more progress towards Module/astgen building with new mem layout 2021-02-12 23:47:17 -07:00
Tadeo Kondrak
9270aae071 stage2: fix zero-sized function parameters (#7998) 2021-02-12 15:40:44 -05:00
Andrew Kelley
a9db40e870 zig fmt: add failing test case for inline/callconv conversion 2021-02-11 23:53:04 -07:00
Andrew Kelley
b4e344bcf8 Merge remote-tracking branch 'origin/master' into ast-memory-layout
Conflicts:
 * lib/std/zig/ast.zig
 * lib/std/zig/parse.zig
 * lib/std/zig/parser_test.zig
 * lib/std/zig/render.zig
 * src/Module.zig
 * src/zir.zig

I resolved some of the conflicts by reverting a small portion of
@tadeokondrak's stage2 logic here regarding `callconv(.Inline)`.
It will need to get reworked as part of this branch.
2021-02-11 23:45:40 -07:00
Andrew Kelley
3d0f4b9030 stage2: start reworking Module/astgen for memory layout changes
This commit does not reach any particular milestone, it is
work-in-progress towards getting things to build.

There's a `@panic("TODO")` in translate-c that should be removed when
working on translate-c stuff.
2021-02-11 23:29:55 -07:00
Veikka Tuominen
288e180598 snake_case render.Space 2021-02-12 02:14:07 +02:00
Veikka Tuominen
bb22490fcc snake_case Node.Tag 2021-02-12 02:12:43 +02:00
Veikka Tuominen
e2289961c6 snake_case Token.Tag 2021-02-12 02:12:00 +02:00
Andrew Kelley
d3565ed6b4 Merge pull request #7749 from tadeokondrak/6429-callconv-inline
Replace inline fn with callconv(.Inline)
2021-02-11 16:01:58 -08:00
Isaac Freund
faa3fa65ac zig fmt: implement line comments 2021-02-11 15:49:49 -08:00
Isaac Freund
b6448a533d zig fmt: fix Tree.lastToken() for empty *Two nodes 2021-02-11 15:49:49 -08:00
Evan Haas
d98f09e4f6 translate-c: comma operator should introduce a new scope
This prevents inadvertent side-effects when an expression is not evaluated
due to boolean short-circuiting

Fixes #7989
2021-02-12 01:40:43 +02:00
Tadeo Kondrak
bb4f4c043e test/cli.zig: Remove inline from panic function in testGodboltApi
Might add another line to stack traces there.
2021-02-10 20:22:20 -07:00
Tadeo Kondrak
bcc13597fc translate_c: switch from inline fn to callconv(.Inline) 2021-02-10 20:22:19 -07:00
Tadeo Kondrak
7644e9a752 stage2: switch from inline fn to callconv(.Inline) 2021-02-10 20:22:18 -07:00
Tadeo Kondrak
1c15091bc8 stage1: switch from inline fn to callconv(.Inline) 2021-02-10 20:06:13 -07:00
Tadeo Kondrak
5dfe0e7e8f Convert inline fn to callconv(.Inline) everywhere 2021-02-10 20:06:12 -07:00
Tadeo Kondrak
9c797fe3ac std.zig: reformat inline fn to callconv(.Inline) 2021-02-10 20:06:11 -07:00
Jonathan Marler
61bcac108c Add more mingw def files
I've added more of the ".def" files from mingw. The list is based on all the libraries referenced by the win32metadata project. (see https://github.com/marlersoft/zigwin32).
2021-02-10 13:38:16 -08:00
Isaac Freund
4c8caf3343 zig fmt: implement Tree.lastToken() for all nodes 2021-02-10 11:53:53 -08:00
Isaac Freund
515d4920e7 zig fmt: fix 0 element struct and array init 2021-02-10 11:53:53 -08:00
Isaac Freund
5df7fc36c6 zig fmt: implement Tree.lastToken() for struct init 2021-02-10 11:53:53 -08:00
Isaac Freund
928f6f48a6 zig fmt: implement Tree.lastToken() for array init 2021-02-10 11:53:53 -08:00
Isaac Freund
3110a73486 zig fmt: implement Tree.lastToken() for array types 2021-02-10 11:53:53 -08:00
Isaac Freund
8c4f3e5a31 zig fmt: fix render of pointers with ** tokens 2021-02-10 11:53:53 -08:00
Isaac Freund
a524e57090 zig fmt: support bodyless function decls
extern function declarations do not have a body, so allow setting
the rhs for FnDecl to 0 to indicate this is the case.
2021-02-10 11:53:53 -08:00
Isaac Freund
80b719d967 zig fmt: fix typo in firstToken() for pointer types 2021-02-10 11:53:53 -08:00
Isaac Freund
6dc2236054 musl: update to 1.2.2 2021-02-10 11:50:55 -08:00
Evan Haas
a2ec77041b translate-c: call @boolToInt on return value when necessary
In C, if a function has return type `int` and the return expression
is a boolean expression, there is no implicit cast. Therefore the
translated Zig code needs to call @boolToInt() on the result.

Written with feedback from @Vexu

Fixes #6215
2021-02-10 20:23:27 +02:00
Jonathan Marler
1480c42806 require specifier for arrayish types 2021-02-09 22:25:52 -08:00
Andrew Kelley
58db3d2775 zig fmt: re-enable now-passing test cases 2021-02-09 23:07:29 -07:00
Andrew Kelley
fa5fcdd734 zig fmt: fix regression with many container members 2021-02-09 22:42:00 -07:00
Andrew Kelley
9d87e6aeb8 zig fmt: remove dead code
likely these will be resurrected to make array literal cases pass.
2021-02-09 22:29:01 -07:00
Andrew Kelley
36eee7bc6c zig fmt: anytype, fn calls with one param, trailing commas
and extra newlines between top level declarations
2021-02-09 22:26:21 -07:00
Andrew Kelley
25bcf4eb99 zig fmt: grouped expressions 2021-02-09 21:17:43 -07:00
Andrew Kelley
7295d4b807 zig fmt: suspend blocks 2021-02-09 20:35:43 -07:00
Andrew Kelley
ebf04c56e1 zig fmt: usingnamespace 2021-02-09 20:17:47 -07:00
Andrew Kelley
39acc4c020 zig fmt: for loops 2021-02-09 20:08:40 -07:00
Andrew Kelley
1c79eea125 zig fmt: while loops 2021-02-09 17:23:57 -07:00
joachimschmidt557
6a5a6386c6 stage2 ARM: fix register allocation in genArmBinOp
Previously, this would reuse an operand even if reuseOperand returned
false for both operands.

genArmBinOpCode was also changed to be more Three-address code oriented
in the process.
2021-02-09 23:58:41 +01:00
joachimschmidt557
c2beaba85a stage2 ARM: fix callee_preserved_regs
Previously, the registers included r0, r1, r2, r3 which are not
included in the callee saved registers according to the Procedure Call
Standard for the ARM Architecture.
2021-02-09 23:57:43 +01:00
Andrew Kelley
bcafc51e58 zig fmt: fn protos and anytype 2021-02-09 14:41:50 -07:00
Andrew Kelley
b1d8a0a5a6 zig fmt: asm expressions 2021-02-08 22:03:23 -07:00
Isaac Freund
d869133a9f zig fmt: implement switches 2021-02-08 15:41:31 -08:00
Isaac Freund
837cd748a8 zig fmt: fix block lbrace indent 2021-02-08 15:41:31 -08:00
Isaac Freund
aaf13a2bb3 zig fmt: implement break 2021-02-08 15:41:31 -08:00
Evan Haas
221f1d898c translate-c: Improve function pointer handling
Omit address-of operator if operand is a function.

Improve handling of function-call translation when using function pointers

Fixes #4124
2021-02-08 10:15:00 +02:00
Isaac Freund
57cec38e61 std/zig/ast: fix Tree.lastToken() for blocks
The fact that blocks may end in a semicolon but this semicolon is not
counted by recursive lastToken() evaluation on the sub expression causes
off-by-one errors for lastToken() on blocks currently.

To fix this, introduce BlockSemicolon and BlockTwoSemicolon following
the pattern used for trailing commas in e.g. builtin function arguments.
2021-02-07 14:51:37 -08:00
Isaac Freund
0e38362d24 zig fmt: split Slice and SliceSentinel
This saves 4 whole bytes in the common case where there is no sentinel.
2021-02-07 14:51:37 -08:00
Isaac Freund
1d71b19c0d zig fmt: implement error set decls 2021-02-07 14:51:37 -08:00
Andrew Kelley
1adac0a55b never pass -s to clang
We only use clang to produce object files; the idea of stripping is not
relevant here.

Fixes regression in previous commit.
2021-02-07 15:08:48 -07:00
Andrew Kelley
e197a03124 zig cc: recognize the -s flag to be "strip" 2021-02-07 14:51:27 -07:00
Isaac Freund
bb7b5ee2ac zig fmt: implement catch and return 2021-02-07 12:04:32 -08:00
Isaac Freund
0929fcbc34 zig fmt: implement slices 2021-02-07 12:04:32 -08:00
Isaac Freund
33915cb1ed zig fmt: implement pointer types
rename PtrType => PtrTypeBitRange, SliceType => PtrType

This rename was done as the current SliceType is used for non-bitrange
pointers as well as slices and because PtrTypeSentinel/PtrTypeAligned
are also used for slices. Therefore using the same Ptr prefix for all
these pointer/slice nodes is an improvement.
2021-02-06 21:29:45 -08:00
Michael Dusan
905c85be96 Merge pull request #7957 from mk12/catalina
Use -isysroot on Catalina too, not just Big Sur
2021-02-06 20:12:09 -05:00
Mitchell Kember
fc79cbcc80 Use -isysroot on Catalina too, not just Big Sur
This amends #7506 to apply to macOS versions since Catalina (10.15),
rather than since Big Sur (11.0).
2021-02-06 16:32:32 -05:00
Andrew Kelley
d898945786 zig fmt: builtin call with trailing comma 2021-02-05 20:38:30 -07:00
Andrew Kelley
409ca88829 zig fmt: trailing comma in fn parameter list 2021-02-05 17:46:15 -07:00
Andrew Kelley
16a2562c3f zig fmt: implement container decls 2021-02-05 15:47:18 -07:00
Andrew Kelley
cf42ae178d std.MultiArrayList: use @memset builtin for undefined
See comment for more details
2021-02-05 15:45:33 -07:00
Isaac Freund
0f3fa4d654 zig fmt: array types 2021-02-05 11:36:19 -08:00
Isaac Freund
6f3b93e2e8 zig fmt: struct and anon array initialization 2021-02-05 10:51:45 -08:00
Isaac Freund
3e960cfffe zig fmt: float literal with exponent 2021-02-05 10:51:45 -08:00
Isaac Freund
0b4bb9b84f std.MultiArrayList: implement review comments 2021-02-05 10:51:45 -08:00
Luuk de Gram
36df6a008f Ensure function indices are correct and fix a memory leak 2021-02-05 18:06:25 +01:00
Luuk de Gram
aa3e0ff454 Create type declarations for extern functions and write the 'import' section 2021-02-05 18:06:20 +01:00
Andrew Kelley
7069459a76 zig fmt: implement struct init 2021-02-04 19:59:06 -07:00
Andrew Kelley
8e46d06650 zig fmt: implement fn protos and defers 2021-02-04 16:38:29 -07:00
Michael Dusan
300ebbd560 target: map zig ppc32 → llvm ppc
- llvm does not accept `ppc32` as a CPU type

closes #7947
2021-02-04 14:22:38 -08:00
Asherah Connor
4428acf0f7 zig fmt: deref, unwrap optional 2021-02-04 10:49:45 -08:00
Koakuma
448a28325c Fix previous %fp calculation 2021-02-05 00:28:07 +07:00
Koakuma
d23dfdeab9 Add comment explaining the alignment setting 2021-02-05 00:25:01 +07:00
Koakuma
e3e4af7271 stage1: set gen_frame_size alignment to work around requirement mismatch
Explicitly set the alignment requirements to 1 (i.e, mark the load as unaligned)
since there are some architectures (e.g SPARCv9) which has different alignment
requirements between a function pointer and usize pointer. On those
architectures, not explicitly setting it will lead into @frameSize generating
usize-aligned load instruction that could crash if the function pointer happens
to be not usize-aligned.
2021-02-04 21:07:54 +07:00
Koakuma
1eb2e48014 std.debug.StackIterator: account for SPARC %fp quirk
On SPARC, previous %fp is saved with a 14 slots offset from current %fp+bias.
Also account for the bias constant at the new_fp calculation.
2021-02-04 20:51:41 +07:00
Andrew Kelley
725adf8332 zig fmt: builtin calls and array access 2021-02-03 22:12:11 -07:00
Andrew Kelley
f5279cbada zig fmt: implement top-level fields 2021-02-03 17:02:12 -07:00
Rocknest
2d447b57cc fix typo in comment 2021-02-02 20:07:08 -08:00
Andrew Kelley
1a83b29bea zig fmt: implement if, call, field access, assignment 2021-02-02 21:05:53 -07:00
Michael Dusan
8661a13b74 fix superfluous fmt specifier in update_glibc 2021-02-02 10:00:13 -05:00
Frank Denis
7a01d396ee siphash: update the link to the SipHash paper 2021-02-02 11:17:14 +02:00
Andrew Kelley
0c6b98b825 zig fmt: implement simple test with doc comments 2021-02-01 21:31:41 -07:00
Andrew Kelley
272a0ab359 zig fmt: implement "line comment followed by top-level comptime" 2021-02-01 20:11:55 -07:00
Andrew Kelley
20554d32c0 zig fmt: start reworking with new memory layout
* start implementation of ast.Tree.firstToken and lastToken
 * clarify some ast.Node doc comments
 * reimplement renderToken
2021-02-01 17:23:49 -07:00
Michael Dusan
70a7c14ca6 update update_glibc to format strings with "{s}" 2021-02-01 16:57:41 -05:00
Andrew Kelley
102d954220 Merge pull request #7827 from Snektron/spirv-setup
Stage 2: SPIR-V setup
2021-02-01 12:49:51 -08:00
Jonathan Marler
06b29c8546 std.json large number support 2021-02-01 12:40:49 -08:00
Martin Wickham
1032a69321 Dupe strings on all public api points for std.build 2021-02-01 12:31:24 -08:00
Ryan Liptak
5e81b048a0 docs: Clarify that @field can work on declarations 2021-02-01 12:29:50 -08:00
Andrew Kelley
1517ed0a5e Merge pull request #7895 from Luukdegram/wasm-control-flow
stage2: wasm control flow
2021-02-01 12:29:22 -08:00
Luuk de Gram
c0685458a2 Define wasm constants
Update link.Wasm.zig to use std.wasm for its constants

Make opcodes u8 and non-exhaustive

Update test and rename 'spec' to 'wasm'
2021-02-01 12:28:25 -08:00
Cameron Conn
683d3f7242 Don't read more bytes than exist in MsfStream (#7839) 2021-02-01 15:27:39 -05:00
joachimschmidt557
446ebddb93 stage2 ARM: save function arguments to stack for debugging
This changes genArg to copy registers to the stack for better
debugging. Thus, it requires genSetStack to be implemented in order for
genArg to work.
2021-02-01 12:17:24 -08:00
Vincent Rischmann
16905d96f7 Fixes for std.Thread.Condition (#7883)
* thread/condition: fix PthreadCondition compilation

* thread/condition: add wait, signal and broadcast

This is like std.Thread.Mutex which forwards calls to `impl`; avoids
having to call `cond.impl` every time.

* thread/condition: initialize the implementation
2021-02-01 15:16:39 -05:00
Andrew Kelley
11f6916f9b Merge pull request #7892 from Vexu/stage2-cbe
Stage2 cbe: more control flow
2021-02-01 12:15:52 -08:00
Andrew Kelley
66c0fe4f90 Merge pull request #7922 from daurnimator/comptime-json-fields
std.json support for comptime fields
2021-02-01 12:11:36 -08:00
Frank Denis
a03f9548d3 std/math/big/int: normalize after a right shift
After a right shift, top limbs may be all zero. However, without
normalization, the number of limbs is not going to change.

In order to check if a big number is zero, we used to assume that the
number of limbs is 1. Which may not be the case after right shifts,
even if the actual value is zero.

- Normalize after a right shift
- Add a test for that issue
- Check all the limbs in `eqlZero()`. It may not be necessary if
callers always remember to normalize before calling the function.
But checking all the limbs is very cheap and makes the function less
bug-prone.
2021-02-01 12:10:01 -08:00
Veikka Tuominen
75acfcf0ea stage2: reimplement switch 2021-02-01 15:45:11 +02:00
Veikka Tuominen
3ec5c9a3bc stage2 cbe: implement not and some bitwise ops 2021-02-01 08:48:24 +02:00
Veikka Tuominen
106520329e stage2 cbe: implement switchbr 2021-02-01 08:48:22 +02:00
Veikka Tuominen
258f3ec5ec stage2 cbe: block results 2021-02-01 08:47:25 +02:00
Veikka Tuominen
bdfe3aeab8 stage2 cbe: condbr and breaks 2021-02-01 08:47:25 +02:00
Veikka Tuominen
6ca0ff90b6 stage2 cbe: use AutoIndentingStream 2021-02-01 08:47:25 +02:00
Veikka Tuominen
81c512f35b stage2 cbe: loop instruction 2021-02-01 08:47:25 +02:00
Andrew Kelley
bf8fafc37d stage2: tokenizer does not emit line comments anymore
only std.zig.render cares about these, and it can find them in the
original source easily enough.
2021-01-31 21:57:48 -07:00
Andrew Kelley
bf76501b5d Merge pull request #7847 from ziglang/astgen-rl-rework
stage2: rework astgen result locations
2021-01-31 20:15:08 -08:00
Andrew Kelley
0f5eda973e stage2: delete astgen for switch expressions
The astgen for switch expressions did not respect the ZIR rules of only
referencing instructions that are in scope:

  %14 = block_comptime_flat({
    %15 = block_comptime_flat({
      %16 = const(TypedValue{ .ty = comptime_int, .val = 1})
    })
    %17 = block_comptime_flat({
      %18 = const(TypedValue{ .ty = comptime_int, .val = 2})
    })
  })
  %19 = block({
    %20 = ref(%5)
    %21 = deref(%20)
    %22 = switchbr(%20, [%15, %17], {
      %15 => {
        %23 = const(TypedValue{ .ty = comptime_int, .val = 1})
        %24 = store(%10, %23)
        %25 = const(TypedValue{ .ty = void, .val = {}})
        %26 = break("label_19", %25)
      },
      %17 => {
        %27 = const(TypedValue{ .ty = comptime_int, .val = 2})
        %28 = store(%10, %27)
        %29 = const(TypedValue{ .ty = void, .val = {}})
        %30 = break("label_19", %29)
      }
    }, {
      %31 = unreachable_safe()
    }, special_prong=else)
  })

In this snippet you can see that the comptime expr referenced %15 and
%17 which are not in scope. There also was no test coverage for runtime
switch expressions.

Switch expressions will have to be re-introduced to follow these rules
and with some test coverage. There is some usable code being deleted in
this commit; it will be useful to reference when re-implementing switch
later.

A few more improvements to do while we're at it:
 * only use .ref result loc on switch target if any prongs obtain the
   payload with |*syntax|
   - this improvement should be done to if, while, and for as well.
   - this will remove the needless ref/deref instructions above
 * remove switchbr and add switch_block, which is both a block and a
   switch branch.
   - similarly we should remove loop and add loop_block.

This commit introduces a "force_comptime" flag into the GenZIR
scope. The main purpose of this will be to choose the "comptime"
variants of certain key zir instructions, such as function calls and
branches. We will be moving away from using the block_comptime_flat
ZIR instruction, and eventually deleting it.

This commit also contains miscellaneous fixes to this branch that bring
it to the state of passing all the tests.
2021-01-31 21:09:22 -07:00
Andrew Kelley
de85c4ac42 astgen: rework for loops 2021-01-31 21:09:22 -07:00
Andrew Kelley
9f4ff80108 astgen: rework while 2021-01-31 21:09:22 -07:00
Andrew Kelley
e9e6cc2171 astgen: rework orelse/catch 2021-01-31 21:09:22 -07:00
Andrew Kelley
6c8985fcee astgen: rework labeled blocks 2021-01-31 21:09:22 -07:00
Andrew Kelley
588171c30b sema: after block gets peer type resolved, insert type coercions
on the break instruction operands. This involves a new TZIR instruction,
br_block_flat, which represents a break instruction where the operand is
the result of a flat block. See the doc comments on the instructions for
more details.

How it works: when adding break instructions in semantic analysis, the
underlying allocation is slightly padded so that it is the size of a
br_block_flat instruction, which allows the break instruction to later
be converted without removing instructions inside the parent body. The
extra type coercion instructions go into the body of the br_block_flat,
and backends are responsible for dispatching the instruction correctly
(it should map to the same function calls for related instructions).
2021-01-31 21:09:22 -07:00
Andrew Kelley
06bb360dd2 astgen: respect a const local's type annotation 2021-01-31 21:09:22 -07:00
Andrew Kelley
2f992e1bb3 astgen: const locals that end up being rvalues do not alloc
Local variable declarations now detect whether the result location for the
initialization expression consumes the result location as a pointer. If
it does, then the local is emitted as a LocalPtr. Otherwise it is
emitted as a LocalVal.

This results in clean, straightforward ZIR code for semantic analysis.
2021-01-31 21:09:22 -07:00
Andrew Kelley
093cbeb018 astgen: @as with block_ptr result location 2021-01-31 21:09:22 -07:00
Andrew Kelley
b7452fe35f stage2: rework astgen result locations
Motivating test case:

```zig
export fn _start() noreturn {
    var x: u64 = 1;
    var y: u32 = 2;
    var thing: u32 = 1;
    const result = if (thing == 1) x else y;
    exit();
}
```

The main idea here is for astgen to output ideal ZIR depending on
whether or not the sub-expressions of a block consume the result
location. Here, neither `x` nor `y` consume the result location of the
conditional expression block, and so the ZIR should communicate the
result of the condbr using break instructions, not with the result
location pointer.

With this commit, this is accomplished:

```
  %22 = alloc_inferred()
  %23 = block({
    %24 = const(TypedValue{ .ty = type, .val = bool})
    %25 = deref(%18)
    %26 = const(TypedValue{ .ty = comptime_int, .val = 1})
    %27 = cmp_eq(%25, %26)
    %28 = as(%24, %27)
    %29 = condbr(%28, {
      %30 = deref(%4)
      < there is no longer a store instruction here >
      %31 = break("label_23", %30)
    }, {
      %32 = deref(%11)
      < there is no longer a store instruction here >
      %33 = break("label_23", %32)
    })
  })
  %34 = store_to_inferred_ptr(%22, %23) <-- the store is only here
  %35 = resolve_inferred_alloc(%22)
```

However if the result location gets consumed, the break instructions
change to break_void, and the result value is communicated only by the
stores, not by the break instructions.

Implementation:

 * The GenZIR scope that conditional branches uses now has an optional
   result location pointer field and a count of how many times the
   result location ended up being an rvalue (not consumed).
 * When rvalue() is called on a result location for a block, it
   increments this counter. After generating the branches of a block,
   astgen for the conditional branch checks this count and if it is 2
   then the store_to_block_ptr instructions are elided and it calls
   rvalue() using the block result (which will account for peer type
   resolution on the break operands).

astgen has many functions disabled until they can be reworked with these
new semantics. That will be done before merging the branch.

There are some new rules for astgen to follow regarding result locations
and what you are allowed/required to do depending on which one is passed
to expr(). See the updated doc comments of ResultLoc for details.

I also changed naming conventions of stuff in this commit, sorry about
that.
2021-01-31 21:09:22 -07:00
daurnimator
e0a04e7f67 allow more complex comptime fields in std.json 2021-02-01 01:01:50 +11:00
daurnimator
f88bb56ee5 std.json union handling should bubble up AllocationRequired 2021-02-01 01:00:15 +11:00
daurnimator
33c0a01b08 std.json support for comptime fields
Closes #6231
2021-01-31 23:41:32 +11:00
Veikka Tuominen
fdc875ed00 Merge pull request #7750 from tadeokondrak/6609-tagtype-tag
Remove @TagType; std.meta.TagType -> std.meta.Tag
2021-01-31 12:37:12 +02:00
Andrew Kelley
4dca99d3f6 stage2: rework AST memory layout
This is a proof-of-concept of switching to a new memory layout for
tokens and AST nodes. The goal is threefold:

 * smaller memory footprint
 * faster performance for tokenization and parsing
 * most importantly, a proof-of-concept that can be also applied to ZIR
   and TZIR to improve the entire compiler pipeline in this way.

I had a few key insights here:

 * Underlying premise: using less memory will make things faster, because
   of fewer allocations and better cache utilization. Also using less
   memory is valuable in and of itself.
 * Using a Struct-Of-Arrays for tokens and AST nodes, saves the bytes of
   padding between the enum tag (which kind of token is it; which kind
   of AST node is it) and the next fields in the struct. It also improves
   cache coherence, since one can peek ahead in the tokens array without
   having to load the source locations of tokens.
 * Token memory can be conserved by only having the tag (1 byte) and byte
   offset (4 bytes) for a total of 5 bytes per token. It is not necessary
   to store the token ending byte offset because one can always re-tokenize
   later, but also most tokens the length can be trivially determined from
   the tag alone, and for ones where it doesn't, string literals for
   example, one must parse the string literal again later anyway in
   astgen, making it free to re-tokenize.
 * AST nodes do not actually need to store more than 1 token index because
   one can poke left and right in the tokens array very cheaply.

So far we are left with one big problem though: how can we put AST nodes
into an array, since different AST nodes are different sizes?

This is where my key observation comes in: one can have a hash table for
the extra data for the less common AST nodes! But it gets even better than
that:

I defined this data that is always present for every AST Node:

 * tag (1 byte)
   - which AST node is it
 * main_token (4 bytes, index into tokens array)
   - the tag determines which token this points to
 * struct{lhs: u32, rhs: u32}
   - enough to store 2 indexes to other AST nodes, the tag determines
     how to interpret this data

You can see how a binary operation, such as `a * b` would fit into this
structure perfectly. A unary operation, such as `*a` would also fit,
and leave `rhs` unused. So this is a total of 13 bytes per AST node.
And again, we don't have to pay for the padding to round up to 16 because
we store in struct-of-arrays format.

I made a further observation: the only kind of data AST nodes need to
store other than the main_token is indexes to sub-expressions. That's it.
The only purpose of an AST is to bring a tree structure to a list of tokens.
This observation means all the data that nodes store are only sets of u32
indexes to other nodes. The other tokens can be found later by the compiler,
by poking around in the tokens array, which again is super fast because it
is struct-of-arrays, so you often only need to look at the token tags array,
which is an array of bytes, very cache friendly.

So for nearly every kind of AST node, you can store it in 13 bytes. For the
rarer AST nodes that have 3 or more indexes to other nodes to store, either
the lhs or the rhs will be repurposed to be an index into an extra_data array
which contains the extra AST node indexes. In other words, no hash table needed,
it's just 1 big ArrayList with the extra data for AST Nodes.

Final observation, no need to have a canonical tag for a given AST. For example:
The expression `foo(bar)` is a function call. Function calls can have any
number of parameters. However in this example, we can encode the function
call into the AST with a tag called `FunctionCallOnlyOneParam`, and use lhs
for the function expr and rhs for the only parameter expr. Meanwhile if the
code was `foo(bar, baz)` then the AST node would have to be `FunctionCall`
with lhs still being the function expr, but rhs being the index into
`extra_data`. Then because the tag is `FunctionCall` it means
`extra_data[rhs]` is the "start" and `extra_data[rhs+1]` is the "end".
Now the range `extra_data[start..end]` describes the list of parameters
to the function.

Point being, you only have to pay for the extra bytes if the AST actually
requires it. There's no limit to the number of different AST tag encodings.

Preliminary results:

 * 15% improvement on cache-misses
 * 28% improvement on total instructions executed
 * 26% improvement on total CPU cycles
 * 22% improvement on wall clock time

This is 1/4 items on the checklist before this can actually be merged:

 * [x] parser
 * [ ] render (zig fmt)
 * [ ] astgen
 * [ ] translate-c
2021-01-30 20:16:59 -07:00
Andrew Kelley
766b315b38 std.GeneralPurposeAllocator: logging improvements
It now uses the log scope "gpa" instead of "std".

Additionally, there is a new config option `verbose_log` which enables
info log messages for every allocation. Can be useful when debugging.
This option is off by default.
2021-01-30 20:15:26 -07:00
Andrew Kelley
0808d98e10 add std.MultiArrayList
Also known as "Struct-Of-Arrays" or "SOA". The purpose of this data
structure is to provide a similar API to ArrayList but instead of
the element type being a struct, the fields of the struct are in N
different arrays, all with the same length and capacity.

Having this abstraction means we can put them in the same allocation,
avoiding overhead with the allocator. It also saves a tiny bit of
overhead from the redundant capacity and length fields, since each
struct element shares the same value.

This is an alternate implementation to #7854.
2021-01-30 20:12:13 -07:00
Tadeo Kondrak
0b5f3c2ef9 Replace @TagType uses, mostly with std.meta.Tag 2021-01-30 22:26:44 +02:00
rgreenblatt
78d2f2b819 FromWriteFileStep for all LibExeObjStep types 2021-01-30 17:50:41 +02:00
Tadeo Kondrak
1637d8ac80 remove @TagType 2021-01-30 13:19:58 +02:00
Tadeo Kondrak
b7767eb834 std.meta: rename TagPayloadType to TagPayload 2021-01-30 13:19:52 +02:00
Tadeo Kondrak
68ec54f386 std.meta: rename TagType to Tag 2021-01-30 13:19:52 +02:00
Dmitry Atamanov
290efc0747 Improve error messages in std.fmt (#7898) 2021-01-30 13:12:44 +02:00
Michael Dusan
f9b85c6e50 stage1: add error for slice.len incr beyond bounds
comptime direct slice.len increment dodges bounds checking but
we can emit an error for it, at least in the simple case.

- promote original assert to compile-error
- add test case

closes #7810
2021-01-30 11:19:25 +02:00
Martin Wickham
3d4eeafb47 Fill out more cases for std.meta.sizeof 2021-01-30 11:13:20 +02:00
Asherah Connor
e8740a90b9 complete {Z} deprecation in std.fmt.formatIntValue
formatZigEscapes doesn't exist any more.
2021-01-29 20:46:39 +02:00
root
236db6232f Fix interger overflow when calling joinZ with empty slices 2021-01-27 12:01:18 +02:00
Evan Haas
1ed8c54cd3 translate-c: add wide string literal support
Adds support for wide, UTF-16, and UTF-32 string literals. If used to initialize
an incomplete array, the same logic as narrow strings is used. Otherwise they
are translated as global "anonymous" arrays of the relevant underlying char type.
A dot is used in the name to ensure the generated names do not conflict with any
other names in the translated program.

For example:

```c
void my_fn() {
    const uint32_t *foo = U"foo";
}
```

becomes:
```zig
const @"zig.UTF32_string_2" = [4]c_uint{
    '\u{66}',
    '\u{6f}',
    '\u{6f}',
    0,
};
pub export fn my_fn() void {
    var foo: [*c]const u32 = &@"zig.UTF32_string_2";
}
```
2021-01-26 21:13:06 -08:00
Luuk de Gram
cc46c1b902 Add tests, fix locals that are created in blocks like loops, and handle all breaks correctly 2021-01-26 19:47:15 +01:00
Jakub Konka
79730e6f5c macho: add arm64 relocation type enum 2021-01-26 08:11:31 +01:00
Joran Dirk Greef
881ecdc72f Add MAX_RW_COUNT limit to std.os.pread()
Fixes: https://github.com/ziglang/zig/issues/7805
2021-01-25 10:41:38 -08:00
Koakuma
09450419d3 Fix f128 NaN check on big-endian hosts
On big-endian hosts, zig_f128_isNaN() takes the high and low halves
from the wrong element, resulting in buggy NaN detection behavior.
This fixes it.
2021-01-25 10:40:23 -08:00
Timon Kruiper
e23bc1f76a render: fix bug when rendering struct initializer with length 1
This crashed the compiler when running translate-c. See the added test.
2021-01-25 10:40:00 -08:00
Andrew Kelley
4ca1f4ec2e Merge pull request #7846 from LemonBoy/filtertest
stage1: don't filter test blocks with empty label
2021-01-25 10:39:11 -08:00
Evan Haas
57b2176e28 translate-c: Improve array support
1. For incomplete arrays with initializer list (`int x[] = {1};`) use the
initializer size as the array size.

2. For arrays initialized with a string literal translate it as an array
of character literals instead of `[*c]const u8`

3. Don't crash if an empty initializer is used for an incomplete array.

4. Add a test for multi-character character constants

Additionally lay some groundwork for supporting wide string literals.

fixes #4831 #7832 #7842
2021-01-25 10:37:23 -08:00
Joran Dirk Greef
68a040aec7 linux: add fallocate() to io_uring 2021-01-25 10:34:20 -08:00
Timon Kruiper
9238d12537 windows: make sure to handle PATH_NOT_FOUND when deleting files
Fixes #7879
2021-01-25 10:33:08 -08:00
Andrew Kelley
0cfa39304b zig cc: recognize more coff linker options
Related: #7874
2021-01-24 14:30:28 -07:00
Andrew Kelley
b56e916fa1 Merge branch 'FireFox317-deadlock-windows-fix'
Merges #7861
2021-01-24 12:22:51 -07:00
Andrew Kelley
2b321c25ce std.Progress: call refreshWithHeldLock as appropriate 2021-01-24 12:22:17 -07:00
Timon Kruiper
4f7d76f19c fix windows bug in Progress.zig
This bug caused the compiler to deadlock when multiple c objects
were build in parallel.

Thanks @kprotty for finding this bug!
2021-01-24 12:20:51 -07:00
Andrew Kelley
15278b7f4b Merge pull request #7856 from ziglang/lto
add LTO support
2021-01-24 11:09:48 -08:00
Luuk de Gram
a0d81caec9 Nested conditions and loops support 2021-01-24 14:38:35 +01:00
Luuk de Gram
ccef167e9d Define wasm constants
Update link.Wasm.zig to use std.wasm for its constants

Make opcodes u8 and non-exhaustive

Update test and rename 'spec' to 'wasm'
2021-01-24 10:54:51 +01:00
Andrew Kelley
0d4b6ac741 add LTO support
The CLI gains -flto and -fno-lto options to override the default.
However, the cool thing about this is that the defaults are great! In
general when you use build-exe in release mode, Zig will enable LTO if
it would work and it would help.

zig cc supports detecting and honoring the -flto and -fno-lto flags as
well. The linkWithLld functions are improved to all be the same with
regards to copying the artifact instead of trying to pass single objects
through LLD with -r. There is possibly a future improvement here as
well; see the respective TODOs.

stage1 is updated to support outputting LLVM bitcode instead of machine
code when lto is enabled. This allows LLVM to optimize across the Zig and
C/C++ code boundary.

closes #2845
2021-01-23 18:18:07 -07:00
Andrew Kelley
ab4f3aee3d stage2: wasm arch does not support -mred-zone flags 2021-01-22 23:35:32 -07:00
Andrew Kelley
3647784d05 stage2: add missing frexpl.c to mingw c source file list 2021-01-22 23:35:13 -07:00
LemonBoy
134f5fd3d6 std: Update test "" to test where it makes sense 2021-01-22 15:46:58 +01:00
LemonBoy
ac004e1bf1 stage1: Allow nameless test blocks
Nameless blocks are never filtered, the test prefix is still applied.
2021-01-22 15:46:58 +01:00
Jakub Konka
843d91e75d Bring back stack trace printing on ARM Darwin
This temporary patch fixes a segfault caused by miscompilation
by the LLD when generating stubs for initialization of thread local
storage. We effectively bypass TLS in the default panic handler
so that no segfault is generated and the stack trace is correctly
reported back to the user.

Note that, this is linked directly to a bigger issue with LLD
ziglang/zig#7527 and when resolved, we only need to remove the
`comptime` code path introduced with this patch to use the default
panic handler that relies on TLS.

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2021-01-21 23:20:42 +01:00
LemonBoy
fc5ae1c409 stage1: don't filter test blocks with empty label
The common pattern of including a file containing all the tests in a
empty-label test block breaks down when using --test-filter.
2021-01-21 09:48:57 +01:00
Evan Haas
bea791b639 translate-c: fix variadic function calls
1702b413 introduced a bug with variadic function calls - trying to access the
paramType of non-existent parameters.
2021-01-20 22:26:18 -08:00
Jakub Konka
58344e0017 Merge pull request #7829 from kubkon/macho-safer
stage2 macho: make int casts fallible where necessary
2021-01-20 17:28:31 +01:00
Andrew Kelley
8098b3f84c stage2: implement TZIR printing for call instruction 2021-01-19 21:09:46 -07:00
Rafael Ristovski
41e6aa78bb zig cc: Support reading input from stdin
This fixes #6271, which allows using `zig cc` with meson.
2021-01-19 17:23:44 -08:00
Andrew Kelley
072d1e088c stage2: fix anonymous Decl ty/val wrong arena
string literals and error set types were allocating the ty/val fields of
the anonymous Decl into the owner Decl's arena, rather than the
new anonymous Decl's arena as intended. This caused use of undefined
value later on in the pipeline.
2021-01-19 16:25:55 -07:00
Andrew Kelley
1af31baf0b stage2: -Dlog enables all logging, log scopes can be set at runtime
Previously you had to recompile if you wanted to change the log scopes
that get printed. Now, log scopes can be set at runtime, and -Dlog
controls whether all logging is available at runtime.

Purpose here is a nicer development experience. Most likely stage2
developers will always want -Dlog enabled and then pass --debug-log
scopes when debugging particular issues.
2021-01-19 15:49:08 -07:00
Jakub Konka
a26ab9afee Backport Elf changes from d5d0619 2021-01-19 22:54:34 +01:00
Jakub Konka
0e56d4cc02 stage2: converge x86_64 and aarch64 tests on macOS 2021-01-19 22:39:49 +01:00
Jakub Konka
5d4401ceec macho: fix overflowing u64 range 2021-01-19 22:39:49 +01:00
Jakub Konka
e726868b02 macho: reuse existing names from the string table 2021-01-19 22:39:49 +01:00
Jakub Konka
7d3aa58e16 macho: make int casts safer 2021-01-19 22:39:49 +01:00
Andrew Kelley
287f640cc9 stage2: ELF: fix crash when only 1 function and it gets updated 2021-01-19 14:08:43 -07:00
Andrew Kelley
d5d0619aac stage2: ELF: avoid multiplication for ideal capacity
ideal capacity is now determined by e.g.
x += x / f
rather than
x = x * b / a

This turns a multiplication into an addition, making it less likely to
overflow the integer. This commit also introduces padToIdeal() which
does saturating arithmetic so that no overflow is possible when
calculating ideal capacity.

closes #7830
2021-01-19 13:47:51 -07:00
Robin Voetter
1055344673 SPIR-V: Use free list for result id generation 2021-01-19 15:28:17 +01:00
Robin Voetter
801732aebd SPIR-V: OpMemoryModel and basic capability generation 2021-01-19 15:28:17 +01:00
Robin Voetter
71ac82ecb0 SPIR-V: Make emitting binary more efficient 2021-01-19 15:28:17 +01:00
Robin Voetter
02c138fe70 SPIR-V: Add glsl450 and vulkan spir-v operating system definitions 2021-01-19 15:28:17 +01:00
Robin Voetter
b2b87b5900 SPIR-V: Linking and codegen setup 2021-01-19 15:28:17 +01:00
Robin Voetter
ab607d455e SPIR-V: Initial architecture definitions and setup 2021-01-19 15:28:17 +01:00
Robin Voetter
9a6babf482 SPIR-V: Add generated specification 2021-01-19 15:28:17 +01:00
Robin Voetter
fd33530aef SPIR-V: Spec generator 2021-01-19 15:28:17 +01:00
Jakub Konka
d5b0a963d1 Merge pull request #7818 from kubkon/macho-more-cleanup
Macho more cleanup
2021-01-19 08:58:51 +01:00
Andrew Kelley
30a824cb9e astgen: eliminate rlWrapPtr and all its callsites
The following AST avoids unnecessary derefs now:
 * error set decl
 * field access
 * array access
 * for loops: replace ensure_indexable and deref on the len_ptr with a
   special purpose ZIR instruction called indexable_ptr_len.

Added an error note when for loop operand is the wrong type.

I also accidentally implemented `@field`.
2021-01-19 00:38:53 -07:00
Andrew Kelley
7e56028bc7 Merge branch 'stage2: rework ZIR/TZIR for optionals and error unions'
closes #7730
closes #7662
2021-01-18 19:29:53 -07:00
Andrew Kelley
ecc246efa2 stage2: rework ZIR/TZIR for optionals and error unions
* fix wrong pointer const-ness when unwrapping optionals
 * allow grouped expressions and orelse as lvalues
 * ZIR for unwrapping optionals: no redundant deref
   - add notes to please don't use rlWrapPtr, this function should be
     deleted
 * catch and orelse: better ZIR for non-lvalue: no redundant deref;
   operate entirely on values. lvalue case still works properly.
   - properly propagate the result location into the target expression
 * Test harness: better output when tests fail due to compile errors.
 * TZIR: add instruction variants. These allow fewer TZIR instructions to
   be emitted from zir_sema. See the commit diff for per-instruction
   documentation.
   - is_null
   - is_non_null
   - is_null_ptr
   - is_non_null_ptr
   - is_err
   - is_err_ptr
   - optional_payload
   - optional_payload_ptr
 * TZIR: removed old naming convention instructions:
   - isnonnull
   - isnull
   - iserr
   - unwrap_optional
 * ZIR: add instruction variants. These allow fewer ZIR instructions to
   be emitted from astgen. See the commit diff for per-instruction
   documentation.
   - is_non_null
   - is_null
   - is_non_null_ptr
   - is_null_ptr
   - is_err
   - is_err_ptr
   - optional_payload_safe
   - optional_payload_unsafe
   - optional_payload_safe_ptr
   - optional_payload_unsafe_ptr
   - err_union_payload_safe
   - err_union_payload_unsafe
   - err_union_payload_safe_ptr
   - err_union_payload_unsafe_ptr
   - err_union_code
   - err_union_code_ptr
 * ZIR: removed old naming convention instructions:
   - isnonnull
   - isnull
   - iserr
   - unwrap_optional_safe
   - unwrap_optional_unsafe
   - unwrap_err_safe
   - unwrap_err_unsafe
   - unwrap_err_code
2021-01-18 19:29:18 -07:00
g-w1
3c2a9220ed stage2: fix orelse at comptime
There was just some untested code that did not work. .isnull -> .isnonnull
and I had to add a .ref resultloc to make types match up.
2021-01-18 19:29:18 -07:00
Jakub Konka
a2ebe3c82c macho: add missing DWARF line no update in codegen 2021-01-18 22:26:23 +01:00
Jakub Konka
e32131cfae stage2 macho: cleanup indirect symbol table writes
Also, force rewriting of code signature padding at every update so
that we take into account possible section relocs and expansion of
the last preceeding section, e.g., the string table.

This commit also tweak the logic responsible for managing debug lines
in `DebugSymbols`. In particular, in case we update the same function,
we'd previously incorrectly create a cycle adding pointer to the same
`SrcFn` to itself.
2021-01-18 22:26:23 +01:00
joachimschmidt557
6c7e66613d stage2 AArch64: implement jump 2021-01-18 22:22:53 +01:00
Andrew Kelley
1a05b54520 update wasm backend to match new Module API
Fixes a logical merge conflict that I didn't notice before.
2021-01-18 14:12:05 -07:00
Andrew Kelley
46dd058d59 Merge pull request #7797 from Luukdegram/wasm-refactor
stage2: wasm - Refactor codegen for wasm similar to other backends
2021-01-18 12:35:52 -08:00
Andrew Kelley
0353c9601a Merge pull request #7814 from LemonBoy/fix-7760
std: Fixed pipe2 fallback
2021-01-18 11:49:42 -08:00
Evan Haas
c3dadfa95b translate-c: Add Wide, UTF-16, and UTF-32 character literals
Add support for L'<wchar_t>', u'<char16_t>', and U'<char32_t>'. Currently
this just translates wide char literals to \u{NNNNNN} escape codes
(e.g. U'💯' -> '\u{1f4af}')

Another approach would be to emit UTF-8 encoded character literals
directly, but in my opinion this approaches Unicode-complete because it
would require knowledge of which Unicode codepoints have graphical
representations for the emitted source to be readable.

We could also just emit integer literals, but the current method makes
it clear that we have translated a wide character literal and not just
an integer constant.
2021-01-18 11:05:51 -08:00
Julian Maingot
384ccaa27a stage2: use %type not @type for libc stubs
Missed a couple places last time so just doing the rest.
2021-01-18 11:04:33 -08:00
Julian Maingot
4c5f69a065 update error return doc
Docs were out of sync with code
2021-01-18 11:04:33 -08:00
Zander Khan
ce22c70586 Change compareFn to fn (a: T, b: T) std.math.Order 2021-01-18 19:02:11 +00:00
Jakub Konka
61b8d42d5c Merge pull request #7808 from joachimschmidt557/stage2-aarch64
Stage2 AArch64: Fix genSetStack
2021-01-18 20:01:44 +01:00
LemonBoy
6418f9ae91 std: Add missing cast when calling fcntl w/ constant args
comptime_int arguments are a big no no.
2021-01-18 18:02:09 +01:00
LemonBoy
f33bac2b12 std: define pipe2 only for os that support it 2021-01-18 17:24:26 +01:00
LemonBoy
9d18df142c std: Fixed pipe2 fallback
Use both F_SETFD and F_SETFL depending on what flag we're setting.

Closes #7760
2021-01-18 14:52:35 +01:00
joachimschmidt557
458011f21f stage2 AArch64: update function prologue and epilogue to include stack
offsets
2021-01-17 23:12:04 +01:00
joachimschmidt557
ea6f3e3fd1 stage2 AArch64: add add/subtract (immediate) instructions 2021-01-17 22:40:14 +01:00
joachimschmidt557
c6cb02c226 stage2 AArch64: fix stack offsets in genSetStack 2021-01-17 22:22:47 +01:00
Jakub Konka
8118336585 macho: refactor undef symbol handling
Now, we don't erroneously write to the string table on every
write of global and undef symbols.
2021-01-17 21:01:52 +01:00
Jakub Konka
3562edf137 macho: improve x86_64 tests; clean fixups on error
When codegen ends in failure, we need to manually clean up any fixups
that may have been gathered during that `codegen.generateSymbol` call.
Otherwise, we will end trapping.
2021-01-17 16:01:16 +01:00
Zander Khan
5bfd9238de Remove resize. Adding uninitialized memory at the end of the items would break the heap property. 2021-01-17 14:43:38 +00:00
Zander Khan
9a09ebb1b9 Replace shrink with shrinkAndFree and shrinkRetainingCapacity 2021-01-17 14:41:20 +00:00
Jakub Konka
b25cf7db02 stage2 aarch64: add basic function pro/epilogue
Fix typo in `nop` implementation.
Simplify `aarch64` macOS tests.
2021-01-17 14:57:53 +01:00
Jakub Konka
e292f33de7 stage2 aarch64: add basic genSetStack 2021-01-17 14:57:36 +01:00
Andrew Kelley
44135ea84e Merge branch 'stage2 error notes'
Closes #7555

There was still some extra work @Vexu did in that PR having to do with
adding more compile errors and notes for switch expressions, but that
can be added in a follow-up commit.
2021-01-17 00:16:10 -07:00
Andrew Kelley
8deb21c58a stage2: add compile error for label redefinition
Also fix incorrectly destroying notes.

This work is based on Vexu's patch in #7555.
2021-01-17 00:15:25 -07:00
Andrew Kelley
629d3bea1b stage2: slight cleanup of Module by calling astgen functions 2021-01-16 23:24:00 -07:00
Andrew Kelley
8c9ac4db97 stage2: implement error notes and regress -femit-zir
* Implement error notes
   - note: other symbol exported here
   - note: previous else prong is here
   - note: previous '_' prong is here
 * Add Compilation.CObject.ErrorMsg. This object properly converts to
   AllErrors.Message when the time comes.
 * Add Compilation.CObject.failure_retryable. Properly handles
   out-of-memory and other transient failures.
 * Introduce Module.SrcLoc which has not only a byte offset but also
   references the file which the byte offset applies to.
 * Scope.Block now contains both a pointer to the "owner" Decl and the
   "source" Decl. As an example, during inline function call, the
   "owner" will be the Decl of the caller and the "source" will be the
   Decl of the callee.
 * Module.ErrorMsg now sports a `file_scope` field so that notes can
   refer to source locations in a file other than the parent error
   message.
 * Some instances where a `*Scope` was stored, now store a
   `*Scope.Container`.
 * Some methods in the `Scope` namespace were moved to the more specific
   type, since there was only an implementation for one particular tag.
   - `removeDecl` moved to `Scope.Container`
   - `destroy` moved to `Scope.File`
 * Two kinds of Scope deleted:
   - zir_module
   - decl
 * astgen: properly use DeclVal / DeclRef. DeclVal was incorrectly
   changed to be a reference; this commit fixes it. Fewer ZIR
   instructions processed as a result.
   - declval_in_module is renamed to declval
   - previous declval ZIR instruction is deleted; it was only for .zir
     files.
 * Test harness: friendlier diagnostics when an unexpected set of errors
   is encountered.
 * zir_sema: fix analyzeInstBlockFlat by properly calling resolvingInst
   on the last zir instruction in the block.

Compile log implementation:
 * Write to a buffer rather than directly to stderr.
 * Only keep track of 1 callsite per Decl.
 * No longer mutate the ZIR Inst struct data.
 * "Compile log statement found" errors are only emitted when there are
   no other compile errors.

-femit-zir and support for .zir source files is regressed. If we wanted
to support this again, outputting .zir would need to be done as yet
another backend rather than in the haphazard way it was previously
implemented.

For parsing .zir, it was implemented previously in a way that was not
helpful for debugging. We need tighter integration with the test harness
for it to be useful; so clearly a rewrite is needed. Given that a
rewrite is needed, and it was getting in the way of progress and
organization of the rest of stage2, I regressed the feature.
2021-01-16 22:51:01 -07:00
Andrew Kelley
8436134499 std.ArrayHashMap: add "AssertDiscard" function variants
* Add `swapRemoveAssertDiscard`
 * Add `orderedRemoveAssertDiscard`
 * Deprecate `removeAssertDiscard`
2021-01-16 22:49:20 -07:00
Andrew Kelley
1f65828ec6 Merge pull request #7716 from koachan/sparc64-libs
stage1: SPARCv9 f128 enablement
2021-01-16 12:10:03 -08:00
joachimschmidt557
d2a297c2b3 stage2 ARM: add extra load/store instructions 2021-01-16 12:06:31 -08:00
joachimschmidt557
fbd5fbe729 stage2 AArch64: add very basic return values 2021-01-16 12:05:38 -08:00
Zander Khan
e1ab425bce Fix slice length when updating 2021-01-16 18:43:13 +00:00
Zander Khan
c6986f29f9 Fix update might change an element no longer in the queue 2021-01-16 18:11:26 +00:00
Zander Khan
4600b489a6 Rename heap to queue in tests for consistency 2021-01-16 18:09:44 +00:00
Zander Khan
4d09803414 Fix edge cases in fromOwnedSlice 2021-01-16 18:06:44 +00:00
Zander Khan
a162a21947 Ensure we cannot remove an item outside the current length of the queue 2021-01-16 17:52:14 +00:00
Zander Khan
ecee1cae45 Remove magic number 2021-01-16 17:48:55 +00:00
Zander Khan
94c47855ec Add missing import 2021-01-16 17:48:29 +00:00
Zander Khan
349ccc0bd0 Add license to top of file 2021-01-16 17:48:14 +00:00
Luuk de Gram
6a87ce0b62 Generate correct opcode for 'addGen' depending on type 2021-01-16 18:22:20 +01:00
Luuk de Gram
6c19aeddca Add tests and move tests to wasm's own file 2021-01-16 14:58:04 +01:00
Zander Khan
a727a508cd std: Add Priority Dequeue 2021-01-16 12:01:06 +00:00
Luuk de Gram
4b2538f72c Cleanup and 'add' instruction for bigger test area 2021-01-15 23:27:38 +01:00
Luuk de Gram
bb74f72e97 stage2: refactor wasm backend - similar to the other backends 2021-01-15 23:27:38 +01:00
Jakub Konka
b204ea0349 macho: ensure that strtab always follows symtab
In rare occassions, it may happen that string table is allocated free
space preceeding symbol table. This is an error in the eyes of the `dyld`
dynamic loader and thus has to forbidden by the linker.
2021-01-15 23:22:28 +01:00
Guillaume Ballet
f7d7cb6268 crypto: add legacy keccak hash functions 2021-01-15 12:36:38 -08:00
Evan Haas
1702b413f7 translate-c: ensure bools are cast to int when necessary
Fixes two scenarios where @boolToInt() calls were missing:

1. Boolean expression cast to different-size int (char, long, etc)
2. Boolean expression used as parameter for function with int argument
2021-01-15 12:35:54 -08:00
Andrew Kelley
35686262f5 Merge pull request #7785 from ziglang/std-thread-primitives
organize std lib concurrency primitives and add RwLock
2021-01-15 12:31:17 -08:00
Koakuma
1d67ab8823 Fix _Qp_cmp definition 2021-01-15 19:07:39 +07:00
Koakuma
b531caac02 Fix f128 codegen on BE hosts 2021-01-15 19:07:38 +07:00
Koakuma
bbb58b10f6 Add compiler-rt stub for SPARC CPUs 2021-01-15 19:07:38 +07:00
Jakub Konka
2faf8c53d2 macho: use target arch page_size for codesig
It turns out I was wrong and we can set the page size to the actual
page size used by the target architecture when dividing the binary
into chunks and calculating a hash of each chunk for embedding within
the adhoc code signature. This shaves of a considerable amount of bytes
since we divide the code signature section by at least 2x.

I've also unified the `write` interface of `CodeSignature` struct to
follow that used in every other bit of `MachO`; namely, the functions
now accept a writer instead of a buffer, therefore, there is no need
to manually track where to write each struct field anymore.
2021-01-15 08:16:47 +01:00
Andrew Kelley
19f893c6bb std.Thread: avoid compile errors for single-threaded OS's 2021-01-14 22:42:29 -07:00
Andrew Kelley
ad301d687a fix namespace of kernel32 function calls 2021-01-14 21:42:49 -07:00
Andrew Kelley
9e1aeda3bf std.Thread.StaticResetEvent: call spinLoopHint appropriately 2021-01-14 21:34:30 -07:00
Andrew Kelley
9698ea3173 std.Thread.Mutex: restore the "Held" API
so that std.Thread.Mutex.Dummy can be used as a drop in replacement.
2021-01-14 21:28:22 -07:00
Andrew Kelley
a9667b5a85 organize std lib concurrency primitives and add RwLock
* move concurrency primitives that always operate on kernel threads to
   the std.Thread namespace
 * remove std.SpinLock. Nobody should use this in a non-freestanding
   environment; the other primitives are always preferable. In
   freestanding, it will be necessary to put custom spin logic in there,
   so there are no use cases for a std lib version.
 * move some std lib files to the top level fields convention
 * add std.Thread.spinLoopHint
 * add std.Thread.Condition
 * add std.Thread.Semaphore
 * new implementation of std.Thread.Mutex for Windows and non-pthreads Linux
 * add std.Thread.RwLock

Implementations provided by @kprotty
2021-01-14 20:41:37 -07:00
Asherah Connor
affb57aad9 use interfaces 2021-01-15 10:34:53 +11:00
Asherah Connor
9168b217b2 fix SectionHeaderIterator impl 2021-01-14 17:52:06 +11:00
Asherah Connor
32d69d70cf expose phdr, shdr parsing 2021-01-14 15:30:28 +11:00
Asherah Connor
49ab6bb429 std.elf: actually pass the pointer 2021-01-14 14:38:52 +11:00
Asherah Connor
1cea88917c std.elf: call it Header.parse 2021-01-14 14:38:52 +11:00
Asherah Connor
e6cdf9cebf std.elf: make Header pub 2021-01-14 14:38:52 +11:00
Asherah Connor
23fb19fe41 std.elf: expose parsing decoupled from std.fs.File 2021-01-14 14:38:52 +11:00
Asherah Connor
2b0e3ee228 std.os.uefi.protocols.FileProtocol: fix and expose get_position, set_position (#7762) 2021-01-13 21:46:22 -05:00
Andrew Kelley
ec1541de26 Merge pull request #7746 from kubkon/macho-extern-fn
macho: extern functions come to MachO!
2021-01-13 15:11:35 -08:00
Jakub Konka
2128149325 macho: update DebugSymbols to include DATA_CONST seg 2021-01-13 23:56:05 +01:00
Jakub Konka
4ffa8952cc macho: add x86_64 tests 2021-01-13 23:55:56 +01:00
Jakub Konka
2ea0901dd6 macho: properly populate offset into lazy bind info 2021-01-13 23:55:48 +01:00
Jakub Konka
f0d7ec6f33 macho: add x86_64 support 2021-01-13 23:55:37 +01:00
Jakub Konka
1b91a9f4c8 macho: bring back lld cc hot-fix 2021-01-13 23:55:28 +01:00
Jakub Konka
7d40aaad2b macho: document more code + add test case 2021-01-13 23:55:18 +01:00
Jakub Konka
b86d0e488b macho: refactor writing and managing externs 2021-01-13 23:55:06 +01:00
Jakub Konka
21c7217e09 macho: memorize start of stubs in helper 2021-01-13 23:54:56 +01:00
Jakub Konka
44a052a65f macho: write out stubs for new externs only 2021-01-13 23:54:46 +01:00
Jakub Konka
2f7cd71193 macho: fully working PoC with main and exit 2021-01-13 23:54:31 +01:00
Jakub Konka
bb691ea16b macho: first working draft of externs on macOS 2021-01-13 23:54:22 +01:00
Jakub Konka
6d2a6513f9 macho: write out binding info 2021-01-13 23:54:11 +01:00
Jakub Konka
5ae82956aa macho: write out rebase info 2021-01-13 23:54:01 +01:00
Jakub Konka
f44732c1b0 macho: populate stubs and stub_helper 2021-01-13 23:53:46 +01:00
Jakub Konka
51a13f8ea6 macho: add missing data sections 2021-01-13 23:53:36 +01:00
Jakub Konka
3d07f057b1 macho: prealloc DATA_CONST and DATA segments 2021-01-13 23:53:25 +01:00
Jakub Konka
5487dd13ea stage2: lay the groundwork in prep for extern fn
This commit lays the groundwork in preparation for implementing
handling of extern functions in various backends.
2021-01-13 14:51:23 -08:00
Jay Petacat
a021c7b1b2 Move fmt.testFmt to testing.expectFmt 2021-01-12 18:13:29 -08:00
Bill Nagel
2c79d669a7 add missing ECONNRESET from getsockoptError 2021-01-12 18:11:58 -08:00
Andrew Kelley
70c608add8 Merge pull request #7577 from semarie/emutls
implement emutls inside compiler_rt.zig
2021-01-12 17:54:02 -08:00
Andrew Kelley
e564d2ca3c Merge pull request #7714 from mikdusan/target-macos
macos: reimplement OS version detection
2021-01-12 16:45:50 -08:00
Bill Nagel
1e2be14b6b define nfds_t for windows 2021-01-12 16:37:58 -08:00
LemonBoy
65b7d2b4e1 stage1: Resolve alignment earlier in @alignCast
Fixes #7744
2021-01-12 16:36:51 -08:00
Andrew Kelley
ffc8a43dfb ci: stop directly pushing web page stuff to s3
This is now handled by the www.ziglang.org repo deploy script.
2021-01-12 17:27:36 -07:00
Andrew Kelley
23c6cca24d ci: give the updated website content to the website repo
and use master branch not hugo-redesign branch
2021-01-12 13:26:52 -07:00
Andrew Kelley
166e9ea689 ci: add stdDocs to downloads/index.json for master branch 2021-01-12 12:52:59 -07:00
Sébastien Marie
d7aa7dbab2 implement emutls in compiler_rt 2021-01-12 05:39:46 +00:00
Sébastien Marie
ebf2a7e9b9 add pthread_key functions 2021-01-12 05:39:46 +00:00
Andrew Kelley
8ea2b40e5f std.event.Loop: fix race condition when starting the time wheel
closes #7572
2021-01-11 22:23:03 -07:00
Andrew Kelley
0edde40c25 Merge 'Add support for no red zone'
Merges #7511
2021-01-11 22:07:47 -07:00
Andrew Kelley
5b2a79848c stage2: cleanups regarding red zone CLI flags
* CLI: change to -mred-zone and -mno-red-zone to match gcc/clang.
 * build.zig: remove the double negative and make it an optional bool.
   This follows precedent from other flags, allowing the compiler CLI to
   be the decider of what is default instead of duplicating the default
   value into the build system code.
 * Compilation: make it an optional `want_red_zone` instead of a
   `no_red_zone` bool. The default is decided by a call to
   `target_util.hasRedZone`.
 * When creating a Clang command line, put -mred-zone on the command
   line if we are forcing it to be enabled.
 * Update update_clang_options.zig with respect to the recent {s}/{} format changes.
 * `zig cc` integration with red zone preference.
2021-01-11 22:07:21 -07:00
Lee Cannon
8932c2d745 Added support for no red zone 2021-01-11 22:07:14 -07:00
Michael Dusan
4c3de99253 more fixups
- clarify comments
- `NativeTargetInfo.detect()` propagate macOS errors
- `macos.detect()` drop `std.log` usage
2021-01-11 20:58:31 -05:00
Michael Dusan
f2be1fb23e macos: reimplement OS version detection
The macOS version is now obtained by parsing `SystemVersion.plist`.

Test cases added for plist files that date back to '2005 Panther and up
to the recent '2020 Big Sur 11.1 release of macOS.

Thus we are now able to reliably identify 10.3...11.1 and higher.

- drop use of kern.osproductversion sysctl
- drop use of kern.osversion sysctl (fallback)
- drop kern.osversion tests
- add `lib.std.zig.system.detect()`
- add minimalistic parser for `SystemVersion.plist`
- add test cases for { 10.3, 10.3.9, 10.15.6, 11.0, 11.1 }

closes #7569
2021-01-11 19:54:56 -05:00
Andrew Kelley
56c03881eb Merge branch 'rohlem-fix-GetFinalPathNameByHandle-before-win10_rs4'
Merges #7379
2021-01-11 17:48:33 -07:00
Rohlem
c96272f618 std.os.windows.GetFinalPathNameByHandle: remove intermediate buffers
... and mem.copy operations. Requires slightly larger input buffers than result length. Add helper functions std.mem.alignInBytes and std.mem.alignInSlice.
2021-01-11 17:48:19 -07:00
Rohlem
f301a8467c std.os.windows.GetFinalPathNameByHandle: remove QueryInformationFile code path 2021-01-11 17:48:18 -07:00
Rohlem
cb20503990 std.os.windows.GetFinalPathNameByHandle: address non-structural review comments 2021-01-11 17:48:18 -07:00
Rohlem
64c5f4979e std.os.windows.GetFinalPathNameByHandle: replace kernel32 by ntdll call
Removes the call to kernel32.GetFinalPathNameByHandleW in favor of NtQueryObject, which means we can reuse the other codepath's logic for DOS naming.
2021-01-11 17:48:18 -07:00
Rohlem
964bbcd0b1 introduce std.os.windows.QueryObjectName 2021-01-11 17:48:18 -07:00
Rohlem
09dc651476 std.os.windows.GetFinalPathNameByHandle: add test 2021-01-11 17:48:18 -07:00
Rohlem
450e467201 std.os.windows.GetFinalPathNameByHandle: reintroduce kernel32 for compatibility
The NtQueryInformationFile with .FileNormalizedNameInformation is only available in Windows 10 1803 (rs4) and later, however there is probably still another route we can go via ntdll.
2021-01-11 17:48:18 -07:00
Rohlem
4b280ac7e9 add std.zig.system.windows version check utility functions 2021-01-11 17:48:17 -07:00
Rohlem
2922a48309 move windows runtime version detection into std.zig.system.windows 2021-01-11 17:48:16 -07:00
Jonathan Knezek
fc10c9c4ce Add std.fmt.formatDuration and std.fmt.duration (#7297)
`formatDuration` works on a writer, and `duration` wraps a u64 to allow pleasant injection into format strings.
2021-01-11 19:15:56 -05:00
Andrew Kelley
025f1559a0 Merge pull request #7200 from Vexu/arr
Type coercion for pointers to anon literals
2021-01-11 16:09:28 -08:00
Andrew Kelley
4f5fa90d6d Merge pull request #7195 from Aransentin/master
A win32-api proposal, implemented for user32.zig
2021-01-11 16:02:40 -08:00
Andrew Kelley
483c057a77 Merge branch 'clean up writeFileAllUnseekable by using readers'
closes #7156
2021-01-11 16:52:29 -07:00
Andrew Kelley
d68adc5382 std.EarlyEOFReader: rename to LimitedReader 2021-01-11 16:51:56 -07:00
daurnimator
01d1a8a783 std: use fifo.pump in writeFileAllUnseekable 2021-01-11 16:48:56 -07:00
daurnimator
e873668d38 std: add LimitedReader: reader that returns EOF early 2021-01-11 16:48:30 -07:00
daurnimator
8695b9fbe7 std: use reader.skipBytes to avoid infinite loop in writeFileAllUnseekable
skipBytes correctly handles EOF for us
2021-01-11 16:47:48 -07:00
daurnimator
0ab8ae944c std: reader.skipBytes's num_bytes should be a u64 2021-01-11 16:47:48 -07:00
Vincent Rischmann
3468872d83 os/bits/linux: add the termios cc bits 2021-01-11 15:39:36 -08:00
Andrew Kelley
ec9158305d Merge pull request #7124 from LemonBoy/netstuff1
std: Decouple network streams from fs.File
2021-01-11 15:35:00 -08:00
Andrew Kelley
29c9d5896c Merge branch 'Stage2 begin implementing container types' 2021-01-11 16:25:21 -07:00
Andrew Kelley
5cc2e500e6 Merge branch 'SpexGuy-fix-comptime-cityhash'
I commented out the comptime test though since it was causing OOM on the
CI server.

closes #7331
2021-01-11 13:58:31 -07:00
Andrew Kelley
0c8e2c987d std CityHash: disable memory-expensive tests for now 2021-01-11 13:58:06 -07:00
Martin Wickham
21213127ec Modify cityhash to work at comptime 2021-01-11 13:52:52 -07:00
Andrew Kelley
73b17474d7 Merge pull request #7134 from alexnask/fix_std_fs_watch
The std.fs.Watch rewrite PR
2021-01-11 12:45:36 -08:00
LemonBoy
34720da3d0 Apparently unix sockets are supported on Windows
Starting from Windows 10 build 17063.
2021-01-11 21:43:15 +01:00
LemonBoy
d0beb4badb Let the kernel pick a random port
Avoid errors if the socket enters the TIME_WAIT state and we need to
re-execute this test before the OS releases it.

This problem was not really a problem before since the accept()-ed
socket was never closed on the server-side.
2021-01-11 21:43:14 +01:00
LemonBoy
676d7fc63c std: Add a small test for i/o on unix sockets 2021-01-11 21:43:13 +01:00
LemonBoy
89d6317b93 std: Decouple network streams from fs.File
The overlap between files and sockets is minimal and lumping them
together means supporting only a small subset of the functionalities
provided by the OS.
Moreover the socket and file handles are not always interchangeable: on
Windows one should use Winsock's close() call rather than the one used
for common files.
2021-01-11 21:43:09 +01:00
Travis
cc2981edfc update path.join to recognize any separators that isSep does 2021-01-11 11:15:34 -08:00
Andrew Kelley
1295525a7a Merge branch 'AdamGoertz-master'
closes #5080
closes #6887
2021-01-10 19:04:22 -07:00
Andrew Kelley
169810b20f zig fmt 2021-01-10 19:04:10 -07:00
Adam Goertz
0f32de77c9 impl lossyCast #5080 2021-01-10 19:02:41 -07:00
Timon Kruiper
e1d8073d2f stage2: add support for loops in LLVM backend
A simple `while(true) {}` loop generates the following LLVMIR:
```
define i32 @main() {
Entry:
  br label %Loop

Loop:                                 ; preds = %Loop, %Entry
  br label %Loop
}
```

Also implement TZIR printing for loops and add a corresponding test.
2021-01-10 17:47:34 -08:00
Vincent Rischmann
2117489e05 debug: don't fail printLineInfo if the source file is not readable
Without this dumping a stacktrace fails with this:

    Unable to dump stack trace: AccessDenied
2021-01-10 17:46:15 -08:00
joachimschmidt557
a7da90071e stage2: fix bug in genArg
When an argument is unused in the function body, still increment
arg_index so we still select the correct arguments in the args slice.
2021-01-10 00:41:02 -08:00
Andrew Kelley
29928af600 Merge pull request #7729 from jayschwa/remove-deprecated-stream
Remove deprecated stream aliases
2021-01-09 13:04:08 -08:00
Jay Petacat
a0ad2dee6a builtin: Add zig_version
This will enable code to perform version checks and make it easier to
support multiple versions of Zig.

Within the SemVer implementation, an intermediate value needed to be
coerced to a slice to workaround a comptime bug.

Closes #6466
2021-01-09 12:50:39 -08:00
Andrew Kelley
5c49a137d5 Merge pull request #7725 from FireFox317/even-more-llvm
stage2: initial implementation of control flow in LLVM backend + TZIR printing
2021-01-09 12:32:10 -08:00
xackus
e4b8148e9c Fix system library path detection on linux
Uses the NativeTargetInfo results instead of std.Target.current.
2021-01-08 20:07:59 -07:00
LemonBoy
eb696e453f stage2: Implicitly enable --eh_frame_hdr when compiling c/c++ files
Matches what Clang/GCC driver do.

Closes #7711
2021-01-08 19:01:05 -08:00
Sobeston
95e66a915b added mem.containsAtLeast 2021-01-08 18:12:30 -08:00
Jakub Konka
7e0e27e738 libstd: add missing MachO rebase opcodes in macho.zig 2021-01-08 23:41:51 +01:00
Jay Petacat
e72472d953 io: FindByteOutStream to FindByteWriter
See #4917
2021-01-08 16:54:56 -05:00
Jay Petacat
1595ce273e Remove deprecated stream aliases 2021-01-08 16:54:56 -05:00
Timon Kruiper
56c059077c stage2: add initial impl of control flow in LLVM backend
The following TZIR instrutions have been implemented in the backend:
- all cmp operators (lt, lte, gt, gte, eq, neq)
- block
- br
- condbr

The following LLVMIR is generated for a simple assert function:
```
define void @assert(i1 %0) {
Entry:
  %1 = alloca i1, align 1
  store i1 %0, i1* %1, align 1
  %2 = load i1, i1* %1, align 1
  %3 = xor i1 %2, true
  br i1 %3, label %Then, label %Else

Then:                                             ; preds = %Entry
  call void @llvm.debugtrap()
  unreachable

Else:                                             ; preds = %Entry
  br label %Block

Block:                                            ; preds = %Else
  ret void
}
```

See tests for more examples.
2021-01-08 19:30:52 +01:00
Timon Kruiper
3715ed7b54 stage2: implement TZIR printing for block and condbr
Zig code:
```
fn assert(ok: bool) void {
    if (!ok) unreachable;
}
```

TZIR:
```
Module.Function(name=assert):
  @0: void = {};
  %0: bool = arg(ok)
  %1: void = dbg_stmt()
  %2: void = block(
    %3: bool = not(%0)
    %4: noreturn = condbr(%3,
    then:
      %5: void = breakpoint()
      %6: noreturn = unreach()
    else:
      %7: noreturn = br(%2, @0)
    )
  )
  %8: noreturn = retvoid()
```
2021-01-08 12:13:27 +01:00
Julius Putra Tanu Setiaji
2b3b355a23 Add compileError message for StringHashMap in AutoHashMap 2021-01-07 23:51:53 -08:00
Andrew Kelley
3fdffe85c0 Merge pull request #7720 from Snektron/sockopt
Some sockopt stuff
2021-01-07 23:50:34 -08:00
Jonathan Marler
31802c6c68 remove z/Z format specifiers
Zig's format system is flexible enough to add custom formatters.  This PR removes the new z/Z format specifiers that were added for printing Zig identifiers and replaces them with custom formatters.
2021-01-07 23:49:22 -08:00
Jay Petacat
a9b505fa77 Reduce use of deprecated IO types
Related: #4917
2021-01-07 23:48:58 -08:00
Michael Dusan
8e9a1ac364 builder: propagate env_map for child processes 2021-01-07 23:48:24 -08:00
Jakub Konka
70771283c5 Want native headers when linking with frameworks
This PR ensures we use system libc headers and system search paths for
framework headers when linking against frameworks and compiling natively
on macOS.
2021-01-07 23:47:37 -08:00
Robin Voetter
ec7adeda2b Add EPERM to std.os.setsockopt 2021-01-08 02:34:42 +01:00
Robin Voetter
83fad7d4f7 Add IP_ constants 2021-01-08 01:35:52 +01:00
Andrew Kelley
c7666ff885 ci: import the update-download-page from www repo 2021-01-07 16:49:13 -07:00
Andrew Kelley
d8eba037a4 ci: fix path to update-download-page.zig script 2021-01-07 15:49:43 -07:00
Andrew Kelley
aa2422e830 ci: add github.com's public key for the ssh clone 2021-01-07 12:28:55 -07:00
Timon Kruiper
36950815a4 stage2 test: make sure to pass the dynamic linker to Compilation
Because this was not set, the `-dynamic-path` argument was not passed
to LLD when linking an ELF binary. This would still generate a valid glibc
binary, however when executing would result in a segfault.
2021-01-07 11:37:52 +01:00
Andrew Kelley
87aa052e23 ci: pass --override-lib-dir to emit std lib docs
Otherwise we get errors from conflicting std libs.
2021-01-07 02:58:27 -07:00
Andrew Kelley
ee1b370404 ci: don't use ninja on linux
I got this error when re-running the cmake line setting
-DZIG_EXECUTABLE:

```
ninja: warning: multiple rules generate zig1.o. builds involving
this target will not be correct; continuing anyway
[-w dupbuild=warn]
```

But it works fine with make.
2021-01-07 00:38:48 -07:00
Andrew Kelley
a279cf81b2 ci: add missing target/mcpu args to zig cc
In the previous commit, I forgot to add these.
2021-01-07 00:18:28 -07:00
Andrew Kelley
ce5222d945 ci: rework linux script
* no longer depend on apt.llvm.org, instead we rely on a zig-bootstrap
   tarball with pre-built Zig, LLVM, LLD, and Clang. Similar to the
   Windows Dev Kit but for Linux. This also makes the script no longer
   depend on Docker, libxml2, or GCC.
 * remove bash retry logic; it was only needed for flaky apt.llvm.org
   and isn't needed for the other resources we download.
 * build and upload the experimental std lib automatically generated
   docs. langref.html is moved to docs/langref.html because the std lib
   docs are in docs/std/.
 * the superfluous "zig" directory in $prefix/lib/zig/std/std.zig is
   removed from the tarball.
 * update_download_page makes a commit in the www.ziglang.org repository
   updating data/releases.json so that repository can manage deploys.
2021-01-06 23:40:17 -07:00
Jonathan Marler
f1ef0a80f1 fix LRESULT and LPARAM typedefs
LRESULT and LPARAM are currently typedef'd as ?*c_void, however, they are supposed to be typedef'd as LONG_PTR which is equivalent to isize in Zig.
2021-01-06 16:41:40 -08:00
Andrew Kelley
5ee0431527 stage2: update to new ArrayListHashMap API 2021-01-06 17:40:25 -07:00
Andrew Kelley
2f58efcc1f std.SpinLock: flatten and remove init/deinit
structs which are intended to be directly initialized and support static
initialization should not have init/deinit methods.
2021-01-06 17:36:06 -07:00
Andrew Kelley
d7d905696c Merge pull request #7622 from tetsuo-cpp/array-hash-map-improvements
std: Support equivalent ArrayList operations in ArrayHashMap
2021-01-06 16:32:23 -08:00
Andrew Kelley
76870a2265 Merge pull request #7700 from FireFox317/more-stage2-stuff-llvm
stage2: improvements to LLVM backend
2021-01-06 16:06:32 -08:00
BinaryWarlock
148c887ace spinlock: Default SpinLock.state to .Unlocked to allow default struct initialization
std.Mutex, which is struct initialized, is possibly defined to be std.SpinLock.
2021-01-06 15:54:30 -08:00
Andreas Karlsson
50af87a9e3 Fix example code in comments for asc and desc 2021-01-06 15:53:53 -08:00
joachimschmidt557
be6ac82ee1 stage2 ARM: fix stack offsets for genSetReg and genSetStack 2021-01-06 15:53:10 -08:00
joachimschmidt557
480d6182ad stage2 ARM: fix offsets in exitlude jump relocations 2021-01-06 15:53:10 -08:00
Frank Denis
5afd6204e8 Azure CI: update MSYS version 2021-01-06 15:52:34 -08:00
Andrew Kelley
efe94a9a12 stage2: C backend: support unused Decls 2021-01-06 16:47:09 -07:00
Timon Kruiper
b1cfa923be stage2: rename and move files related to LLVM backend 2021-01-06 10:52:20 +01:00
Timon Kruiper
31d1ec4c2f stage2: make use of llvm.Context in LLVM backend
This for example allows for multiple LLVM instances to run in parallel.

Also rename some functions in llvm_bindings.zig.

Fixes #7688
2021-01-06 10:52:20 +01:00
Timon Kruiper
5d5db833f2 stage2: hoist alloca instructions to top of function in LLVM backend
This way the generated code only has to setup the stack size at the
beginning of a function and this improves codegen.

Fixes #7689

```
fn foo() void {}

export fn hello(z: i8) void {
    var x: i16 = undefined;
    foo();
    var y: i32 = 1;
    y += z;
}
```
llvm-ir:
```
define void @hello(i8 %0) {
Entry:
  %1 = alloca i8, align 1
  %2 = alloca i16, align 2
  %3 = alloca i32, align 4
  store i8 %0, i8* %1, align 1
  %4 = load i8, i8* %1, align 1
  store i16 undef, i16* %2, align 2
  call void @foo()
  store i32 1, i32* %3, align 4
  %5 = load i32, i32* %3, align 4
  %6 = sext i8 %4 to i32
  %7 = add nsw i32 %5, %6
  store i32 %7, i32* %3, align 4
  ret void
}
```
2021-01-06 10:52:20 +01:00
Timon Kruiper
1149cd593e stage2: rename *const llvm.ValueRef to *const llvm.Value in LLVM backend
The same has been done for all the other LLVM types.
2021-01-06 10:52:19 +01:00
Timon Kruiper
70f6d16ae2 stage2: add initial impl for generating global decls in LLVM backend
Also adds support for extern functions, simple pointer and simple array
types and values.

A simple hello world now compiles:
`zig build-exe example.zig -fLLVM -lc`
```
extern fn puts(s: [*:0]const u8) c_int;
export fn main() c_int {
    _ = puts("hello world!");
    return 0;
}
```
2021-01-06 10:52:07 +01:00
Andrew Kelley
91e3431d4a stage2 test harness: don't try to run non-native C backend tests 2021-01-05 20:44:19 -07:00
g-w1
ab5f7b5156 stage2: add compile log statement 2021-01-05 18:43:41 -07:00
Andrew Kelley
38572ee894 Merge branch 'stage2-rework-cbe'
Reworks the C backend and -femit-h to properly participate in
incremental compilation.

closes #7602
2021-01-05 17:42:16 -07:00
Andrew Kelley
3e39d0c44f minor fixups from moving identifiers and files around 2021-01-05 17:41:22 -07:00
Andrew Kelley
1a2dd85570 stage2: C backend: re-implement emit-h
and also mark functions as `extern "C"` as appropriate to support c++
compilers.
2021-01-05 17:41:14 -07:00
Andrew Kelley
cd95444e47 stage2: C backend: remove format() hackery
All C backend tests passing now, except for emit-h tests. Next task in
the branch is to restore emit-h.
2021-01-05 17:41:14 -07:00
Andrew Kelley
58cfaa5982 stage2: C backend: adjust spaces around functions 2021-01-05 17:41:14 -07:00
Andrew Kelley
e1811f72eb stage2: link.C: use pwritev 2021-01-05 17:41:14 -07:00
Andrew Kelley
7b8cede61f stage2: rework the C backend
* std.ArrayList gains `moveToUnmanaged` and dead code
   `ArrayListUnmanaged.appendWrite` is deleted.
 * emit_h state is attached to Module rather than Compilation.
 * remove the implementation of emit-h because it did not properly
   integrate with incremental compilation. I will re-implement it
   in a follow-up commit.
 * Compilation: use the .codegen_failure tag rather than
   .dependency_failure tag for when `bin_file.updateDecl` fails.

C backend:
 * Use a CValue tagged union instead of strings for C values.
 * Cleanly separate state into Object and DeclGen:
   - Object is present only when generating a .c file
   - DeclGen is present for both generating a .c and .h
 * Move some functions into their respective Object/DeclGen namespace.
 * Forward decls are managed by the incremental compilation frontend; C
   backend no longer renders function signatures based on callsites.
   For simplicity, all functions always get forward decls.
 * Constants are managed by the incremental compilation frontend. C
   backend no longer has a "constants" section.
 * Participate in incremental compilation. Each Decl gets an ArrayList
   for its generated C code and it is updated when the Decl is updated.
   During flush(), all these are joined together in the output file.
 * The new CValue tagged union is used to clean up using of assigning to
   locals without an additional pointer local.
 * Fix bug with bitcast of non-pointers making the memcpy destination
   immutable.
2021-01-05 17:41:14 -07:00
Noam Preil
9360e5887c integrate CBE with Compilation.update pipeline (closes #7589)
* CBE buffers are only valid during a flush()
* the file is reopened and truncated during each flush()
* CBE now explicitly ignores updateDecl and deleteDecl
* CBE updateDecl is gone
* test case is enabled
2021-01-05 17:41:14 -07:00
xackus
6c4924408b std.c add syslog 2021-01-05 13:09:40 -08:00
xackus
1640c357f4 freebsd, netbsd, dragonfly: add struct timeval 2021-01-05 13:07:25 -08:00
Alex Cameron
d92ea56884 std: Support equivalent ArrayList operations in ArrayHashMap 2021-01-06 00:55:51 +11:00
Alex Cameron
89286376c6 std: Rename ArrayList shrink => shrinkAndFree 2021-01-06 00:55:51 +11:00
Andrew Kelley
3e8aaee829 std: skip more tests on Windows to save CI memory
I've enabled only the tests that check things specific to Windows that
are not tested by other systems.
2021-01-04 22:25:04 -07:00
Andrew Kelley
16896a9d8b ci: skip crypto tests on windows
Trying to buy us more time on the Windows CI.
2021-01-04 15:57:54 -07:00
Andrew Kelley
66e5e92a3e Merge pull request #7592 from LemonBoy/fix-7188
Allow variable captures on multi-prong switch arms
2021-01-04 14:23:01 -08:00
Evan Haas
d95724454c Allow dollar sign $ in identifiers in translate-c
In strictly conforming C, identifiers cannot container dollar signs.
However GCC and Clang allow them by default, so translate-c should
handle them. See http://gcc.gnu.org/onlinedocs/cpp/Tokenization.html
I encountered this in the wild in windows.h

Fixes #7585
2021-01-04 14:14:04 -08:00
Felix (xq) Queißner
819f2a01a1 Fixes missing error prong in std.os.send. 2021-01-04 14:03:39 -08:00
J.C. Moyer
fc3508b7e8 Fix off-by-one error in SinglyLinkedList.len() and add associated tests 2021-01-04 14:03:21 -08:00
xackus
a93c123f83 std.c: add some noalias 2021-01-04 14:02:42 -08:00
Andrew Kelley
2fe8a48215 ci: omit stage2 backend from stage1 on Windows
to avoid out-of-memory on the CI runs.
2021-01-04 14:59:18 -07:00
Andrew Kelley
462c1d8c74 stage2: add more perf tracing points 2021-01-04 14:33:32 -07:00
Andrew Kelley
fc38b42521 Revert "Fix #7296:"
This broke build scripts that wanted to refer to `exe_dir` or
`install_path`.

There has also been some pushback and discussion on this breaking
change. I think it should be re-evaluated.

This reverts commit a1a1929cf4.
2021-01-04 13:49:17 -07:00
Andrew Kelley
ef2fa67ef0 Merge branch 'g-w1-stage2-evalbranch'
closes #7682
2021-01-04 13:40:51 -07:00
Andrew Kelley
7e64dc4221 stage2: improvements to @setEvalBranchQuota
* extract magic number into a constant
 * properly use result location casting for the operand
 * naming convention for ZIR instructions
2021-01-04 13:40:01 -07:00
g-w1
638f93ebdc stage2: implementation of @setEvalBranchQuota:
`@setEvalBranchQuota` can be called before the comptime/inline call
stack is created.

For example:

```zig
@setEvalBranchQuota(100);
comptime {
    while (true) {}
}
```

Here we need to set the branch_quota before the comptime block creates a
scope for the branch_count.
2021-01-04 12:42:52 -07:00
joachimschmidt557
aa0906e9aa stage2 x86_64: fix bug in Function.gen
Previously, the x86_64 backend would remove code for exitlude relocs
if the jump amount were 0. This causes issues as earlier jumps rely on
the jump being present at the same address.
2021-01-03 19:54:12 -08:00
Frank Denis
4400d2d7ab std/crypto: add BLAKE2-160 types and tests 2021-01-03 19:53:30 -08:00
daurnimator
e4c4a0a5f6 Improve uring definitions 2021-01-03 19:52:20 -08:00
Andrew Kelley
53a0b7997d Merge pull request #7681 from kubkon/stage2-aarch64-fn-args
stage2: basic fn args for aarch64
2021-01-03 19:51:38 -08:00
Andrew Kelley
c8e44d82bd stage2: remove the Cache deadlock detection code
It's more trouble than it's worth; it didn't even catch the most recent
incident because it was across process boundaries anyway.
2021-01-03 20:34:51 -07:00
Andrew Kelley
404dc9692e stage2: fix Cache debug deadlock code memory leak 2021-01-03 20:34:51 -07:00
Andrew Kelley
5c92e24a29 drone ci: skip compile error tests to save time
These are covered by other CI scripts and we're up against Drone CI time
limits.
2021-01-03 20:10:07 -07:00
Andrew Kelley
f6644255f5 Merge pull request #7598 from FireFox317/more-llvm-stage2
stage2: More improvements to self-hosted LLVM backend
2021-01-03 16:09:14 -08:00
Evan Haas
5cc131030c Static function declarations with no prototype should not be variadic
If a static function is defined with no argument list and no prototype
is given, it should be treated as a function that takes no arguments
rather than as a variadic function.

Fixes #7594
2021-01-03 15:08:32 -08:00
Jakub Konka
807dc56fd6 stage2: add aarch64 stage2 tests
Fix missing string format specifier in Mach-O used to generate
path to debug symbols bundle.
2021-01-03 23:20:09 +01:00
Jakub Konka
2a410baa2b stage2: implement basic function params aarch64
Implement missing `.register` prong for `aarch64` `genSetReg`.
2021-01-03 23:03:20 +01:00
Timon Kruiper
0151f3b76a stage2: Add support for testing LLVM enabled builds in test-stage2
To make sure that we don't have to rebuild libc for every case, we now
have a seperate cache directory for the global cache, which remains
the same between test runs.

Also make sure to destory the Compilation before executing a child process,
otherwise the compiler deadlocks. (#7596)
2021-01-03 21:13:38 +01:00
Timon Kruiper
a926c91814 stage2: enable building test-stage2 with LLVM backend enabled
We can now run `zig build test-stage2 -Denable-llvm`.
2021-01-03 17:39:43 +01:00
Timon Kruiper
7e5aacab69 stage2: add some missing deallocations in Compilation.zig 2021-01-03 17:39:43 +01:00
Timon Kruiper
3c05c60acc stage2: Output the LLVM object files in the cache directory
Also make sure to properly free everything.
2021-01-03 17:39:43 +01:00
Timon Kruiper
0008bef1e6 stage2: add support for integers in LLVM backend
Also adds support for simple operators, like add and subtract.
The intcast and bitcast instruction also have been implemented.

Linking with libc also works, so we can now generate working executables!

`zig build-exe example.zig -fLLVM -lc`:
```
fn add(a: i32, b: i32) i32 {
    return a + b;
}

export fn main() c_int {
    var a: i32 = -5;
    const x = add(a, 7);
    var y = add(2, 0);
    y -= x;
    return y;
}
```
2021-01-03 17:39:30 +01:00
Timon Kruiper
e095ebf312 stage2: make use of proper LLVM intrinsic APIs in LLVM backend 2021-01-03 17:23:30 +01:00
Timon Kruiper
da545d6a31 stage2: implement argument passing and returning in LLVM backend
Furthermore add the Not instruction.

The following now works:
```
export fn _start() noreturn {
    var x: bool = true;
    var other: bool = foo(x);
    exit();
}

fn foo(cond: bool) bool {
    return !cond;
}

fn exit() noreturn {
    unreachable;
}
```
2021-01-03 17:23:30 +01:00
Timon Kruiper
47a4d43e41 stage2: Add code generation for Load instruction in LLVM backend
The following now works:
```
export fn _start() noreturn {
    var x: bool = true;
    var y: bool = x;
    exit();
}

fn exit() noreturn {
    unreachable;
}
```
2021-01-03 17:23:30 +01:00
Timon Kruiper
19cfd310b0 stage2: implement register allocation in LLVM self-hosted backend
A HashMap has been added which store the LLVM values used in a function.
Together with the alloc and store instructions the following now works:
```
export fn _start() noreturn {
    var x: bool = true;
    exit();
}

fn exit() noreturn {
    unreachable;
}
```
2021-01-03 17:23:30 +01:00
Timon Kruiper
a5dab15ede stage2: clear err_msg after it has been added to module.failed_decls 2021-01-03 17:23:30 +01:00
Timon Kruiper
0ed04aac8b stage2: fix building self-hosted compiler with -Dstatic-llvm
This supersedes c81ae52ee0
2021-01-03 17:23:30 +01:00
Frank Denis
5aac2fc281 std/crypto: properly support arbitrary output sizes
Fixes #7657
2021-01-02 22:32:57 -08:00
Andrew Kelley
683814190b Merge pull request #7612 from g-w1/do-7296
Implement #7296
2021-01-02 22:05:31 -08:00
Andrew Kelley
d8f3f14532 Merge pull request #7647 from ziglang/stage2-comptime-fn-call
stage2: comptime function calls and inline function calls
2021-01-02 22:01:51 -08:00
Andrew Kelley
654832253a stage2: support recursive inline/comptime functions
zir.Inst no longer has an `analyzed_inst` field. This is previously how
we mapped ZIR to their TZIR counterparts, however with the way inline
and comptime function calls work, we can potentially have the same ZIR
structure being analyzed by multiple different analyses, such as during
a recursive inline function call. This would cause the `analyzed_inst`
field to become clobbered. So instead, we use a table to map the
instructions to their semantically analyzed counterparts. This will help
with multi-threaded compilation as well.

Scope.Block.Inlining is split into 2 different layers of "sharedness".
The first layer is shared by the whole inline/comptime function call
stack. It contains the callsite where something is being inlined and the
branch count/quota. The second layer is different per function call but
shared by all the blocks within the function being inlined.

Add support for debug dumping br and brvoid TZIR instructions.

Remove the "unreachable code" error. It was happening even for this case:

```zig
if (comptime_condition) return;
bar(); // error: unreachable code
```

We will need smarter logic for when it is legal to emit this compile
error.

Remove the ZIR test cases. These are redundant with other higher level
Zig source tests we have, and maintaining support for ZIRModule as a
first-class top level abstraction is getting in the way of clean
compiler design for the main use case. We will have ZIR/TZIR based test
cases someday to help with testing optimization passes and ZIR to TZIR
analysis, but as is, these test cases are not accomplishing that, and
they are getting in the way.
2021-01-02 22:42:07 -07:00
g-w1
3d151fbfc8 fix 7665:
only add self exe path when testing
2021-01-02 20:35:44 -08:00
Andrew Kelley
50a530196c stage2: fix handling compile error in inline fn call
* scopes properly inherit inlining information
 * compile errors of inline function calls are properly attached to the
   caller rather than the callee.
   - added a test case for this
 * --watch still opens a repl if compile errors happen.
2021-01-02 19:11:56 -07:00
Andrew Kelley
006e7f6805 stage2: re-use ZIR for comptime and inline calls
Instead of freeing ZIR after semantic analysis, we keep it around so
that it can be used for comptime calls, inline calls, and generic
function calls. ZIR memory is now managed by the Decl arena.

Debug dump() functions are conditionally compiled; only available in
Debug builds of the compiler.

Add a test for an inline function call.
2021-01-02 19:11:55 -07:00
Andrew Kelley
9362f382ab stage2: implement function call inlining in the frontend
* remove the -Ddump-zir thing. that's handled through --verbose-ir
 * rework Fn to have an is_inline flag without requiring any more memory
   on the heap per function.
 * implement a rough first version of dumping typed zir (tzir) which is
   a lot more helpful for debugging than what we had before. We don't
   have a way to parse it though.
 * keep track of whether the inline-ness of a function changes because
   if it does we have to go update callsites.
 * add compile error for inline and export used together.

inline function calls and comptime function calls are implemented the
same way. A block instruction is set up to capture the result, and then
a scope is set up that has a flag for is_comptime and some state if the
scope is being inlined.

when analyzing `ret` instructions, zig looks for inlining state in the
scope, and if found, treats `ret` as a `break` instruction instead, with
the target block being the one set up at the inline callsite.

Follow-up items:
 * Complete out the debug TZIR dumping code.
 * Don't redundantly generate ZIR for each inline/comptime function
   call. Instead we should add a new state enum tag to Fn.
 * comptime and inlining branch quotas.
 * Add more test cases.
2021-01-02 19:11:19 -07:00
Andrew Kelley
fea8659b82 stage2: comptime function calls
* Function calls that happen in a comptime scope get called at
   compile-time. We do this by putting the parameters in place as
   constant values and then running regular function analysis on the
   body.
 * Added `Scope.Block.dump()` for debugging purposes.
 * Fixed some code to call `identifierTokenString` rather than
   `tokenSlice`, making it work for `@""` syntax.
 * Implemented `Value.copy` for big integers.

Follow-up issues to tackle:
 * Adding compile errors to the callsite instead of the callee Decl.
 * Proper error notes for "called from here".
   - Related: #7555
 * Branch quotas.
 * ZIR support?
2021-01-02 19:10:11 -07:00
Andrew Kelley
fb37c1b091 Merge branch 'LemonBoy-revive-6680'
closes #6870
2021-01-02 19:03:37 -07:00
Andrew Kelley
974c008a0e convert more {} to {d} and {s} 2021-01-02 19:03:14 -07:00
LemonBoy
5b981b1be7 Remove some unwanted changes
Leftovers after a long rebase.
2021-01-02 17:12:58 -07:00
LemonBoy
608a73efb1 Decrement max_depth when printing slice elements 2021-01-02 17:12:57 -07:00
LemonBoy
04f37dcd8e stage2: Use {z} instead of {s} in generated Zig code 2021-01-02 17:12:57 -07:00
LemonBoy
1fbe89dc2e langref: Update langref to use {s} 2021-01-02 17:12:57 -07:00
LemonBoy
d2f6fa1608 Fix more stray uses of {} for formatting strings 2021-01-02 17:12:57 -07:00
LemonBoy
1ca2deca33 std: Disable the special casing of {} for u8 slices/arrays
Unless {s} is specified the contents won't be treated as a string.
2021-01-02 17:12:57 -07:00
LemonBoy
4420afe64d tests: Use {s} instead of {} when formatting strings 2021-01-02 17:12:57 -07:00
LemonBoy
1c13ca5a05 stage2: Use {s} instead of {} when formatting strings 2021-01-02 17:12:57 -07:00
LemonBoy
dd973fb365 std: Use {s} instead of {} when printing strings 2021-01-02 17:12:57 -07:00
LemonBoy
5a06fdfa55 Use same brace pairs for arrays/slices/vectors 2021-01-02 17:12:57 -07:00
LemonBoy
d4a8fc8b67 Small cleanup 2021-01-02 17:12:57 -07:00
data-man
2b5e93fd3e Add formatting for arrays 2021-01-02 17:12:57 -07:00
LemonBoy
6f53653db1 std: Refactor the slice formatting code
Also fix the `*` specifier for more types, print an error message if we
can't show the value address.
2021-01-02 17:12:57 -07:00
ryuukk
5275280ede Formatting fix 2021-01-02 17:12:57 -07:00
ryuukk
1d97747665 Pretty print Slices
This code is adapted from pixelherodev paste from IRC

I have added a new fmt option to handle printing slice values ``{v}`` or ``{V}``

While i think it can be made the default, i want your opinion about it

```zig
    var slicea = [0]u32{};
    var sliceb = [3]u32{ 1, 2, 3 };

    std.log.info("Content: {v}", .{slicea});
    std.log.info("Content: {v}", .{sliceb});
```

will print:

```
info: Content: []
info: Content: [1, 2, 3]
```

Question:

Should we drop ``{v}`` and make it the default behavior?
2021-01-02 17:12:57 -07:00
Cameron Conn
db1e97d4b1 Improve documentation for ArrayList, ArrayListUnmanaged, etc. (#7624)
* Improve ArrayList & co documentation

- Added doc comments about the validity of references to elements in
an ArrayList and how they may become invalid after resizing operations.
- This should help users avoid footguns in future.

* Improve ArrayListUnmanaged & co's documentation

- Port improved documentation from ArrayList and ArrayList aligned to
  their unmanaged counterparts.
- Made documentation for ArrayListUnmanaged & co more inclusive and
  up-to-date.
- Made documentation more consistent with `ArrayList`.

* Corrections on ArrayList documentation.

- Remove incorrect/unpreferred wording on ArrayList vs
  ArrayListUnmanaged.
- Fix notes about the alignment of ArrayListAligned
- Be more verbose with warnings on when pointers are invalidated.
- Copy+paste a few warnings

* add warning to replaceRange

* revert changes to append documentation
2021-01-02 19:06:51 -05:00
LemonBoy
1856dfea6b stage1: Use correct format specifier for size_t parameters
Use `Iu` on Windows, the integer width depends on the target being
a 32bit or a 64bit one.
2021-01-02 16:04:34 -08:00
Sizhe Zhao
af8eab546e Fix usage message 2021-01-02 16:03:41 -08:00
Andrew Kelley
44c9bf559b std: disable a couple tests on windows
They are passing but we're hitting OOM on the Windows CI server. This is
to buy us more time until stage2 rescues us from the CI memory crisis.
2021-01-02 12:21:19 -07:00
Jakub Konka
5a6579611f Merge pull request #7506 from kubkon/fix-6923
zig cc: detect framework include paths when native
2021-01-02 20:08:37 +01:00
Jakub Konka
763d807377 Duplicate OSAtomic.h between aarch64 and x86_64
The reason this is required is for two reasons: 1) the libc
targeting `aarch64` macOS is slightly newer than that targeting
`x86_64`, and 2) `OSAtomic.h` uses relative imports rather than
system-wide imports for accompanying headers which clearly is an
oversight on Apple's part. Until such time when `libkern` headers
between `x86_64` and `aarch64` are identical, this will require a
manual intervention to duplicate the relevant headers between the
respective architectures.
2021-01-02 15:30:14 +01:00
Jakub Konka
91a35e1a92 Detect native iframework dirs on macOS
This commit adds default search paths for system frameworks
on macOS while also adding `-isysroot` for OS versions at least BigSur.
Since BigSur (11.0.1), neither headers nor libs exist in standard
root locations (`/usr/include`, `/System/Library/Frameworks`). Instead, they
are now exclusively part of the installed developer toolchain (either
via XCode.app or CLT), and specifying `-isysroot` allows us to keep
using universal search paths such as `/System/Library/Frameworks` while
only changing the include flag from `-iframework` to
`-iframeworkwithsysroot`.
2021-01-02 15:29:05 +01:00
Sébastien Marie
a9c75a2b48 openbsd: add pollfd interface 2021-01-01 20:05:19 -08:00
Andrew Kelley
ca0b03f7b5 Merge branch 'jayschwa-ci-deep-clone'
closes #7629
2021-01-01 21:03:35 -07:00
Andrew Kelley
ec8c25fd8f Restore the reverted semantic versioning commits
restore "Comply with semantic versioning pre-release format"
restore "stage2: SemVer compliance for development builds"
restore "Remove 'g' prefix from commit hash in Zig semver"

This reverts commit d96d8639e5.
This reverts commit e8810f5794.
This reverts commit 9afe5859a3.
2021-01-01 21:02:32 -07:00
Jay Petacat
993f4b5a06 ci: fix git describe
git describe is used for version string creation, but it had to be
reverted in commit 69da6ba because it was broken in CI builds.
Azure Pipelines and Drone perform shallow clones by default.
This change reconfigures them to fetch history and tags. It adds tens of
seconds, which is negligible compared to overall build and test time.

Related: #6466, #6509, #7601
2021-01-01 20:41:39 -07:00
Isaac Freund
d3ecbbebd3 std/build: assert that install paths are relative
If absolute paths are passed they will work unless $DESTDIR is set,
which causes subtly broken build.zig's.
2021-01-01 18:57:23 -08:00
Andrew Kelley
3dafc5b9a3 Merge branch 'daurnimator-meta.fields'
closes #7420
2021-01-01 16:01:27 -07:00
daurnimator
bbab5e19b4 std: loop in trailer flags can be indexing operation 2021-01-01 15:48:48 -07:00
daurnimator
4387e50d4f std: use FieldEnum from TrailerFlags 2021-01-01 15:48:48 -07:00
daurnimator
9c97a07f18 std: have std.meta.fieldInfo take an enum rather than a string 2021-01-01 15:48:46 -07:00
daurnimator
73bf2e1525 std: add std.meta.FieldEnum 2021-01-01 15:48:04 -07:00
joachimschmidt557
c5ec096b2f stage2 AArch64: add logical (shifted register) instructions 2021-01-01 14:43:12 -08:00
Andrew Kelley
6c0c275b27 Merge branch 'LemonBoy-panicthreadid'
closes #6869
2021-01-01 14:57:03 -07:00
Andrew Kelley
c24540d263 std.debug: adjust panic message
also extern "c" instead of extern "pthread"
2021-01-01 14:56:26 -07:00
LemonBoy
c9756ca0e1 std: Show the panicking thread ID
Annotate the panic message with the thread ID to know who's the culprit.
2021-01-01 14:54:53 -07:00
Sizhe Zhao
3bce5b2f30 Fix ssize_t definition 2021-01-01 13:47:18 -08:00
Andrew Kelley
99203e4177 Merge pull request #7578 from vrischmann/walker
fix segfault in std.fs.Walker
2021-01-01 13:28:01 -08:00
Andrew Kelley
4cc374c639 Merge pull request #7634 from daurnimator/packed-init-all-to
Add PackedIntArray .initAllTo function
2021-01-01 13:23:18 -08:00
Andrew Kelley
dfacac916f Merge pull request #7565 from joachimschmidt557/stage2-arm
stage2 ARM: add conditional branches
2021-01-01 13:19:11 -08:00
Jakub Konka
5dfeb6cbc8 macho: unblock stage2 on 32bit platforms (#7632)
* macho: unblock stage2 on 32bit platforms

Unblocks compilation of stage2 on 32bit platforms, and fixes #7630.

* Use libstd convention: reads - usize, writes - u64
2021-01-01 21:28:52 +01:00
Andrew Kelley
1cef0be01b Merge pull request #7640 from daurnimator/use-markInvalidUserInput
Don't process.exit() on invalid option use .markInvalidUserInput
2021-01-01 11:48:36 -08:00
daurnimator
aa631cfd1f Build errors should be followed by two newlines 2021-01-02 04:13:08 +11:00
daurnimator
b3c9dfc9cc Don't process.exit() on invalid option use .markInvalidUserInput 2021-01-02 04:09:59 +11:00
daurnimator
ad1780959d std/build.zig: use (existing) warn function alias 2021-01-02 04:01:21 +11:00
daurnimator
03e2c53747 Add workaround in PackedIntArray .initAllTo for #7635 2021-01-02 01:10:47 +11:00
daurnimator
31ba9d569b Add PackedIntArray .initAllTo function 2021-01-02 00:52:47 +11:00
joachimschmidt557
a2ab2fb9b0 stage2 ARM: Add simple tests for conditional branching 2021-01-01 12:22:17 +01:00
joachimschmidt557
c52ca0b178 stage2 ARM: implement genSetReg with compare_flags 2021-01-01 12:22:16 +01:00
joachimschmidt557
85e1b47c40 stage2 ARM: implement genCondBr for compare_flags 2021-01-01 12:22:16 +01:00
joachimschmidt557
4d2919a1ee stage2 ARM: implement genCondBr 2021-01-01 12:22:14 +01:00
g-w1
33e53d7294 update .gitignore to include /release/ and /debug/ 2020-12-31 21:30:25 -05:00
g-w1
a1a1929cf4 Fix #7296:
* makes '$build_root/{install,debug}/' the default prefix. This makes it not '$pwd/zig-cache/'.
2020-12-31 20:02:07 -05:00
Andrew Kelley
93bb1d93cd Merge pull request #7616 from ziglang/stage2-inferred-vars
stage2: inferred local variables
2020-12-31 16:28:08 -08:00
Andrew Kelley
982acc22fd stage2: compile error for invalid var type 2020-12-31 17:25:42 -07:00
Andrew Kelley
79a9391414 stage2: no Payload for Type.Tag.inferred_alloc
Simpler, less memory usage. The Value has all the info needed.
2020-12-31 16:51:40 -07:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Andrew Kelley
69da6ba14d Merge branch 'revert-semver'
Updating the download page is stuck because in all cases
`zig version` is outputting 0.8.0 rather than e.g.
0.8.0-dev.716+fbf269cc4.

See #6466
2020-12-31 16:41:54 -07:00
Andrew Kelley
d96d8639e5 Revert "Comply with semantic versioning pre-release format"
This reverts commit bbe2cca1ae.
2020-12-31 16:41:42 -07:00
Andrew Kelley
e8810f5794 Revert "stage2: SemVer compliance for development builds"
This reverts commit 4af763d401.
2020-12-31 16:41:35 -07:00
Andrew Kelley
9afe5859a3 Revert "Remove 'g' prefix from commit hash in Zig semver"
This reverts commit 02438aabe3.
2020-12-31 16:41:24 -07:00
Jakub Konka
fbf269cc47 More MachO.zig fixes ensuring 32bit compat
Partial resolution to #7614.
2020-12-31 14:57:08 +01:00
LemonBoy
102e45e04f stage1: Remove stray brace in rarely-tested code path
This should fix #7614 or part of it.
2020-12-31 14:35:19 +01:00
Jakub Konka
707b81ec37 Make sure MachO.zig compiles on 32bit hosts
This should fix #7614 or part of it.
2020-12-31 14:30:53 +01:00
Jakub Konka
46ea7a704c Merge pull request #7608 from kubkon/macho-dsym
macho: add preliminary support for DWARF debugging symbols
2020-12-31 11:38:13 +01:00
Andrew Kelley
7deb1f4f6c stage2: type inference for local var 2020-12-31 02:42:48 -07:00
Jakub Konka
0fd3015e55 macho: sentinel can be 4 byte long 2020-12-31 10:19:04 +01:00
Jakub Konka
9369176332 macho: advance VM address of DWARF sections when relocating 2020-12-31 10:19:04 +01:00
Jakub Konka
ea4ff34e13 macho: put all DWARF-related logic into DebugSymbols 2020-12-31 10:19:04 +01:00
Jakub Konka
d189614647 macho: move updateDeclLineNumber logic to DebugSymbols 2020-12-31 10:19:04 +01:00
Jakub Konka
60b3c4ae3c macho: refactor and fix stage2 tests 2020-12-31 10:19:04 +01:00
Jakub Konka
364691fa1f macho: add decl line and file info to subprogram 2020-12-31 10:19:04 +01:00
Jakub Konka
fa28f7006d macho: fix bundle name to .dSYM 2020-12-31 10:19:04 +01:00
Jakub Konka
9318656ce2 macho: use 32bit DWARF format 2020-12-31 10:19:04 +01:00
Jakub Konka
2875a7335a macho: add Elf dwarf sections 2020-12-31 10:19:04 +01:00
Jakub Konka
d4725cb40b macho: prealloc space for debug sections in dSym 2020-12-31 10:19:04 +01:00
Jakub Konka
3174508903 macho: write symbol and string tables to dSym 2020-12-31 10:19:04 +01:00
Jakub Konka
d9ce7a021b macho: copy snapshots of segment commands 2020-12-31 10:19:04 +01:00
Jakub Konka
a7bae1b857 macho: write matching UUID to dSym bundle 2020-12-31 10:19:04 +01:00
Jakub Konka
cf94341910 macho: write Mach-O dSym header 2020-12-31 10:19:04 +01:00
Jakub Konka
bd99a87dc2 macho: create dSym bundle next to final artefact
macOS requires the debug symbols to either be part of the intermediate
object file `whatever.o` or a companion `whatever.dSym` bundle. The
former case seems ill-suited for our needs since it subscribes to
the old-fashioned compilation strategy using intermediate compilation
units; the latter is what we need however on macOS the debug symbols
unlike in Elf are not part of the final artefact; rather they sit
next to it in its own Mach-O file.
2020-12-31 10:19:04 +01:00
Jakub Konka
0ff56e8bb1 macho: add and populate UUID load command 2020-12-31 10:19:04 +01:00
Jakub Konka
e1451f92f8 macho: move findFreeSpace into SegmentCommand
One exception will be treatment of the __LINKEDIT segment which
will be handled separately inside MachO directly since it doesn't
include any sections.
2020-12-31 10:19:04 +01:00
Andrew Kelley
595397dbeb Merge pull request #7601 from jayschwa/stage2-semver
stage2: SemVer compliance for development builds
2020-12-31 01:15:18 -08:00
Andrew Kelley
a46d24af1c stage2: inferred local variables
This patch introduces the following new things:

Types:
 - inferred_alloc
   - This is a special value that tracks a set of types that have been stored
     to an inferred allocation. It does not support most of the normal type queries.
     However it does respond to `isConstPtr`, `ptrSize`, `zigTypeTag`, etc.
   - The payload for this type simply points to the corresponding Value
     payload.

Values:
 - inferred_alloc
   - This is a special value that tracks a set of types that have been stored
     to an inferred allocation. It does not support any of the normal value queries.

ZIR instructions:
 - store_to_inferred_ptr,
   - Same as `store` but the type of the value being stored will be used to infer
     the pointer type.
 - resolve_inferred_alloc
   - Each `store_to_inferred_ptr` puts the type of the stored value into a set,
     and then `resolve_inferred_alloc` triggers peer type resolution on the set.
     The operand is a `alloc_inferred` or `alloc_inferred_mut` instruction, which
     is the allocation that needs to have its type inferred.

Changes to the C backend:
 * Implements the bitcast instruction. If the source and dest types
   are both pointers, uses a cast, otherwise uses memcpy.
 * Tests are run with -Wno-declaration-after-statement. Someday we can
   conform to this but not today.

In ZIR form it looks like this:

```zir
fn_body main { // unanalyzed
  %0 = dbg_stmt()
=>%1 = alloc_inferred()
  %2 = declval_in_module(Decl(add))
  %3 = deref(%2)
  %4 = param_type(%3, 0)
  %5 = const(TypedValue{ .ty = comptime_int, .val = 1})
  %6 = as(%4, %5)
  %7 = param_type(%3, 1)
  %8 = const(TypedValue{ .ty = comptime_int, .val = 2})
  %9 = as(%7, %8)
  %10 = call(%3, [%6, %9], modifier=auto)
=>%11 = store_to_inferred_ptr(%1, %10)
=>%12 = resolve_inferred_alloc(%1)
  %13 = dbg_stmt()
  %14 = ret_type()
  %15 = const(TypedValue{ .ty = comptime_int, .val = 3})
  %16 = sub(%10, %15)
  %17 = as(%14, %16)
  %18 = return(%17)
} // fn_body main
```

I have not played around with very many test cases yet. Some interesting
ones that I want to look at before merging:

```zig
var x = blk: {
  var y = foo();
  y.a = 1;
  break :blk y;
};
```

In the above test case, x and y are supposed to alias.

```zig
var x = if (bar()) blk: {
  var y = foo();
  y.a = 1;
  break :blk y;
} else blk: {
  var z = baz();
  z.b = 1;
  break :blk z;
};
```

In the above test case, x, y, and z are supposed to alias.

I also haven't tested with `var` instead of `const` yet.
2020-12-31 01:54:02 -07:00
Luna
7550af0d4c ci: freebsd: use py37-s3cmd 2020-12-31 08:18:06 +01:00
Andrew Kelley
3f7d9b5fc1 stage2: rework Value Payload layout
This is the same as the previous commit but for Value instead of Type.

Add `Value.castTag` and note that it is preferable to call than
`Value.cast`. This matches other abstractions in the codebase.

Added a convenience function `Value.Tag.create` which really cleans up
the callsites of creating `Value` objects.

`Value` tags can now share payload types. This is in preparation for
another improvement that I want to do.
2020-12-30 21:41:02 -08:00
Andrew Kelley
133da8692e stage2: rework Type Payload layout
Add `Type.castTag` and note that it is preferable to call than
`Type.cast`. This matches other abstractions in the codebase.

Added a convenience function `Type.Tag.create` which really cleans up
the callsites of creating `Type` objects.

`Type` payloads can now share types. This is in preparation for another
improvement that I want to do.
2020-12-30 21:41:02 -08:00
Jay Petacat
02438aabe3 Remove 'g' prefix from commit hash in Zig semver 2020-12-30 20:57:50 -06:00
LemonBoy
2622575fde std: Remove duplicated code
Make osRequiresLibC call Os.requiresLibC, let's keep a single list of OS
that require the libc to be linked in.
2020-12-30 14:45:39 -08:00
LemonBoy
daed2ba2a0 std: Add more standard type definitions for FreeBSD
Closes #7550
2020-12-30 10:25:43 -08:00
LemonBoy
2561168adb std: Clean up some tests
No functional changes, remove some dead code.
2020-12-30 09:42:21 +01:00
LemonBoy
88634f0481 stage1: Allow variable capture for multi-prong switch arms
Handle the multi-prong case as we do with range cases.

Closes #7188
2020-12-30 09:42:20 +01:00
Jay Petacat
4af763d401 stage2: SemVer compliance for development builds
This matches the behavior of CMake builds. These changes should have
been in PR #6509, but were missed.
2020-12-29 23:25:58 -06:00
Isaac Freund
3634d44d08 std: fix Reader.readUntilDelimiterOrEofAlloc() API
The current API does not allow the user to distinguish between EOF and
an empty line. Reader.readUntilDelimiterOrEof() gets this API right so
update readUntilDelimiterOrEofAlloc() to match it. Returning an optional
here additionally makes calling this in a loop much cleaner.

Remove readUntilDelimiterOrEofArrayList() as it no longer needed to
implement readUntilDelimiterOrEof() and has the same API issues
described without a clear way to fix them.
2020-12-29 19:09:36 -08:00
Andrew Kelley
3d79ae2be3 stage2 tests: improve C backend testing
Add -Werror -pedantic -std=c89 to make sure our outputted C code is
squeaky clean.

Allow garbage to be printed to stderr for Execution tests because
wasmtime is printing a bogus warning, causing the CI to fail.
2020-12-29 20:01:18 -07:00
Andrew Kelley
d18b6785bb stage2: C backend improvements
* Module: improve doc comments
 * C backend: improve const-correctness
 * C backend: introduce renderTypeAndName
 * C backend: put `static` on functions when appropriate
 * C backend: fix not handling errors in genBinOp
 * C backend: handle more IR instructions
   - alloc, store, boolean comparisons, ret_ptr
 * C backend: call instruction properly stores its result
 * test harness: ensure execution tests have empty stderr
2020-12-29 17:56:30 -07:00
LemonBoy
1ac512df70 stage1: Let LLVM legalize the overflowing ops on vectors
LLVM is smart enough to produce tight overflow checking sequences.

On x86_64 a simple v4u32 addition is turned from:

```
  c5 e9 d4 d4                  	vpaddq	%xmm4, %xmm2, %xmm2
  c5 f1 d4 cb                  	vpaddq	%xmm3, %xmm1, %xmm1
  c5 f8 28 e9                  	vmovaps	%xmm1, %xmm5
  c4 e3 55 18 ea 01            	vinsertf128	$1, %xmm2, %ymm5, %ymm5
  c5 f0 c6 da 88               	vshufps	$136, %xmm2, %xmm1, %xmm3
  c5 c8 57 f6                  	vxorps	%xmm6, %xmm6, %xmm6
  c4 e3 55 0c ee aa            	vblendps	$170, %ymm6, %ymm5, %ymm5
  c4 e3 7d 19 ec 01            	vextractf128	$1, %ymm5, %xmm4
  c4 e2 69 29 d4               	vpcmpeqq	%xmm4, %xmm2, %xmm2
  c5 e9 ef d0                  	vpxor	%xmm0, %xmm2, %xmm2
  c4 e2 71 29 cd               	vpcmpeqq	%xmm5, %xmm1, %xmm1
  c5 f1 ef c0                  	vpxor	%xmm0, %xmm1, %xmm0
  c5 f9 6b c2                  	vpackssdw	%xmm2, %xmm0, %xmm0
  c5 f8 50 c0                  	vmovmskps	%xmm0, %eax
  84 c0                        	testb	%al, %al
```

into:

```
  c5 f9 fe c9                  	vpaddd	%xmm1, %xmm0, %xmm1
  c4 e2 71 3f c0               	vpmaxud	%xmm0, %xmm1, %xmm0
  c5 f1 76 c0                  	vpcmpeqd	%xmm0, %xmm1, %xmm0
  c5 f8 50 c0                  	vmovmskps	%xmm0, %eax
  34 0f                        	xorb	$15, %al
  0f 95 c1                     	setne	%cl
  f6 c1 01                     	testb	$1, %cl
```
2020-12-29 14:28:39 -07:00
Jay Petacat
bbe2cca1ae Comply with semantic versioning pre-release format
Example version: 0.8.0-dev.460+g81b343a16

From a semantic versioning perspective, development builds will now be
considered distinct from a tagged release. The number of commits added
since the last tag is included in the pre-release component.

Updates #6466
2020-12-29 13:17:08 -08:00
Andrew Kelley
8078d8cd3f std.ChildProcess: fix max_output_bytes handling
The previous logic had a false positive of returning an error when in
fact the maximum number of output bytes had not been exceeded.
2020-12-29 14:02:12 -07:00
Andrew Kelley
0b46c27333 zig test: release Compilation Cache locks
before executing child process. This fixes a deadlock when the test
wanted to obtain the same lock on compiler_rt.o that was held by the
process building the test binary itself.
2020-12-29 11:47:29 -07:00
Andrew Kelley
e54fd25781 Merge branch 'LemonBoy-cprocess'
This is a partial merge of #6750. I took the Posix code paths and
dropped the Windows code paths, and then did the improvements noted in
the comments.

The Windows implementation is still TODO.
2020-12-29 11:16:28 -07:00
Andrew Kelley
717cf00fe0 std.ChildProcess: improvements to collectOutputPosix
* read directly into the ArrayList buffers.
 * respect max_output_bytes

 * std.ArrayList:
   - make `allocatedSlice` public.
   - add `unusedCapacitySlice`.

I removed the Windows implementation of this stuff; I am doing a partial
merge of LemonBoy's patch with the understanding that a later patch can
add the Windows implementation after it is vetted.
2020-12-29 11:13:00 -07:00
LemonBoy
892b37cdae std: Use WINAPI instead of .Stdcall 2020-12-29 10:40:28 -07:00
LemonBoy
b297c2eae9 std: Fix compilation on FreeBSD/Darwin 2020-12-29 10:40:26 -07:00
LemonBoy
1667c937a0 std: Uniform polling logic for Windows and Unix
Keep polling until there are enough open handles, if the child process
terminates closing the handles or explicitly closes them we just quit
polling and wait for the process handle to signal the termination
condition.
2020-12-29 10:40:00 -07:00
LemonBoy
2c16a96686 std: Fix poll definitions for FreeBSD/Darwin 2020-12-29 10:40:00 -07:00
LemonBoy
dc810eb73b std: Avoid deadlocking in ChildProcess.exec
Reading stdin&stderr at different times may lead to nasty deadlocks (eg.
when stdout is read before stderr and the child process doesn't write
anything onto stdout).

Implement a polling mechanism to make sure this won't happen: we read
data from stderr/stdout as it becomes ready and then it's copied into an
ArrayList provided by the user, avoiding any kind of blocking read.
2020-12-29 10:40:00 -07:00
Andrew Kelley
1590ed9d6a stage2 tests: pass cwd to child process to fix exe path
Previous commit broke the tests for non-Windows because we were
intending to change the cwd when running the child process. However, for
Windows we don't support passing a directory handle for cwd when
spawning child processes yet. However on Linux we do. This commit
reverts the previous one but then fixes things for all systems by
passing both cwd_dir and cwd to the child process.
2020-12-29 00:33:08 -07:00
Andrew Kelley
7e1e771f02 stage2 tests: fix incorrect path used for execution binary 2020-12-28 23:06:47 -08:00
Andrew Kelley
79a5151155 Revert "stage2: fix compilation of self-hosted compiler with -Denable-llvm"
This broke compiling with -Dstage1 on Windows, because it added the
cpp_source_files to the compilation multiple times.

This reverts commit c81ae52ee0.
2020-12-28 22:41:29 -08:00
Frank Denis
8ab870cf56 std/crypto: increment the correct words for vectorized salsa20
Add a test for this by the way.

Fixes #7579
2020-12-28 21:28:39 -08:00
Andrew Kelley
1dd5c032bf stage2 tests: better failure reporting for failed execution 2020-12-28 22:21:25 -07:00
Andrew Kelley
a62353fb4b fix zig test with regards to passing parameters 2020-12-28 22:15:07 -07:00
Andrew Kelley
e0a78d10cc stage2: better error message for root zig source file not found
closes #6777
closes #6893
2020-12-28 21:49:40 -07:00
Andrew Kelley
78dcd1b23e std.process: update arg iterator tests
These tests asserted there were no args passed to the test binary, but
now there is an arg intentionally passed to the test binary, so the test
case needed to be updated.
2020-12-28 21:09:47 -07:00
Andrew Kelley
3b5dd48f99 Merge branch 'hello-c-backend' into master
This branch introduces a new kind of test into the stage2 test harness:
Zig code that compiles into C code with the C backend, and then the
resulting C code gets run and output compared against the expected
result.

This branch also implements extern functions in the frontend so that we
can have a "hello world" C backend test that passes.
2020-12-28 20:32:53 -07:00
Andrew Kelley
813d3308cc stage2: update C backend test cases for new output 2020-12-28 20:32:13 -07:00
Andrew Kelley
bbe66572e1 stage2: C backend: handle string literals more gracefully 2020-12-28 20:15:17 -07:00
Andrew Kelley
7561fca435 stage2: improve test harness to support executing generated C code 2020-12-28 20:01:17 -07:00
Andrew Kelley
7ca9f3bc7b zig test: std.testing.zig_exe_path is now available
it will be set to the path of the zig executable which is running
`zig test`.
2020-12-28 20:00:34 -07:00
Andrew Kelley
a54ccd8537 stage2: C backend: implement @breakpoint and clean up test harness 2020-12-28 18:43:01 -07:00
Andrew Kelley
37f04d66be stage2: C backend: properly render type of array decls 2020-12-28 18:24:55 -07:00
Andrew Kelley
52056b156b stage2: C backend: pointer cast decl refs if necessary 2020-12-28 17:46:50 -07:00
Andrew Kelley
87c6341b61 stage2: add extern functions
and improve the C backend enough to support Hello World (almost)
2020-12-28 17:15:29 -07:00
Andrew Kelley
2df2f0020f Merge pull request #7498 from FireFox317/stage2-llvm
stage2: add initial impl of LLVM backend in self-hosted compiler
2020-12-28 15:07:21 -08:00
Timon Kruiper
ec3aedffb1 stage2: add initial implementation of func arguments in LLVM backend
The following works:
```
export fn _start() noreturn {
    assert(true);
    exit();
}

fn assert(cond: bool) void {}

fn exit() noreturn {
    unreachable;
}
```
2020-12-28 21:20:49 +01:00
Timon Kruiper
4a32d4f288 stage2: refactor (simplify) code structure of llvm_backend.zig 2020-12-28 21:20:49 +01:00
Timon Kruiper
09cf043efd stage2: add missing asserts and early returns for LLVM backend 2020-12-28 21:20:49 +01:00
Timon Kruiper
6b8d28312c stage2: fix building self-hosted without llvm-backend enabled. 2020-12-28 21:20:49 +01:00
Timon Kruiper
b059bb84b8 stage2: add LLVM codegen windows support to the self-hosted compiler
The following example generates a valid `main.exe`:
`zig build-exe main.zig -fLLVM -target x86_64-windows-gnu --subsystem console`

```
export fn wWinMainCRTStartup() noreturn {
    foo();
    exit();
}

fn foo() void {}

fn exit() noreturn {
    unreachable;
}
```
2020-12-28 21:20:46 +01:00
Timon Kruiper
071417161d stage2: add initial impl of LLVM backend in self-hosted compiler 2020-12-28 21:19:40 +01:00
Timon Kruiper
4a0d64300b stage2: rename llvm.zig to llvm_bindings.zig
Putting functions in this file will create functions like
`llvm.function`, and the compiler thinks these are llvm intrinsics.
2020-12-28 21:15:13 +01:00
Timon Kruiper
c81ae52ee0 stage2: fix compilation of self-hosted compiler with -Denable-llvm 2020-12-28 21:15:13 +01:00
Andrew Kelley
f75d4cbe56 Revert "stage2: add compile log statement (#7191)"
The addition of `addDeclErr` introduced a memory leak at every call
site, and I also would like to push back on having more than 1
compilation error per `Decl`.

This reverts commit 1634d45f1d.
2020-12-28 11:24:53 -07:00
Vincent Rischmann
9c53564af1 fs: fix segfault in Walker.next
`top` might point to invalid memory after a call to self.stack.append
which causes a segfault.

Prevent this by recomputing `top`.

Fixes #7560
2020-12-28 18:14:27 +01:00
Vincent Rischmann
399c428cb0 fs: add a test for the walker
Written like this it triggers the segfault reported in #7560
2020-12-28 18:14:27 +01:00
Isaac Freund
7ed499ec45 std/heap: fix documentation of raw_c_allocator
This is not in fact safe to use with GeneralPurposeAllocator as GPA
requires align(page_size) but raw_c_allocator provides only
@alignOf(std.c.max_align_t).
2020-12-28 16:15:04 +02:00
g-w1
c234761edd stage2: make Alloc(Inferred) have mutabality info (#7570) 2020-12-28 15:42:22 +02:00
LemonBoy
fffb0904f8 stage1: Prevent crash with some lazy pointer types
Make sure the child element is not undefined, let's catch this problem
early on.

Closes #7568
2020-12-28 15:27:31 +02:00
Veikka Tuominen
8aab1e2e8a Merge pull request #7483 from indocomsoft/autohashmap
Make hasUniqueRepresentation false for slices
2020-12-28 01:13:23 +02:00
Veikka Tuominen
3fb0288d87 Merge pull request #7563 from ifreund/alloc-sent-cleanup
std: add test for createNullDelimitedEnvMap(), clean up sentinel handling for argv/environ
2020-12-28 01:08:12 +02:00
frmdstryr
dd86e9d78c Update event loop sendto error to SendToError 2020-12-28 01:00:23 +02:00
Veikka Tuominen
d96f5b38a3 Merge pull request #7556 from Vexu/translate-c
some fixes
2020-12-28 00:55:44 +02:00
Veikka Tuominen
5acfaa35d3 Merge pull request #7557 from g-w1/stage2-hookup-compilerror
stage2: compileError builtin for zig code
2020-12-28 00:54:44 +02:00
Isaac Freund
8000262e07 std: clean up sentinel handling for argv/environ 2020-12-27 14:23:59 +01:00
Isaac Freund
4d1096976a std: add test for createNullDelimitedEnvMap() 2020-12-27 14:23:59 +01:00
Andrew Kelley
4cc4b54d25 std.event.Loop: fix regression with ResetEvent 2020-12-26 19:40:10 -07:00
Andrew Kelley
8fc765387f Merge pull request #7449 from kristoff-it/macos-termios
add termios bits for darwin
2020-12-26 17:13:17 -08:00
Isaac Freund
988ddd1bed std: add c._exit() and use in ChildProcess
This issue with atexit() functions after forking isn't isolated to linux
I'm sure, the proper way to do this when linking libc is to use _exit(2)
2020-12-26 16:51:55 -08:00
Andrew Kelley
e5894221f7 Merge pull request #7553 from ziglang/fix-the-damn-deadlock
Fix the damn deadlock
2020-12-26 16:33:38 -08:00
Andrew Kelley
cb290ed6c9 stage2: Cache deadlock debugging only for safe build modes 2020-12-26 17:33:15 -07:00
Andrew Kelley
3366e4caf3 ci: put Drone CI back to normal
Surely this time all the problems have been fixed
2020-12-26 13:55:38 -07:00
Andrew Kelley
3f9588ca29 std: do not call malloc() between fork() and execv()
We were violating the POSIX standard which resulted in a deadlock on
musl v1.1.24 on aarch64 alpine linux, uncovered with the new ThreadPool
usage in the stage2 compiler.

std.os execv functions that accept an Allocator parameter are removed
because they are footguns. The POSIX standard does not allow calls to
malloc() between fork() and execv() and since it is common to both
(1) call execv() after fork() and (2) use std.heap.c_allocator,
Programmers are encouraged to go through the `std.process` API
instead, causing some dissonance when combined with `std.os` APIs.

I also slapped a big warning message on all the relevant doc comments.
2020-12-26 13:50:26 -07:00
g-w1
af80240678 make compileError use an UnOp since its operand is just a *Inst 2020-12-26 12:01:14 -05:00
g-w1
d6e9862049 add test for @compileError in zig code, not only zir 2020-12-26 11:34:15 -05:00
g-w1
7f512f2236 fix test cases to use str zir inst instead of just a quoted string 2020-12-26 11:22:16 -05:00
g-w1
504c78c022 change zir definition to use *Inst instead of []const u8 2020-12-26 11:13:13 -05:00
Julius Putra Tanu Setiaji
f9506e9155 Handle unions in autoHash 2020-12-26 19:43:15 +08:00
Veikka Tuominen
795770bcb4 stage1: const_values_equal error union, improve remaining "TODO" panics 2020-12-26 13:29:48 +02:00
Veikka Tuominen
50e8c3882a translate-c: demote variadic functions to declarations 2020-12-26 13:02:17 +02:00
Veikka Tuominen
641bf4c46e Merge pull request #7552 from Vexu/stage2-continue
stage2 continue
2020-12-26 12:26:16 +02:00
lithdew
d20174ad88 builder: implement sanitize_thread option 2020-12-26 11:56:50 +02:00
Julius Putra Tanu Setiaji
d9133b9ae0 Also check whether structs contain slices 2020-12-26 12:58:52 +08:00
Julius Putra Tanu Setiaji
1df601d581 Make hasUniqueRepresentation false for slices 2020-12-26 11:57:09 +08:00
Andrew Kelley
ed39ff202b stage2: Cache: fix resource management of the deadlock debug code 2020-12-25 19:02:15 -07:00
Andrew Kelley
c452bb1322 ci: build in Debug mode to help find the deadlock 2020-12-25 18:39:13 -07:00
Andrew Kelley
c7834f274d stage2: Cache: add debug deadlock detection code 2020-12-25 18:38:49 -07:00
g-w1
1634d45f1d stage2: add compile log statement (#7191) 2020-12-26 02:40:49 +02:00
g-w1
939bd52c8a remove '||=' from stage1
It seems depreciated.
2020-12-26 02:39:34 +02:00
Andrew Kelley
864a5442f1 Merge pull request #7542 from g-w1/build-diff-large
remove `git diff` feature from build.zig
2020-12-25 16:39:23 -08:00
Veikka Tuominen
a50759325c stage2: add error for unused labels 2020-12-26 02:36:12 +02:00
Veikka Tuominen
40aad4f47e stage2: break and continue out of loops 2020-12-26 02:26:53 +02:00
g-w1
ec102951cb remove git diff dirty changes feature from build.zig 2020-12-25 17:18:44 -05:00
Sébastien Marie
c99c6c0a68 openbsd: add commonly used libc wrappers for pledge(2) and unveil(2) 2020-12-25 16:43:14 +02:00
Sébastien Marie
bc11528b8b openbsd: define sem_t as optional pointer on opaque {} 2020-12-25 16:20:22 +02:00
Vexu
1780132d7c fix tests 2020-12-25 14:58:14 +02:00
Vexu
0bc82a9070 stage1: validate pointer attributes when coercing anon literals 2020-12-25 14:58:13 +02:00
Vexu
990eccf282 stage1: implement type coercion of pointer to anon list to array/struct/union/slice 2020-12-25 14:57:46 +02:00
Vexu
ed028fd660 stage1: implement type coercion of anon list to array 2020-12-25 14:57:46 +02:00
Evan Haas
830bc41b1f Correctly cast bool to signed int in translate-c
Previously casting a bool to an int would result in the following Zig code:

    @intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(b))));

This is incorrect if `b` is true, since bitcasting a `u1` with the value 1
to an `i1` will result in the value -1. Instead, generate the following code:

    @as(c_int, @boolToInt(b));

Since @boolToInt returns a `u1`, this is only disallowed if the destination
type is one-bit and signed, which can only happen if it's a bitfield
(currently not supported by translate-c)
2020-12-25 14:38:31 +02:00
g-w1
1322a73141 make if the diff too large just default to dirty_diff_too_big as the diff 2020-12-24 18:28:13 -05:00
Andrew Kelley
9f33984119 Merge pull request #7520 from ziglang/tsan
add support for TSAN
2020-12-24 15:17:52 -08:00
Andrew Kelley
6ab9268a90 stage2: re-use compiler runtime libs across opt modes and strip flag
Previously Zig would need to recompile runtime libs if you changed the
values of --strip or -O. Now, unless the `debug_compiler_runtime_libs`
flag is set (which is currently not exposed to the CLI), Zig will always
choose ReleaseFast or ReleaseSmall for compiler runtime libraries.

When the main application chooses ReleaseFast or ReleaseSmall, that
value is propagated to compiler runtime libraries. Otherwise a decision
is made based on the target, which is currently ReleaseSmall for
freestanding WebAssembly and ReleaseFast for everything else.

Ultimately the purpose of this commit is to have Debug and ReleaseSafe
builds of applications still get optimized builds of, e.g. libcxx and
libunwind, as well as to spend less time unnecessarily rebuilding compiler
runtime libraries.
2020-12-24 14:11:58 -07:00
Andrew Kelley
894434988d libunwind: fix compile errors and warnings for 32-bit arm 2020-12-24 13:31:41 -07:00
LemonBoy
e18abab55a stage1: Create a new declaration scope for union enum types
Making the enum type share the scope with the parent union means every
declaration "bleeds" into the enum scope.
Let's mint a fresh empty scope for the enum type.

Thanks to @Vexu for the test case.

Closes #7532
2020-12-24 15:57:12 +02:00
Veikka Tuominen
83646df2cc Merge pull request #7531 from Vexu/orphanage
Move ArrayListSentineled to std lib orphanage
2020-12-24 10:59:37 +02:00
Andrew Kelley
ed26b3204a stage2: tsan forces linking libc 2020-12-24 01:18:48 -07:00
Andrew Kelley
4d8c5dd4be stage1: add tsan LLVM passes when appropriate 2020-12-24 01:18:48 -07:00
Andrew Kelley
a4b134746f zig cc: support both ubsan and tsan at the same time 2020-12-24 01:18:48 -07:00
Andrew Kelley
3002856a7f libunwind: add __gcc_personality_v0 symbol 2020-12-24 01:18:48 -07:00
Andrew Kelley
8219d92987 stage2: fix Cache deadlock and build more of TSAN
* rename is_compiler_rt_or_libc to skip_linker_dependencies
   and set it to `true` for all sub-Compilations. I believe
   this resolves the deadlock we were experiencing on Drone
   CI and on some users' computers. I will remove the CI workaround in
   a follow-up commit.
 * enabling TSAN automatically causes the Compilation to link against
   libc++ even if not requested, because TSAN depends on libc++.
 * add -fno-rtti flags where appropriate when building TSAN objects.
   Thanks Firefox317 for pointing this out.
 * TSAN support: resolve all the undefined symbols. We are still seeing
   a dependency on __gcc_personality_v0 but will resolve this one in a
   follow-up commit.
 * static libs do not try to build libc++ or libc++abi.
2020-12-24 01:18:48 -07:00
Andrew Kelley
42b4a48bc9 WIP start adding support for TSAN 2020-12-24 01:18:47 -07:00
Andrew Kelley
0fd68f49e2 Merge pull request #7519 from ziglang/more-pthreads-integration
More pthreads integration
2020-12-24 00:15:33 -08:00
Andrew Kelley
87e4f7376a Revert "std.valgrind: add helgrind functions"
This reverts commit f2ab9512af.

I did it wrong and didn't end up using these.
2020-12-24 01:14:41 -07:00
Andrew Kelley
c2b1c88953 std: fix compile errors introduced in previous commit 2020-12-23 20:49:38 -07:00
Andrew Kelley
177377b6e3 rework std.ResetEvent, improve std lib Darwin integration
* split std.ResetEvent into:
   - ResetEvent - requires init() at runtime and it can fail. Also
     requires deinit().
   - StaticResetEvent - can be statically initialized and requires no
     deinitialization. Initialization cannot fail.
 * the POSIX sem_t implementation can in fact fail on initialization
   because it is allowed to be implemented as a file descriptor.
 * Completely define, clarify, and explain in detail the semantics of
   these APIs. Remove the `isSet` function.
 * `ResetEvent.timedWait` returns an enum instead of a possible error.
 * `ResetEvent.init` takes a pointer to the ResetEvent instead of
   returning a copy.
 * On Darwin, `ResetEvent` is implemented using Grand Central Dispatch,
   which is exposed by libSystem.

stage2 changes:
 * ThreadPool: use a single, pre-initialized `ResetEvent` per worker.
 * WaitGroup: now requires init() and deinit() and init() can fail.
   - Add a `reset` function.
   - Compilation initializes one for the work queue in creation and
     re-uses it for every update.
   - Rename `stop` to `finish`.
   - Simplify the implementation based on the usage pattern.
2020-12-23 16:57:18 -08:00
frmdstryr
577b57784a Return encoded slice from base64 encode 2020-12-24 01:27:21 +02:00
Veikka Tuominen
7154882423 Merge pull request #7447 from LemonBoy/fix-7445
std: non-byte-multiple sized integers have no definite representation
2020-12-24 00:25:52 +02:00
Veikka Tuominen
e79acc24d3 std: clenup, fixes, fmt 2020-12-24 00:23:29 +02:00
Andrew Kelley
5377b7fb97 put the drone CI workaround back in
this branch does not solve it
2020-12-23 13:36:21 -08:00
Andrew Kelley
f4d82f0ad6 std.Progress: work around time going backwards 2020-12-23 13:36:21 -08:00
Andrew Kelley
485ec0884f restore std.ResetEvent.isSet functionality 2020-12-23 13:36:21 -08:00
Andrew Kelley
a368c0d099 std: add Darwin and FreeBSD sem_t bits 2020-12-23 13:36:21 -08:00
Andrew Kelley
b2e1bce240 minor code readability changes 2020-12-23 13:36:21 -08:00
Andrew Kelley
f2ab9512af std.valgrind: add helgrind functions 2020-12-23 13:36:21 -08:00
Andrew Kelley
78ab1f609a apply kprotty's WaitGroup fix 2020-12-23 13:36:21 -08:00
Andrew Kelley
19459840fe std.ResetEvent: pthreads sem_t cannot be statically initialized
because it is allowed for the implementation to use a file descriptor,
which would require making a syscall at runtime.
2020-12-23 13:36:21 -08:00
Andrew Kelley
028af97df4 std.ResetEvent: use sem_t when linking against pthreads 2020-12-23 13:36:21 -08:00
Andrew Kelley
829c00a77f kprotty ThreadPool and WaitGroup patch 2020-12-23 13:36:21 -08:00
Andrew Kelley
4eb4d26fa1 std.Mutex: integrate with pthreads
When using pthreads for threading, std.Mutex uses pthread_mutex_t as the
implementation. This integrates better with tooling.
2020-12-23 13:36:21 -08:00
Sébastien Marie
6e2622661c openbsd: implement segfault handling on openbsd x86_64 2020-12-23 20:47:06 +02:00
Koakuma
588e828759 float_*_ieee597: only swap bytes when targeting different endianness than native
float_*_ieee597 functions should fill the buffer with the target endianness,
instead of always filling it in LE ordering.
2020-12-23 20:22:43 +02:00
xackus
1d3ceac770 stage1: LLVMSetModuleInlineAsm is deprecated 2020-12-23 20:21:47 +02:00
xackus
0a6ba6f666 gdb pretty printers for slices and optionals 2020-12-23 20:21:47 +02:00
Loris Cro
9bb0da6100 added comments, removed useless comptime keywords 2020-12-23 17:28:59 +01:00
Loris Cro
8c00c7473c add termios bits for darwin 2020-12-23 17:28:59 +01:00
Eleanor Bartle
49ca51fc3a Clarify condusing wording regarding % and /
Previous wording made it seem like any signed or floating-point value would be allowed at comptime, whereas negative values do not work with `%`, and negative integers do not work with `/`.
2020-12-23 17:05:37 +02:00
Veikka Tuominen
e5aab62228 move ArrayListSentineled to std lib orphanage 2020-12-23 16:24:22 +02:00
Alex Cameron
ca282184ae Implement parsing for multi-arg Clang options. 2020-12-23 15:03:11 +02:00
g-w1
51a904677c update depreciated code (#7502)
* `zig env`:

* fix depreciated interface, update outStream -> writer
* make code more readable by updating `anytype` -> `std.fs.File.Writer`
2020-12-23 13:01:29 +02:00
xackus
4128eea00c std.c: add fmemopen 2020-12-23 12:58:21 +02:00
Veikka Tuominen
ce7dcf2294 Merge pull request #7507 from joachimschmidt557/stage2-arm
stage2 ARM: implement basic binary bitwise operations
2020-12-23 12:17:40 +02:00
daurnimator
53a8e73205 Add sincosf function (#7267)
* Add sincosf function

* also add sincos

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2020-12-23 11:18:15 +02:00
Andreas Linz
7e63f7ad03 Truncate user and group ids for 64 bit Linux systems (#7466)
* Truncate user and group ids

Calls to `getuid`, `getgid` and their `eid` variants fail to compile on
64bit Linux systems because the return value of the syscall is of
`usize` and needs to be truncated to fit the size of `uid_t` that is 32
bit.

Thanks to @FireFox317 for figuring this out in Zig's Discord channel!

* Add a regression test for user and group ids

* Replace @truncate with @intCast

This should be safe because `uid_t` will be 32-bit.

* Add missing import for getauxval

* Add missing package names

* Revert "Add missing import for getauxval"

This reverts commit 38f93dc89effdf657f2b81a56b96527ce4083f52.

* Skip user and group test if builtin.link_libc
2020-12-23 11:16:27 +02:00
Sébastien Marie
4420dabdf5 openbsd: fix siginfo_t struct definition
`_proc` struct part contains an union for kill/cld parts.

see [siginfo_t](77c6c13150/sys/sys/siginfo.h (L132))
2020-12-23 11:08:55 +02:00
Alex Cameron
60020fd545 Enable segfault handling on FreeBSD. 2020-12-23 11:02:05 +02:00
Matt Sicker
d9fe7ea815 Fix Gimli hash on 16n byte inputs 2020-12-23 10:59:14 +02:00
Matthew Knight
55b998c98d Add c_longdouble mapping for bpf (#7504) 2020-12-23 01:33:43 +02:00
tgschultz
ab6183e119 Added std.io.counting_reader 2020-12-23 01:27:12 +02:00
g-w1
cb3198af2a stage2: @TypeOf (#7475)
* stage2: add @TypeOf

* stage2: discriminate on what type of @builtinCall in nodeMayNeedMemoryLocation

* merge upstream into my stash

* add type equality to make easier to test and defer free the types

* remove addDeclErr, I dont know why I added it, its from a different branch that im working on

* add tests

* update error message to match stage1

* use ComptimeStringMap and update which nodes don't need memory from vexu's suggestions

* fix typo

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

* make @TypeOf(single_arg) go to .typeof zir inst and add test for that

* unioninit, as, reduce change mayneedmemorylocation

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2020-12-23 01:26:36 +02:00
g-w1
ea18f894f5 Peer type resolution with unsigned ints and larger signed ints 2020-12-23 00:05:42 +02:00
Veikka Tuominen
03113d9246 Merge pull request #7111 from tetsuo-cpp/emit-h
Implement emit-h
2020-12-23 00:01:22 +02:00
Veikka Tuominen
ba2f2e1393 Merge pull request #7476 from ifreund/pkgs
stage2: free Package resources, print package path on --pkg-begin failure
2020-12-23 00:00:37 +02:00
Evan Haas
ccdb81fb31 Improve handling of C compiler intrinsics in translate-c
C compiler intrinsics can only appear as part of a function call. When called
they are implicitly cast to a function pointer; treat this as a non-null
pointer so that it emits as a regular Zig function call.

Put `pub usingnamespace @import("std").c.builtins;` at the top of translated
C files so that they will have access to builtin functions defined there.

Fixes #6707
2020-12-22 23:59:30 +02:00
luna
6a75cfd0f6 cast sendto to SendError inside send (#7481)
* cast sendto to SendError inside send

* remove WouldBlock from SendToError

* add missing ENOTCONN mapping

* remove SystemResources duplicate

* move NetworkUnreachable to SendError

* add NetworkSubsystemFailed to SendError

* Use zig's implicit error set casting

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-12-22 16:47:11 -05:00
Alex Cameron
9849e894d5 Add emit_h path to compilation hash. 2020-12-23 01:14:35 +11:00
Alex Cameron
0771aac48b Don't use emit-h in test cases for other backends. 2020-12-23 01:14:35 +11:00
Alex Cameron
e834d0369a Make sure emit-h is off by default. 2020-12-23 01:14:35 +11:00
Alex Cameron
58bd6c5f8e Add tests for emit-h functionality. 2020-12-23 01:14:35 +11:00
Noam Preil
8d6066e09c Fix a dumb 2020-12-23 01:14:35 +11:00
Noam Preil
8538053940 Add header test harness 2020-12-23 01:14:35 +11:00
Noam Preil
ac33b10b5e CBE: Improve formatting 2020-12-23 01:14:35 +11:00
Noam Preil
37438dd789 CBE: add support for bool,u32 2020-12-23 01:14:35 +11:00
Noam Preil
15a148db01 Fix memory leak 2020-12-23 01:14:35 +11:00
Alex Cameron
c87da2f45a Remove redundant emit_h member in Compilation struct. 2020-12-23 01:14:35 +11:00
Alex Cameron
aba273d731 Enable emit-h by default for obj and lib compilation. 2020-12-23 01:14:35 +11:00
Alex Cameron
40f0275e7c Implement emit-h 2020-12-23 01:14:35 +11:00
Jakub Konka
43dbe86226 Merge pull request #7516 from kubkon/macho-better-space-alloc
macho: space preallocation, and various cleanups and fixes
2020-12-22 14:23:55 +01:00
Jakub Konka
34663abc90 macho: pad out LINKEDIT upto specified filesize 2020-12-22 10:57:58 +01:00
Jakub Konka
f106a46fd2 macho: enable binding and lazy binding info writes 2020-12-21 23:16:00 +01:00
Jakub Konka
3f21f9155f macho: write only bits that changed
Refactor use of `log` to not include an additional newline char.
2020-12-21 19:59:40 +01:00
joachimschmidt557
45a88be573 stage2 ARM: add test cases for binary bitwise operations 2020-12-21 19:24:23 +01:00
joachimschmidt557
82236a5029 stage2 ARM: implement basic binary bitwise operations 2020-12-21 19:24:21 +01:00
Jakub Konka
de5421a0a6 macho: deduplicate symbol table relocation codepath 2020-12-21 18:31:26 +01:00
Jakub Konka
a1b3606f0e macho: dynamically preallocate space for LINKEDIT sections as well 2020-12-21 17:03:55 +01:00
Vexu
286077fec8 stage1: add missing error check on inferred struct field ptr 2020-12-21 12:40:51 +02:00
Andrew Kelley
4918605176 Merge pull request #7462 from ziglang/parallel-c-objects
Introduce a ThreadPool and parallel execution of some of the compilation work items
2020-12-20 21:19:05 -05:00
Andrew Kelley
1d94a68936 add an option to compile zig in single-threaded mode
And enable it for Drone CI. I hate to do this, but I need to make
progress on other fronts.
2020-12-20 15:37:58 -07:00
Andrew Kelley
10d30838d1 update WaitGroup to yet another version 2020-12-20 15:08:59 -07:00
Andrew Kelley
fbcffe9d5d std.Progress: fix atomic ordering semantics
thx king protty
2020-12-20 15:08:59 -07:00
Andrew Kelley
4e621d4260 workaround for std lib AutoResetEvent bug 2020-12-20 15:08:59 -07:00
Andrew Kelley
e00b6db2aa update stage2 test harness to new std.Progress API 2020-12-20 15:08:59 -07:00
Andrew Kelley
aa6ef10cc6 std.Progress: make the API thread-safe
We generally get away with atomic primitives, however a lock is required
around the refresh function since it traverses the Node graph, and we
need to be sure no references to Nodes remain after end() is called.
2020-12-20 15:08:59 -07:00
Andrew Kelley
b2f8631a3c ThreadPool: delete dead code
If this errdefer did get run it would constitute a race condition. So I
deleted the dead code for clarity.
2020-12-20 15:08:59 -07:00
Andrew Kelley
32fd637e57 stage2: replace WaitGroup with a trivially auditable one 2020-12-20 15:08:59 -07:00
Andrew Kelley
0d1cd0d482 use kprotty's ThreadPool implementation (v5) 2020-12-20 15:08:59 -07:00
Andrew Kelley
01d33855c7 stage2: protect mutable state from data races in updateCObject 2020-12-20 15:08:59 -07:00
Andrew Kelley
4964bb3282 std: move serialization to the std lib orphanage
std-lib-orphanage commit 633792839f6f838fa864cde6af015413ee713404
2020-12-20 15:08:06 -07:00
LemonBoy
84549b4267 stage1: Fix for generic fn monomorphization
Don't use the instantiation argument types to build the function
parameter array.

f416535768 worked around the problem, this
commit solves it.
2020-12-19 19:45:48 -05:00
Vincent Rischmann
dd7b816d98 builder: implement float options 2020-12-20 01:24:59 +02:00
Jakub Konka
3f7dbde92a macho: bring back allocatedSize function 2020-12-19 23:51:39 +01:00
Jakub Konka
6712575e04 macho: preallocate space for linkedit hidden sections; 2020-12-19 23:37:21 +01:00
Jakub Konka
ca1d03fe77 macho: fix findFreeSpace start value 2020-12-19 19:44:13 +01:00
Jakub Konka
c89f4781bd macho: add missing dirty markers 2020-12-19 12:19:20 +01:00
Jakub Konka
f32681033d macho: auto-coerce to slice 2020-12-19 12:19:10 +01:00
Jakub Konka
99578e828b macho: move findFreeSpace back to MachO struct
However, adding a twist where `findFreeSpace` accepts a `SegmentCommand`
as argument meaning we want to look for free space specifically within
that segment and nowhere else.
2020-12-19 12:19:00 +01:00
Jakub Konka
6a021d845a macho: find free space even for __text section 2020-12-19 12:18:49 +01:00
Jakub Konka
f33b644c4f macho: redo how we allocate within a segment
Firstly, we preallocate segments offset and sizes, and then
when adding sections, we find the free space within each segment.
Currently, this applies to any segment that is not __LINKEDIT
segment since this requires special treatment.
2020-12-19 12:18:35 +01:00
Jakub Konka
b090451646 Merge pull request #7318 from kubkon/cc-macho
stage1: cross compile to x86_64 and arm64 macOS from anywhere with LLVM
2020-12-19 12:13:03 +01:00
Jakub Konka
3f81ddb735 macho: address review comments 2020-12-19 09:59:38 +01:00
Andrew Kelley
506af7e52e Merge pull request #7482 from ziglang/tlcsprng
std: introduce a thread-local CSPRNG for general use
2020-12-18 23:57:46 -05:00
Andrew Kelley
f416535768 work around compiler bug regarding generic function slice alignment
See #7495
2020-12-18 18:30:06 -07:00
Andrew Kelley
53987c932c std.crypto.random: introduce fork safety
Everybody gets what they want!

 * AT_RANDOM is completely ignored.
 * On Linux, MADV_WIPEONFORK is used to provide fork safety.
 * On pthread systems, `pthread_atfork` is used to provide fork safety.
 * For systems that do not have the capability to provide fork safety,
   the implementation falls back to calling getrandom() every time.
 * If madvise is unavailable or returns an error, or pthread_atfork
   fails for whatever reason, it falls back to calling getrandom() every
   time.
 * Applications may choose to opt-out of fork safety.
 * Applications may choose to opt-in to unconditionally calling
   getrandom() for every call to std.crypto.random.fillFn.
 * Added `std.meta.globalOption`.
 * Added `std.os.madvise` and related bits.
 * Bumped up the size of the main thread TLS buffer. See the comment
   there for justification.
 * Simpler hot path in TLS initialization.
2020-12-18 15:54:01 -07:00
Andrew Kelley
2b8dcc76eb take advantage of std.os.linux.getauxval 2020-12-18 12:22:46 -07:00
Andrew Kelley
d9368d7012 update test-stack-traces because start.zig updated 2020-12-18 12:22:46 -07:00
Andrew Kelley
2e4b409f31 std: tlcsprng: cleanups & improvements
* get rid of the pointless fences
 * make seed_len 16 instead of 32, which is accurate since it was
   already padding the rest anyway; now we do 1 pad instead of 2.
 * secureZero to clear the AT_RANDOM auxval
 * add a flag root source files can use to disable the start code. This
   is in case people want to opt out of the initialization when they
   don't depend on it.
2020-12-18 12:22:46 -07:00
Andrew Kelley
228a0937a2 memory fences to make sure TLS init happens 2020-12-18 12:22:46 -07:00
Andrew Kelley
7dab3ae135 update guess number standalone test 2020-12-18 12:22:46 -07:00
Andrew Kelley
4dcd1e6059 start code: overwrite AT_RANDOM after we use it 2020-12-18 12:22:46 -07:00
Andrew Kelley
013efaf139 std: introduce a thread-local CSPRNG for general use
std.crypto.random

* cross platform, even freestanding
* can't fail. on initialization for some systems requires calling
  os.getrandom(), in which case there are rare but theoretically
  possible errors. The code panics in these cases, however the
  application may choose to override the default seed function and then
  handle the failure another way.
* thread-safe
* supports the full Random interface
* cryptographically secure
* no syscall required to initialize on Linux (AT_RANDOM)
* calls arc4random on systems that support it

`std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`.

I moved some of the Random implementations into their own files in the
interest of organization.

stage2 no longer requires passing a RNG; instead it uses this API.

Closes #6704
2020-12-18 12:22:46 -07:00
LemonBoy
ce65533985 std: Properly fix the TLS alignment problem
ad05509 introduced a fix for the wrong problem, the logic to align the
start of main_thread_tls_buffer was already there but was flawed.

Fix it for good and avoid wasting too many bytes for alignment purposes.
2020-12-18 14:22:30 -05:00
Andrew Kelley
ad05509930 std: align(16) main_thread_tls_buffer
Before this change, thread local variables were landmines if LLVM
decided to optimize any writes to them using vector instructions.
2020-12-17 22:58:56 -07:00
Alexandros Naskos
16144a7a37 Add EV_ERROR to FreeBSD bits 2020-12-17 22:58:05 +02:00
Isaac Freund
fa09c3a5e7 stage2: print package path on --pkg-begin failure
This makes it much easier for the user to figure out what has gone wrong
than dumping an error return trace.
2020-12-17 20:03:15 +01:00
Isaac Freund
c102eb83e6 stage2: free Package resources
Without this commit we leak file descriptors and memory
2020-12-17 19:32:40 +01:00
Tau
9b86dde7b9 Add baudrate constants
This adds the missing baudrate constants for linux where I've used them
directly.
2020-12-17 19:17:10 +02:00
Luuk de Gram
d73f46b57c Fix StackFallbackAllocator 2020-12-17 19:09:29 +02:00
Josh Holland
e93cb22541 Improve documentation for string slices.
Closes #7454.
2020-12-17 19:01:13 +02:00
Dmitry Atamanov
e16997a66c Add process_madvise to Linux syscalls (#7450) 2020-12-17 18:58:09 +02:00
LemonBoy
135f4791e5 std: Don't hash undefined bits
auto_hash must be extra careful when hashing integers whose bit size is
not a multiple of 8 as, when reinterpreted with mem.asBytes, may contain
undefined non-zero bits too.
2020-12-17 12:00:48 +01:00
Alexandros Naskos
85cc3f24a0 Only check for evented mode in windows.OpenFile when in async mode 2020-12-17 11:08:21 +02:00
Jakub Konka
b42ef0e6ea macho: refactor calculating LEB128 sizes 2020-12-17 10:04:53 +01:00
Jakub Konka
3e9e79378d macho: deduplicate libc headers between macos arch 2020-12-17 10:04:53 +01:00
Jakub Konka
2d5d661703 macho: no need to parse symbol/string tables 2020-12-17 10:04:53 +01:00
Jakub Konka
ae535111a4 macho: cleanup (lazy) binding info tables 2020-12-17 10:04:53 +01:00
Jakub Konka
5e913c9c2c macho: move (lazy)binding tables into imports module 2020-12-17 10:04:53 +01:00
Jakub Konka
46b2a08d06 macho: parse binding info into a table of entries 2020-12-17 10:04:53 +01:00
Jakub Konka
77e545892e macho: do not error out on unknown load commands
Also, do not try to fixup missing libSystem for dylibs.
2020-12-17 10:04:53 +01:00
Jakub Konka
b099fdff93 macho: parse symbol and string tables 2020-12-17 10:04:53 +01:00
Jakub Konka
f5a0b9315b macho: calculate next available dylib ordinal 2020-12-17 10:04:53 +01:00
Jakub Konka
cc2592969d macho: clean up formatting 2020-12-17 10:04:53 +01:00
Jakub Konka
3971522fee macos: add unfiltered aarch64 libc headers 2020-12-17 10:04:53 +01:00
Jakub Konka
2e7883c597 lld+macho: lld xcomp to x86_64 macos now works 2020-12-17 10:04:53 +01:00
Jakub Konka
eb528a9cbc lld+macho: add missing LC_LOAD_DYLIB cmd 2020-12-17 10:04:53 +01:00
Andrew Kelley
6dfe9cc83e zig cc: default to a.exe on windows
This matches Clang. Thanks to Abner Coimbre for pointing this out.
2020-12-16 21:37:15 -07:00
Andrew Kelley
8975fa5b38 stage2: add test_evented_io to cache hash 2020-12-16 19:22:48 -07:00
Andrew Kelley
8f1408578c update the CPU target features and models
Rather than directly pasting the output from the
target-details-generator tool, we have to look at the diff line by line
and decide how to incorporate the changes.

The baseline abstraction is something that Zig provides.

The changes to x86 appear to be incorrect. After LLVM commit
3ad09fd03c51823aeb0bcbd7898aada33e9228d6 the CPU features are stored in
a different data layout in their tables, and so we need to update the
target details extraction tool to match.
2020-12-16 17:25:48 -07:00
Andrew Kelley
bbb3403b5d stage1: apply LLVM ssp attributes globally
instead of per-function. Otherwise LLVM asserts with:
"stack protected callee but caller requested no stack protector"
2020-12-16 15:45:32 -07:00
Andrew Kelley
da54e7cd00 update clang.zig and translate-c for the clang C++ API changes 2020-12-16 14:29:27 -07:00
Andrew Kelley
755c558026 Merge remote-tracking branch 'origin/master' into llvm12 2020-12-16 14:24:36 -07:00
Jakub Konka
f59069f3d0 Update clang options
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 18:38:11 +01:00
Jakub Konka
4b62f1bd93 Update changes due to different CPU feature sets
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 18:25:25 +01:00
Jakub Konka
1c40a4df09 Update zig_llvm.cpp and other bits
Include updates to corresponding zig sources

llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 18:13:58 +01:00
Jakub Konka
6f3ed2f71f Update target details
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
zig-llvm-target-details-generator commit
4299674ecabeb668b0d84285cd1b41a652a391b1
2020-12-16 18:13:52 +01:00
Jakub Konka
38bf94280b Update libcxxabi
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 12:19:09 +01:00
Jakub Konka
f9a11fbfaf Update libcxx
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 12:18:55 +01:00
Jakub Konka
1e66ac5755 Update libunwind
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 12:18:43 +01:00
Jakub Konka
8612dac225 Update clang headers
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 12:18:33 +01:00
Jakub Konka
83ff94406e Update clang drivers
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 12:18:14 +01:00
data-man
d877eb0e8d Fix typo in math.order 2020-12-16 12:14:44 +02:00
Veikka Tuominen
d3a57b96a9 translate-c: detect parenthesized string literals 2020-12-16 12:13:23 +02:00
Jakub Konka
9c2d8056ce Update LLVM version numbers in CMake 2020-12-16 09:37:32 +01:00
Alexandros Naskos
aa6654a4b3 Fix compilation for MacOS 2020-12-16 00:47:41 +02:00
Andrew Kelley
b3c1ced2c3 Merge pull request #7431 from LemonBoy/fix-7426
stage1: Fix crash in can_mutate_comptime_var_state
2020-12-15 15:07:49 -05:00
Christian Wesselhoeft
b3f4802aa0 mingw-w64: add .def files for xaudio2_8 2020-12-15 15:00:39 -05:00
luna
0c33624a45 create SendToError (#7417)
* add SendToError

* remove error catch

* add missing SendToError entries

* add mappings to new errors for posix

* map windows sendto() errors
2020-12-15 14:56:42 -05:00
LemonBoy
5f7352b5b5 stage2: Add -include libc-symbols.h when building crtn.S
This -include is added for nearly every file in glibc's makefiles.
2020-12-15 14:53:46 -05:00
Sébastien Marie
96e3222796 openbsd: crt0.o file is different when build static or dynamic mode
it is a first step for support static *and* dynamic mode for openbsd
2020-12-15 14:53:23 -05:00
Sébastien Marie
8bf5a3a5c1 openbsd: correct few structs
- addrinfo: addr and canonname are switched (wrong layout)
- addrinfo, Flock, msghdr struct: use proper c_xxx type instead of fixed size. it should help using struct on all architectures supported by openbsd
2020-12-15 14:49:42 -05:00
Sebastien Marie
7cd6c25c8f openbsd: link with required system libraries (#7380)
* openbsd: use -lpthread when linking

and while compiling zig stage2, use c++ and c++abi too
2020-12-15 14:45:48 -05:00
LemonBoy
8a2ab60fca stage1: Don't skip steps when analyzing union types
Don't cut any corner and properly run the type trough every single step
even though it has no fields (or, better, the sum of the size of all its
fields is zero).

Fix the logic to consider an explicit non-zero-sized tag enough to treat
the type as sized.

Closes #7451
2020-12-15 14:40:21 -05:00
LemonBoy
9e5869262a std: Bool has no definite representation too
The padding bits are undefined.
2020-12-14 20:06:46 +01:00
LemonBoy
44556bfebe std: non-byte-multiple sized integers have no definite representation
Closes #7445
2020-12-14 20:06:46 +01:00
Alexandros Naskos
da007f318b Implement std.fs.Watch on Windows
Use unmanaged containers in std.fs.Watch
2020-12-14 21:03:50 +02:00
Alexandros Naskos
5112ab8233 Fixed std.fs.Watch implementation on Linux
Added .Deleted event to std.fs.Watch on Linux
2020-12-14 21:00:54 +02:00
LemonBoy
bbfa3550a0 Add a test case
Co-authored-with: Vexu <git@vexu.eu>
2020-12-14 17:39:35 +01:00
data-man
8591f30b0d Add missed Linux syscalls 2020-12-14 18:22:28 +02:00
Jakub Konka
91e8be385c Merge pull request #7411 from LemonBoy/sigaction-smoke
std: Improve sigaction interface
2020-12-14 17:16:55 +01:00
LemonBoy
a471a57560 std: Fix formatting of type values
Closes #7429
2020-12-13 23:21:23 -05:00
Isaac Freund
343249efd8 stage2: use %type not @type for libc stubs
Apparently ARM uses @ for comments. Everything seems to accept % here
though.
2020-12-13 23:19:23 -05:00
Andrew Kelley
481ce7361e bump version to 0.7.0 => 0.7.1
The official tag is in the 0.7.x branch.
2020-12-13 12:53:31 -07:00
LemonBoy
d9e9390550 Fix compilation error on OpenBSD 2020-12-13 20:36:47 +01:00
LemonBoy
bb72b0e800 Fix compilation error on FreeBSD 2020-12-13 20:36:34 +01:00
LemonBoy
561565fa81 stage1: Fix crash in can_mutate_comptime_var_state
No lazy value can mutate global state, no need to resolve them.

Closes #7426
2020-12-13 20:27:04 +01:00
LemonBoy
97ba3d9a66 std: Drop struct prefixes in FreeBSD siginfo
I'm not sure this prefix-free style is a good idea, but let's roll with
it for the moment.
2020-12-13 19:45:11 +01:00
Alex Cameron
7515922907 Fix Sigaction struct on FreeBSD. 2020-12-13 19:37:13 +01:00
LemonBoy
3a759fdb17 Disable sigaction test on i386 because of #7427 2020-12-13 19:35:40 +01:00
LemonBoy
3375a580be std: Update more siginfo bits for BSDs 2020-12-13 19:28:38 +01:00
LemonBoy
fc70db5ab5 std: Fixes for siginfo test on macos
Xnu's sigaction() only supports fetching a limited set of sa_flags, test
SA_SIGINFO instead of SA_RESETHAND as that's supported everywhere.

Add another check to make sure SA_RESETHAND works.

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2020-12-13 19:17:04 +01:00
Andrew Kelley
4fd27719b4 Merge pull request #7406 from ifreund/dyn-musl2
stage2: support dynamically linking musl libc
2020-12-12 18:46:07 -05:00
Isaac Freund
1d8f33ca98 stage2: link musl dynamically by default if native
If targeting the native OS and the system libc is musl, link against it
dynamically by default.
2020-12-13 00:40:35 +01:00
Isaac Freund
078a64f8d9 std.CrossTarget: add isNativeAbi() 2020-12-13 00:40:35 +01:00
Isaac Freund
307d98dc35 stage2: support dynamically linking musl libc 2020-12-13 00:40:35 +01:00
Andrew Kelley
6b7ddfbafe glibc: do not provide -lcrypt
glibc is dropping this functionality moving forward.

This is a partial revert of commit
97c0e1cc41
2020-12-12 12:42:33 -07:00
LemonBoy
629cc6cf28 std: Further siginfo refinements
* Define siginfo and sigaction for Darwin
* Define sigaction/handler union for maximum libc compatibility
* Minor correction to some type definitions
2020-12-12 16:44:10 +01:00
LemonBoy
1d9b28403a std: Correct check in signal test
Ooops.
2020-12-12 15:34:26 +01:00
LemonBoy
beae3cea17 std: Improve sigaction interface
Add a smoke test to prevent regressions.
2020-12-12 13:57:25 +01:00
Andrew Kelley
d569e37cb5 std.fs.path.extension: different behavior for ending dot
extension("a.") now returns "." instead of "".

This matches both Python and Node.js standard library behavior as well
as my personal opinion on how this function should be defined.

Apologies for missing this in the code review.
2020-12-11 18:20:57 -07:00
Andrew Kelley
6ab5bebed1 stage2: proper file extension stripping
Previously it used mem.split on "." and took the first iterated item.
Now it uses fs.path.extension and strips off that number of bytes.

Closes #7404
2020-12-11 17:42:13 -07:00
Andrew Kelley
52bc1442d6 std.fs.path.extension: add additional API guarantee
Added:

The returned slice is guaranteed to have its pointer
within the start and end pointer address range of `path`,
even if it is length zero.
2020-12-11 17:41:34 -07:00
Andrew Kelley
1852dc7e13 Merge pull request #7098 from MasterQ32/std.fs.path.extension
Implements std.fs.path.extension
2020-12-11 19:32:21 -05:00
Andrew Kelley
c4f53d1ef6 fix deadlock with build-exe on an object for windows
The steps to repro this issue are:

zig build-obj hello.zig -target x86_64-windows-msvc
zig build-exe hello.obj -target x86_64-windows-msvc --subsystem console
-lkernel32 -lntdll

What was happening is that the main Compilation added a work item to
produce kernel32.lib. Then it added a sub-Compilation to build zig's
libc, which ended up calling a function with extern "kernel32", which
caused the sub-Compilation to also try to produce kernel32.lib. The main
Compilation and sub-Compilation do not coordinate about the set of
import libraries that they will be trying to build, so this caused a
deadlock.

This commit solves the problem by disabling the extern "foo" feature
from working when building compiler_rt or libc. Zig's linker code is now
responsible for putting the appropriate import libs on the linker line,
if any for compiler_rt and libc.

Related: #5825
2020-12-11 18:34:34 -05:00
Andrew Kelley
5b56f4e48a mingw-w64: add .def files for xinput1_4
closes #7398
2020-12-11 11:12:23 -07:00
Andrew Kelley
a1d3886ff0 mingw-w64: add support for -lwldap32
closes #7395
2020-12-11 00:50:28 -07:00
LemonBoy
fa6449dac0 zig fmt: Fix alignment of initializer elements
Resetting `column_counter` is not needed as the effective column number
is calculated by taking that value modulo `row_size`.

Closes #7289
2020-12-11 02:34:44 -05:00
Andrew Kelley
64a590a311 stage2: detect redundant C/C++ source files
Cache exposes BinDigest.

Compilation gains a set of a BinDigest for every C/C++ source file. We
detect when the same source/flags have already been added and emit a
compile error. This prevents a deadlock in the caching system.

Closes #7308
2020-12-11 02:33:09 -05:00
Andrew Kelley
0d00938016 update contributing docs 2020-12-10 20:17:07 -07:00
Andrew Kelley
f7d600675c CLI: improved local cache directory logic
Previously, when choosing the local cache directory, if there was no
root source file, an explicitly chosen path, or other clues, zig would
choose cwd + zig-cache/ as the local cache directory.

This can be problematic if Zig is invoked with the CWD set to a
read-only directory, or a directory unrelated to the actual source files
being compiled. In the real world, we see this when using `zig cc` with
CGo, which for some reason changes the current working directory to the
read-only go standard library path before running the C compiler.

This commit conservatively chooses to use the global cache directory
as the local cache directory when there is no other reasonable choice,
and no longer will rely on the cwd path to choose a local cache directory.

As a reminder, the --cache-dir CLI flag and ZIG_LOCAL_CACHE_DIR
environment variable are available for overriding the decision. For the
zig build system, it will always choose the directory that build.zig is
+ zig-cache/.

Closes #7342
2020-12-10 16:17:02 -07:00
antlilja
26399b5249 Added global-cache argument to build system + removed extra args.
* Field global_cache_root was added to Builder struct along with
mandatory argument for build_runner.zig. Logic for using the custom
global cache was also added.

* The arguments --cache-dir and --global-cache-dir are no longer passed
directly through to build_runner.zig and are instead only passed through the
mandatory cache_root and global_cache_root arguments.
2020-12-10 18:06:19 -05:00
Andrew Kelley
a3de27ef3b Merge pull request #7372 from LemonBoy/atomicint
Improvements for std.atomic.{Int,Bool}
2020-12-10 16:13:36 -05:00
Evan Haas
55cac65f95 Support casting enums to all int types.
In C, enums are represented as signed integers, so casting from an enum to an integer
should use the "cast integer to integer" translation code path. Previously it used the
"cast enum to generic non-enum" code path, because enums were not being treated as integers.
Ultimately this can produce zig code that fails to compile if the destination type does not
support the full range of enum values (e.g. translated C code that casts an enum value to an
unsigned integer would fail to compile since enums are signed integers, and unsigned integers
cannot represent the full range of values that signed ones can).

One interesting thing that came up during testing is that the implicit enum-to-int cast that
occurs when an enum is used in a boolean expression was parsed as an (int) by some versions of
the zig compiler, and an (unsigned int) cast by others. Specifically, the following code:

```c
	enum Foo {Bar, Baz};
	// ...
	enum Foo foo = Bar;
	if (0 || foo) {
		// do something
	}
```

When tested on MacOS, Linux, and Windows using a compiler built from the Windows Zig Compiler
Dev Kit, the above code would emit a cast to c_uint:

`if (false or (@bitCast(c_uint, @enumToInt(foo)) != 0)) {}`

However when tested on Windows with a Zig compiler built using MSVC, it produces:

`if (false or (@bitCast(c_int, @enumToInt(foo)) != 0)) {}`

In this particular case I don't think it matters, since a c_int and c_uint will have the same
representation for zero, but I'm not sure if this is ultimately the result of
implementation-defined behavior or something else.

Because of this, I added explicit casts in the `translate_c.zig` tests, to ensure that the
emitted zig source exactly matches across platforms. I also added a behavior test in
`run_translated_c.zig` that uses the old implicit casts from `translate_c.zig` to ensure
that the emitted Zig code behaves the same as the C code regardless of what cast is used.
2020-12-10 15:47:56 -05:00
Andrew Kelley
5a5389128d Merge pull request #7369 from jorangreef/io_uring_timeout
Add io_uring TIMEOUT and TIMEOUT_REMOVE operations:
2020-12-10 15:45:38 -05:00
Vexu
afc21a2f1c make std.json.unescapeString pub 2020-12-10 21:19:41 +02:00
Vexu
73016212a3 translate-c: support referencing c containers in macros 2020-12-10 14:45:48 +02:00
Joran Dirk Greef
b5a9fd9f98 Skip timeout_remove test where not supported by the kernel 2020-12-10 11:34:20 +02:00
LemonBoy
88e3a7d6dc std: Fix misuse of atomic.Int 2020-12-10 09:23:48 +01:00
LemonBoy
5e91cc2fe3 std: Validate the atomic ordering parameter in atomic.Int 2020-12-10 09:23:48 +01:00
LemonBoy
5844511408 std: prevent instantiation of atomic.Int with non-integral types 2020-12-10 09:23:48 +01:00
LemonBoy
ef7db9717e std: introduce meta.traits.is{Integral,Float} 2020-12-10 09:23:48 +01:00
Jakub Konka
23c1b7faee Merge pull request #7368 from kubkon/macho-trie-cleanup
stage2: MachO export trie cleanup
2020-12-10 08:32:59 +01:00
Joran Dirk Greef
dd3eac2eb1 Debug CI io_uring unsupported op 2020-12-10 08:36:33 +02:00
Michael Dusan
8951f72fa3 Merge pull request #7375 from mikdusan/qemu
ci linux: bump qemu-5.2.0
2020-12-10 00:05:14 -05:00
Andrew Kelley
cb896a6573 CLI: infer --name based on first C source file or object
Previously, --name would only be inferred if there was exactly 1 C
source file or exactly 1 object. Now it will be inferred if there is at
least one of either.
2020-12-09 21:20:13 -07:00
Timon Kruiper
4c51adeb0d Do not keep the build.zig cache manifest file locked.
This allows to have multiple instances of `zig build` at the same
time. For example when you have a long running `zig build run` and
then want to run `zig build somethingelse`.
2020-12-09 22:16:04 -05:00
Michael Dusan
ae0af5e5a6 ci linux: bump qemu-5.2.0 2020-12-09 21:31:31 -05:00
Andrew Kelley
7c93d9aacb mingw-w64: patch to silence implicit-function-declaration warnings
Closes #7356

I did this as a patch to the source rather than passing flags so that
it would intentionally be reverted when we update to the next release of
mingw-w64. At this time if any warnings are still emitted we should find
out why and make sure upstream is aware of the problem.
2020-12-09 16:12:03 -07:00
Andrew Kelley
6e636064e6 MoveFileEx can return ACCESS_DENIED
I observed this on Windows 10, trying to use MoveFileEx with
MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH
to overwrite a running executable.
2020-12-09 15:03:17 -07:00
Jakub Konka
44e2f210bb lld+macho: clean up error message when padding insufficient 2020-12-09 20:36:58 +01:00
Jakub Konka
184c0f3c4e stage2+macho: write code signature only when targeting aarch64 2020-12-09 20:36:58 +01:00
Jakub Konka
601600dec9 macho: parsing Trie now takes a reader and returns bytes read 2020-12-09 20:36:58 +01:00
Jakub Konka
a283404053 macho: split writing Trie into finalize and const write 2020-12-09 20:36:58 +01:00
Jakub Konka
a579f8ae8d macho: add generic terminal info nullable struct to a node 2020-12-09 20:36:58 +01:00
Jakub Konka
4c3e6c5bff macho: cleanup export trie generation and parsing
Now, ExportTrie is becoming usable for larger linking contexts such
as linking in multiple object files, or relinking dylibs, etc.
2020-12-09 20:36:58 +01:00
Andrew Kelley
ae3fd86dcc Merge pull request #7367 from kubkon/aarch64-stp-ldp
stage2: add aarch64 load/store pair of registers instructions
2020-12-09 14:31:08 -05:00
Andrew Kelley
f291194834 Merge pull request #7362 from Vexu/std
zig fmt improvement and small miscellaneous fixes
2020-12-09 14:29:15 -05:00
Martin Wickham
676e416c86 Fix operator precedence documentation 2020-12-09 14:26:29 -05:00
Andrew Kelley
5ff0f364a5 Merge pull request #7366 from LemonBoy/fix-7346
Some compiler-rt fixes
2020-12-09 14:19:58 -05:00
LemonBoy
3f0a4ffbf4 langref: Update setEvalBranchQuota prototype 2020-12-09 20:15:58 +01:00
Joran Dirk Greef
349d32dc2c Add io_uring TIMEOUT and TIMEOUT_REMOVE operations:
ring.timeout() to queue a IORING_OP_TIMEOUT operation
ring.timeout_remove() to queue a IORING_OP_TIMEOUT_REMOVE operation

io_uring_prep_timeout() to prep a IORING_OP_TIMEOUT sqe
io_uring_prep_timeout_remove() to prep a IORING_OP_TIMEOUT_REMOVE sqe
2020-12-09 19:06:28 +02:00
Jakub Konka
2082c27557 stage2+aarch64: clean up offset helper structs 2020-12-09 17:21:21 +01:00
Jakub Konka
e91dbab256 stage2+aarch64: fix stage2 tests 2020-12-09 17:21:17 +01:00
Jakub Konka
eca0727417 stage2+aarch64: use stp and ldp to navigate MachO jump table 2020-12-09 17:20:58 +01:00
Jakub Konka
21dae538ca stage2+aarch64: add load and store pair of registers instructions 2020-12-09 17:20:14 +01:00
LemonBoy
2f4f7ace7a stage1: Resolve some constants to u32, not usize
The latter may be smaller than a u32, use a u32 explicitly.
2020-12-09 17:01:18 +01:00
LemonBoy
6f220bb7ca std: explicitly cast indices to usize
This is needed for platforms where usize=u16, eg. MSP430.
2020-12-09 16:48:41 +01:00
LemonBoy
afd491c07e compiler-rt: Fix compilation of clzsi for armv6 targets 2020-12-09 16:48:02 +01:00
LemonBoy
518168edb2 compiler-rt: Avoid exposing atomic builtins when not supported
Let's a void any kind of compilation/LLVM errors for niche targets such
as AVR/MSP430 or ARM v6m. By not exporting any atomic builtin anymore
the user is free to provide their own implementation (that disable the
IRQs) or to provide the --single-threaded switch and forget about this.
2020-12-09 16:33:53 +01:00
Vexu
7e30e83900 small fixes and zig fmt 2020-12-09 13:54:26 +02:00
Vexu
be71994fb1 zig fmt: improve var decl initializer formatting 2020-12-09 13:47:22 +02:00
Lee Cannon
3599fb9bfc Fixes #7352 - ignore zig fmt ignore zig-cache 2020-12-09 12:11:52 +02:00
Andrew Kelley
391d81a380 Merge pull request #7355 from ziglang/lld-child-process
invoke LLD as a child process rather than a library
2020-12-09 02:26:13 -05:00
Andrew Kelley
7dd4afb224 stage2: link: properly implement passthrough mode for LLD child proc
passthrough mode does not mean always exit - it just means to pass
through stdio and exit if the child process exits, without doing any
special error reporting.
2020-12-08 22:37:01 -07:00
Andrew Kelley
4592fd26b9 add std.testing.expectStringEndsWith 2020-12-08 21:59:24 -07:00
Andrew Kelley
72f6c6e634 invoke LLD as a child process rather than a library
Closes #3825
2020-12-08 20:00:16 -07:00
xackus
21550bb7cd std.json: unreachable -> expect in tests 2020-12-08 19:16:17 -05:00
LemonBoy
8ac711596d stage1: Validate the specified cc for lazy fn types
Closes #7337
2020-12-08 19:09:25 -05:00
antlilja
8f646daed6 Change tag returned by zigTagType for c_longdouble to Float.
Function was returning Int before.
2020-12-09 01:18:27 +02:00
Andrew Kelley
2759313263 add support for environment variables to control cache directories
This commit adds:

ZIG_LOCAL_CACHE_DIR corresponding to --cache-dir
ZIG_GLOBAL_CACHE_DIR corresponding to --global-cache-dir
ZIG_LIB_DIR corresponding to --override-lib-dir

The main use case is for `zig cc` where we are bound by clang's CLI
options and need alternate channels to pass these configuration options.
2020-12-08 14:39:17 -07:00
antlilja
c796c4528e Add option to override default stack size in build system. 2020-12-08 16:18:16 -05:00
Nathanaël Courant
81890e30e2 Fix general purpose allocator incorrectly modifying total_requested_bytes in some cases 2020-12-08 15:53:34 -05:00
Andrew Kelley
58c8ad8ea8 tests: run-translated-c now respects -Dtarget 2020-12-08 13:46:05 -07:00
Andrew Kelley
24cbf1c706 always use codeview (pdb) when object_format is PE/COFF
Previously, when mixing Zig and C/C++ code for windows-gnu targets, zig
would get codeview format but the C/C++ code would not get any debug
info. Now, C/C++ code properly emits debug info in codeview format and
everything just works.
2020-12-08 13:31:39 -07:00
Andrew Kelley
a482b82e2d stage2: only patch up LLD binaries on aarch64-macos
The code is a bit fragile so it was causing CI failures on x86_64-macos.
Also the patch up code is only needed for aarch64-macos, so we were
doing unnecessary work.
2020-12-08 12:47:48 -07:00
Andrew Kelley
97c0e1cc41 glibc: additionally provide -lcrypt
also remove redundant "util" string matching.
2020-12-08 13:17:57 -05:00
Nathan Michaels
1847d0cfc2 Implement msp430 mapping for c_longdouble. (#7333) 2020-12-08 13:09:00 -05:00
Andrew Kelley
a01d55e801 Merge pull request #7309 from ziglang/build-stage1-with-only-zig
ability to build stage1 using only a zig tarball
2020-12-07 23:54:34 -05:00
Andrew Kelley
1afea36a16 update readme installation instructions
The readme now links to the wiki for instructions on building from
source. I plan to make many updates to the wiki soon as I start to
provide tarballs for working on the compiler.
2020-12-07 17:50:14 -07:00
Andrew Kelley
88dc688bbf restore the option to build with cmake
restore cmake to be capable of figuring out the zig version

restore config.h and config.zig. config.h is used to detect whether we
should propagate cmake configuration information to build.zig; however
it can be overridden with -Dstatic-llvm.

fix not passing -DZIG_LINK_MODE with zig build.

when using the cmake build path, build.zig no longer tries to call
llvm-config. Instead it relies 100% on the LLVM_LIBRARIES cmake variable.

build.zig logic reworked and simplified.
2020-12-07 17:27:09 -07:00
Andrew Kelley
211ac00f83 build: -lversion -luuid on windows and -DNDEBUG=1 for clang sources 2020-12-07 17:27:09 -07:00
Andrew Kelley
76e306ad0f fix wrong entrypoint, undefined package, and wrong build option 2020-12-07 17:27:09 -07:00
Andrew Kelley
5a65caa2a3 ability to build stage1 using only a zig tarball
The main idea here is that there are now 2 ways to get a stage1 zig
binary:

 * The cmake path. Requirements: cmake, system C++ compiler, system
   LLVM, LLD, Clang libraries, compiled by the system C++ compiler.

 * The zig path. Requirements: a zig installation, system LLVM, LLD,
   Clang libraries, compiled by the zig installation.

Note that the former can be used to now take the latter path.

Removed config.h.in and config.zig.in. The build.zig script no longer is
coupled to the cmake script.

cmake no longer tries to determine the zig version. A build with cmake
will yield a stage1 zig binary that reports 0.0.0+zig0. This is going to
get reverted.

`zig build` now accepts `-Dstage1` which will build the stage1 compiler,
and put the stage2 backend behind a feature flag.

build.zig is simplified to only support the use case of enabling LLVM
support when the LLVM, LLD, and Clang libraries were built by zig. This
part is probably sadly going to have to get reverted to make package
maintainers happy.

Zig build system addBuildOption supports a couple new types.

The biggest reason to make this change is that the zig path is an
attractive option for doing compiler development work on Windows. It
allows people to work on the compiler without having MSVC installed,
using only a .zip file that contains Zig + LLVM/LLD/Clang libraries.
2020-12-07 17:27:09 -07:00
Luna
5f7b97e84c add AddressFamilyNotSupported to SendError 2020-12-07 16:40:03 -05:00
antlilja
5c60558796 Utilize std.fmt.parseUnsigned in main.zig.
* Remove function parseAnyBaseInt.
* Replace calls to parseAnyBaseInt to calls to std.fmt.parseUnsigned
with radix 0.
* Replace calls to parseInt where the type is unsigned with calls to
parseUnsigned. Note that the functionality of these arguments haven't
changed, they still retain the original radix specified.
2020-12-07 16:38:52 -05:00
xackus
85dc039632 std.c: freeing null is a no-op 2020-12-07 16:33:27 -05:00
g-w1
6294c1136c stage2: variable shadowing detection (#6969) 2020-12-06 19:36:49 +02:00
Veikka Tuominen
0268f54fcf Merge pull request #7313 from LemonBoy/booo
Fix a few unsound optimizations on single-element union/enum
2020-12-06 19:31:07 +02:00
LemonBoy
b45d2968e5 Add some test cases for the previous commits 2020-12-05 20:14:04 +01:00
LemonBoy
97f36d93f4 stage1: Don't fold single-element enums too aggressively
When the tag type is not a zero-sized type (eg. `enum(i32)`) we
absolutely need to avoid constant-folding this values. Doing so masked
any invalid input and, since the folding was not even applied
consistently, introduced some hard to catch errors.
2020-12-05 20:14:04 +01:00
LemonBoy
0f7954831a stage1: Initialize single-element union tag correctly
Use the field value instead of defaulting to zero.
2020-12-05 18:58:54 +01:00
LemonBoy
865d6df03e stage1: Fix constant folding of single-element enums
Fill in the correct value instead of leaving everything uninitialized.
This problem can be noticed in behavior/union.zig but it's masked by
some other "optimization" kicking in at the wrong time, the following
commits will address that.
2020-12-05 18:58:37 +01:00
Andrew Kelley
2ed1ed9b32 stage2: introduce Module.failed_root_source_file
Use case:

zig build-exe non_existent_file.zig

Previous behavior:

error.FileNotFound, followed by an error return trace

Behavior after this commit:

error: unable to read non_existent_file.zig: FileNotFound
(end of stderr, exit code 1)

This turns AllErrors.Message into a tagged union which now has the
capability to represent both "plain" errors as well as source-based
errors (with file, line, column, byte offset). The "no entry point found"
error has moved to be a plain error message.
2020-12-04 17:21:55 -07:00
Andrew Kelley
1c5606af9f update to latest clang C headers 2020-12-04 15:39:16 -07:00
LemonBoy
fd8fa55129 std: Add a few helpers for matching ascii strings (#7300)
* startsWithIgnoreCase
* endsWithIgnoreCase
2020-12-04 15:27:28 -05:00
LemonBoy
ac443b941d std: Restore file locking test on Windows
Make it even more robust wrt timing problems.

Closes #7010
2020-12-04 12:24:50 -08:00
Jakub Konka
b390ced356 macho: specify -install_name as full dylib's name
This then allows for proper resolution of names via runpath search
path list, i.e., `-rpath @loader_path` will correctly resolve
to `@rpath/libxxx.dylib (...)` in the linked binary.
2020-12-04 12:23:49 -08:00
Andrew Kelley
a90de4eef5 Merge pull request #7301 from LemonBoy/more-ci-stuff
Make the CI script more robust
2020-12-04 12:15:55 -08:00
Jakub Konka
c4853ba7ea Version-gate appending -syslibroot flag to lld
This commit version-gates appending `-syslibroot` flag to lld. This
is predicated upon the fact that for versions of macOS lower than
11, lld would fail to find and link against frameworks with this
flag specified.

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-12-04 11:37:55 -08:00
LemonBoy
55838bc291 ci: Use eval to make retry() work for pipelines too 2020-12-04 17:31:27 +01:00
Jakub Konka
b6b7a6401c Merge pull request #7293 from kubkon/fix-7030
stage1: allow idx 0 err to be put into error_name_table
2020-12-04 16:29:38 +01:00
LemonBoy
2282eb1be1 ci: Use -nv flag for wget
-nv, --no-verbose   turn off verboseness, without being quiet
2020-12-04 13:11:45 +01:00
LemonBoy
77031baf98 ci: Prevent some more CI failures
Many times the CI pipeline fails in the early stages because the APT
repo for LLVM is being updated.
Add a retry mechanism for some more APT commands.
2020-12-04 13:11:45 +01:00
Jakub Konka
e3db2be899 Add minimal standalone test case 2020-12-04 12:43:58 +01:00
Andrew Kelley
58241364cb add more mingw-w64 .def files
closes #7268
2020-12-03 18:03:34 -07:00
Andrew Kelley
afaef36194 stage1: compile error for pointer arithmetic on ptr-to-array
See #2018
2020-12-03 17:07:13 -07:00
Isaac Yonemoto
fd18252a71 makes the implementation public 2020-12-03 15:14:59 -08:00
Andrew Kelley
ddaf915389 add @cImport files to Compilation cache manifest
closes #7007
2020-12-03 16:07:38 -07:00
Jakub Konka
54706dd229 Allow idx 0 err to be put into error_name_table
This way, in the very situation where a function has a return type
an error union such as `anyerror!void` but doesn't have any erroneous
paths, calling `@errorName` on the unpacked error (which will never
be triggered) will not trip up the static analyzer.
2020-12-03 23:31:35 +01:00
Andrew Kelley
ecf7dfcd3a Merge pull request #7273 from kubkon/lld-codesig-poc
lld+macho: patch lld output on Apple Silicon by calculating and embedding adhoc code signature
2020-12-03 13:41:31 -08:00
Jakub Konka
d3be499270 lld+macho: address review comments 2020-12-03 21:57:26 +01:00
Isaac Yonemoto
a2cd9dc3bd Gpa mutex configurable (#7234)
* makes the mutex for the gpa configurable

* fixed logic, added test

* updates docstring; pushes logic to one place, better duck-type
2020-12-03 15:49:35 -05:00
Koakuma
5317f00e04 Fix floating point parsing on BE systems (#7256)
* Fix floating point parsing on BE systems

* Load the appropriate endian.h files for macOS and BSD

* Add endian definition for Windows and extra check for ldshape selection

* Fix endian macro definition for macOS

Apparently their macros are defined without a leading __.

* Define new macro for endian checking purposes

This is gross and I really do not like the lack of standardization
around this part, but what can I do?
2020-12-03 15:47:06 -05:00
Miles Alan
7bbd369fbb std/event: Fix import path for WaitGroup 2020-12-03 12:43:55 -08:00
Jakub Konka
a8e543bd6b Merge pull request #7280 from leecannon/master
Add `readUntilDelimiterOrEofArrayList` & `readUntilDelimiterOrEofAlloc`
2020-12-03 21:03:48 +01:00
Timon Kruiper
ac85e1f2c8 stage2: make sure to emit the ZIR instructions of exported functions
Previously the emitted ZIR code would not have the ZIR instructions
of the exported functions.
2020-12-03 11:46:35 -08:00
Lee Cannon
f598245836 Make zig fmt happy with multiline arguments for readAllArrayListAligned 2020-12-03 10:24:49 +00:00
Andrew Kelley
5b6cbd2e7c stage2: don't pass -l arguments when building .a or .o files
See #7094
2020-12-02 20:17:51 -07:00
LemonBoy
cb63ecd6e9 std: Add nosuspend around stderr.print calls 2020-12-02 16:34:51 -08:00
Vexu
d4c167f3cd std.build: addBuildOption special handling for SemanticVersion 2020-12-02 16:33:27 -08:00
Andrew Kelley
41387e1822 stage2: linkAsArchive: respect disable_lld_caching
Closes #7274
Closes #6943
2020-12-02 16:37:32 -07:00
Andrew Kelley
6d91ebce45 wire up -Dskip-non-native to stage2 tests 2020-12-02 15:52:07 -07:00
Andrew Kelley
463186e856 stage2: wire up -Dskip-non-native
The purpose of this is to save time in the edit-compile-test cycle when
working on stage2 code.
2020-12-02 14:52:56 -07:00
Andrew Kelley
f842327147 Merge pull request #7277 from LemonBoy/thread-posix
std: make the use of pthread_join POSIX-compliant
2020-12-02 13:47:40 -08:00
Jakub Konka
5cba16c707 macho:use mem.asBytes and meta.eql in commands.zig
This commit addresses comments suggesting a cleaner approach
at converting an `extern` struct to its byte representation using
`mem.asBytes`, and to use `meta.eql` in place of more fragile
`mem.eql(u8, ...)` for comparison of two `extern` structs.

Thanks LemonBoy!
2020-12-02 18:40:31 +01:00
Mathieu Guay-Paquet
4c8632e244 fix the tinyest typo 2020-12-02 19:08:25 +02:00
Lee Cannon
76f3921544 Add readUntilDelimiterOrEofArrayList & readUntilDelimiterOrEofAlloc 2020-12-02 12:55:54 +00:00
LemonBoy
471e26425a ci: Retry apt-get install at most three times
Try harder instead of failing after the first invocation fails.
2020-12-02 12:14:11 +01:00
Jakub Konka
0fba2f7175 lld: fix using incorrect path for the final artefact 2020-12-02 11:21:52 +01:00
LemonBoy
f8cef32f27 std: make the use of pthread_join POSIX-compliant
Applications supplying their own custom stack to pthread_create are not
allowed to free the allocated memory after pthread_join returns as,
according to the specification, the thread is not guaranteed to be dead
after the join call returns.

Avoid this class of problems by avoiding the use of a custom stack
altogether, let pthread handle its own resources.

Allocations made on the child stack are now done on the C heap.

Thanks @semarie for noticing the problem on OpenBSD and suggesting a
fix.

Closes #7275
2020-12-02 10:59:35 +01:00
daurnimator
db0cb54f4e Localhost is special (#6955)
* std: always return loopback address when looking up localhost

* std: also return Ipv6 loopback

* std: remove commented out obsolete code
2020-12-01 19:13:59 -05:00
LemonBoy
c91c4dc256 stage2: Create cache manifest before calling final
If we enter the `if` because `comp.disable_c_depfile` is false the `man`
object has no manifest and calling .final on it will trip an assertion.

Closes #7096
2020-12-01 16:52:28 -07:00
Andrew Kelley
5b5097a22a stage2: add -femit-foo=bar args to the cache hash
Closes #6979
Closes #7036
2020-12-01 16:35:27 -07:00
Jakub Konka
3e2d1ccaad lld+macho: rename final artefact in main.zig 2020-12-02 00:03:07 +01:00
Jakub Konka
b58a2a4de6 lld+macho: move parsing logic into MachO 2020-12-01 23:39:07 +01:00
Alexandros Naskos
8d6eff5cb9 Add package names and paths to the zig root module cache hash.
Add package names to the stage1 cache hash and package files to the
stage1 manifest file.
2020-12-01 13:56:36 -08:00
Timon Kruiper
8cbcc61c4d Make sure to include the root_name in the cache.
This fixes a bug where the caching system did not notice when the
--name flag changed.
2020-12-01 10:38:33 -08:00
Andrew Kelley
c7028ce0c6 COFF linking: fix incorrectly passing .dll instead of .lib
commit 9d1816111d used the "output path"
as the path for passing shared library artifact paths to the Zig CLI.
For Windows, this was incorrect because it would pass the .dll instead
of the .lib file. This commit passes the "output lib path" instead,
which makes it pass the .lib path in case of a .dll on Windows.

This way the linker does not complain and say, "bad file type. Did you
specify a DLL instead of an import library?"
2020-12-01 11:28:44 -07:00
Jakub Konka
ed18046518 macho: dynamically calculate code signature padding 2020-12-01 18:03:31 +01:00
Jakub Konka
abb697e751 macho: unify code signature between stage1 and stage2 2020-12-01 18:03:04 +01:00
Jakub Konka
1f7fb560ab lld: use commands.LoadCommand in self-hosted linker 2020-12-01 10:49:31 +01:00
Jakub Konka
de66b65677 lld: start unifying load command logic 2020-12-01 10:49:31 +01:00
Jakub Konka
0ef3071db6 lld: copy+rename to please the kernel 2020-12-01 10:49:31 +01:00
Jakub Konka
c25b3593e7 lld: add code signature to lld output 2020-12-01 10:49:31 +01:00
Jakub Konka
545721ccd1 lld: add code signature padding 2020-12-01 10:49:31 +01:00
Jakub Konka
e8ffae60a2 lld: parse output lld file 2020-12-01 10:49:31 +01:00
Andrew Kelley
02e12ede46 update to latest fetch-them-macos-headers
commit 1efc3a7f584dd75a5783756e168af74cdf6bb727
2020-11-30 20:20:31 -08:00
Isaac Freund
92ec24f77c std/os: remove unneeded error from accept errorset
POSIX compliant fnctl cannot return EPERM when getting/setting the given
flags. See the specification here:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
2020-11-30 20:00:26 -08:00
Andrew Kelley
21565ca991 restore -target wasm32-freestanding-musl for C headers
See #5854

Some tiny tweaks too:
 * Use `wasm-freestanding-musl` instead of `wasm32-freestanding-musl`,
   making it pointer-size-agnostic.
 * Fix trying to build non-existent wasm musl start files.
2020-11-30 20:44:36 -07:00
Andrew Kelley
429a219f42 stage2: fix not detecting all dynamic libraries
Positional shared library arguments were not being detected as causing
dynamic linking, resulting in invalid linker lines. LLD did not have an
error message for this when targeting x86_64-linux but it did emit an
error message when targeting aarch64-linux, which is how I noticed the
problem.

This surfaced an error having to do with fifo.pipe() in the cat example
which I did not diagnose but solved the issue by doing the revamp that
was already overdue for that example.

It appears that the zig-window project was exploiting the previous
behavior for it to function properly, so this prompts the question, is
there some kind of static/dynamic executable hybrid that the compiler
should recognize? Unclear - but we can discuss that in #7240.
2020-11-30 20:25:28 -07:00
Andrew Kelley
c55984b58f Merge branch 'alexnask-fix_6868' into master
Closes #7139
Closes #6868
2020-11-30 18:12:07 -07:00
Andrew Kelley
9d1816111d build system: pass dyn lib artifacts as positionals 2020-11-30 18:12:00 -07:00
Alexandros Naskos
f7d0a32045 Switched OBJECT_NAME_INVALID handling to unreachable in faccessatW 2020-11-30 18:08:27 -07:00
Alexandros Naskos
beb9d33d6d Disallow absolute paths passed as system libraries
Added OBJECT_NAME_INVALID handling in faccessatW
2020-11-30 18:08:27 -07:00
Andrew Kelley
8c9919ec7b fix regression on wasm targets
The previous commit broke wasm targets because the linking step would
look for the compiler-rt lib in the wrong place. Fixed in this commit.
2020-11-30 17:46:10 -07:00
Andrew Kelley
205af5b148 Merge branch 'alexnask-bundle_compiler_rt' into master
Closes #7013
Closes #6817
2020-11-30 16:40:25 -07:00
Andrew Kelley
ff9798eb26 rework the bundle compiler-rt feature
* it is now -fcompiler-rt and -fno-compiler-rt to override the (quite
   reasonable) default of bundling compiler-rt only for executables and
   dynamic libraries.
   - the build.zig API is still called bundle_compiler_rt however it is
     now an optional bool instead of a bool. leaving it as `null` means
     to use the compiler default.
 * renamed some internal identifiers to make the source more readable
 * additionally support -fcompiler-rt when doing build-obj for ELF files
   since that target already supports linking multiple objects into one.
   - includes an error message when attempting this for non-ELF. in the
     future this could additionally be supported with a more advanced
     implementation that does not rely on the linker.
 * properly populate the linker cache hash
2020-11-30 16:35:00 -07:00
Alexandros Naskos
2fae28b6af Added bundle-compiler-rt flag 2020-11-30 14:31:41 -07:00
Andrew Kelley
51d7c14ce1 update to latest fetch-them-macos-headers
commit 09b70199e738bfa86c55cd3a848287229a207982

closes #7261
2020-11-30 13:18:34 -08:00
Andrew Kelley
50a336fff8 move std.SegmentedList to the std-lib-orphanage
I spent a long time working on this data structure, and I still think
it's a neat idea, but it has no business being in the std lib.

I'm aware of the few remaining references to SegmentedList that exist in
the std lib, but they are dead code, and so I'm leaving the dead
references as a clue that the code is dead. Cleaning up dead code will
be a separate effort that involves code coverage tools to make sure we
find it all.

std-lib-orphanage commit: 2c36a7894c689ecbaf63d5f489bb0c68773410c4

closes #7190
2020-11-30 13:04:26 -07:00
Jonathan Marler
b587a42233 add std.os.shutdown function for sockets 2020-11-30 11:25:03 -08:00
Michael Freundorfer
baa075ac8c Fix WindowsDynLib.openW trying to strip the \??\ prefix when it does not exist 2020-11-30 11:12:33 -08:00
Rageoholic
0369b65082 Switch to using unicode when parsing the command line on windows (#7241)
* Switch to using unicode when parsing the command line on windows

* Apply changes by LemonBoy and *hopefully* fix tests on MIPs

Co-authored-by: LemonBoy <LemonBoy@users.noreply.github.com>

* Fix up next and skip

* Move comment to more relevant place

Co-authored-by: LemonBoy <LemonBoy@users.noreply.github.com>
2020-11-30 13:47:01 -05:00
Jonathan Marler
b8f09f773a fix memory leak in BufMap 2020-11-30 10:40:16 -08:00
Andrew Kelley
4808a0261f macOS headers: add memory.h
it's provided by macOS LibC and apparently there is code in the wild
that depends on it. all it does is #include <string.h>

closes #7249
2020-11-29 17:41:16 -08:00
Andrew Kelley
52b24d5725 stage1: add some code comments for ConstValSpecial 2020-11-29 18:02:13 -07:00
Andrew Kelley
3fb0cc0a14 CLI: add missing usage help text 2020-11-29 16:32:24 -07:00
Andrew Kelley
263f25fea6 Merge pull request #7116 from joachimschmidt557/stage2-arm
stage2 ARM: add basic arithmetic instructions
2020-11-29 10:43:29 -08:00
LemonBoy
df99cfdf1e stage1: Fix typeInfo generation for arrays w/o sentinel
ZigTypeIdOptional types have a different way of specifying their payload
value depending on whether the child type is a pointer or not (plus some
other special cases).

Fixes #7251
2020-11-29 10:39:10 -08:00
LemonBoy
c80d196094 stage1: Add missing bitcast when rendering var ptr
Some types require this extra bitcast, eg. structs or unions with extra
padding fields inserted by the compiler.

Fixes #7250
2020-11-29 10:37:06 -08:00
Jonathan Marler
48660371a2 std.meta: add assumeSentinel 2020-11-29 10:36:02 -08:00
Andrew Kelley
e701ac1a51 Merge pull request #7237 from koachan/sparc64-longdouble_fork
Add "long double" mapping and implement fork() on Linux/sparc64
2020-11-29 10:33:43 -08:00
LemonBoy
89ee4b8621 std: Avoid deadlock in the signal handler
stderr_mutex may still be held when we reach the signal handler, grab
our own stderr handle to print the error messages and avoid deadlocking.

Closes #7247
2020-11-29 10:31:06 -08:00
joachimschmidt557
ceebcb2b4d stage2 ARM: add test case for addition 2020-11-28 23:26:17 +01:00
joachimschmidt557
2ad2636588 stage2 ARM: use strb + implement genBoolOp 2020-11-28 18:19:22 +01:00
joachimschmidt557
f06f0ebcda stage2 ARM: Implement genNot 2020-11-28 18:19:22 +01:00
joachimschmidt557
85a3991a43 stage2 codegen: use switch in genBoolOp 2020-11-28 18:19:22 +01:00
joachimschmidt557
27c5c97f21 stage2 ARM: genAdd, genSub for simple cases 2020-11-28 18:19:19 +01:00
Koakuma
f10bff9ffb Add a comment to explain the fork return values on sparc64 2020-11-28 13:24:24 +07:00
christian-stephen
abc729a5f9 Add readAllArrayListAligned to Reader which can accept an arbitrary alignment 2020-11-27 17:00:50 -08:00
Andrew Kelley
9268972ff9 Merge branch 'kubkon-elf-soname-opt-in' into master
closes #7162
2020-11-27 17:54:22 -07:00
Andrew Kelley
c3b0182f31 restore sonames by default when using zig cli
Before this commit, the branch regressed this case:

zig build-lib foo.zig -dynamic
readelf -d libfoo.so
 x000000000000000e (SONAME) Library soname: [libfoo.so]

Now it works again, but it preserves the property that using `zig cc`
has the SONAME off by default to match C compilers.
2020-11-27 17:49:55 -07:00
Jakub Konka
dd522c0c97 stage2 elf: fix glibc to always specify soname 2020-11-27 15:42:39 -07:00
Jakub Konka
375bab8460 stage2 elf: refactor override_soname to soname 2020-11-27 15:42:39 -07:00
Jakub Konka
12efefeba5 stage2 elf: make -soname an opt-in and not opt-out
As discussed with LemonBoy, it makes more sense to have the `-soname`
an opt-in option rather than opt-out, which is especially true if
we are to align `zig cc` with `cc` to a greater degree.
2020-11-27 15:42:39 -07:00
Andrew Kelley
9e4360c335 Merge pull request #7198 from LemonBoy/freebsd-lock
std: Fix file locking logic for BSD targets
2020-11-27 14:35:30 -08:00
LemonBoy
f91df39ad2 stage1: Fix crash in *[N]T to []T conversion with zst
Prevent the crash by not making the codegen try to access the
non-existing ptr field in the slice.

Closes #6951
2020-11-27 14:33:26 -08:00
Jakub Konka
3bc1c719bd Merge pull request #7231 from kubkon/stage2-arm-macos
stage2: Hello, Silicon!\n
2020-11-27 21:49:06 +01:00
Jakub Konka
5ed76268c9 stage2 macho: apply more review comments 2020-11-27 20:55:34 +01:00
Jakub Konka
02baaac506 Update src/codegen.zig
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-11-27 20:31:26 +01:00
Koakuma
41c40f4bbe Fix fork() on Linux/sparc64
fork() on Linux/sparc64 seems to return its result in two registers,
with %o0 always holding the current process' PID, and the parent/child
status returned in %o1. Add some glue code to convert those into
the libc-style return value.
2020-11-27 23:02:22 +07:00
Koakuma
cf2ee4ae2c Add sparc64 long double mapping 2020-11-27 18:51:50 +07:00
g-w1
daf6c0da5b CONTRIBUTING: src-self-hosted -> src 2020-11-26 16:40:57 -08:00
Jakub Konka
ebb2f20815 stage2 macho: Dir.copyFile does the rename for us! 2020-11-26 21:12:20 +01:00
Jakub Konka
a8f8d82215 stage2 macho: use Dir.copyFile instead of manual create+copy 2020-11-26 20:21:53 +01:00
LemonBoy
21c488ce68 stage1: Force union member types to be resolved
No test case because I couldn't reduce the huuuge test case.
Fixes the problem discovered by @ifreund.
2020-11-26 10:49:47 -08:00
Jakub Konka
f125c4f5c7 stage2 macho: enable end-to-end incremental linking tests on aarch64 2020-11-26 11:50:09 +01:00
Jakub Konka
7e8f7da3ec stage2 macho: rename inodes to prevent SIGKILL 2020-11-26 11:50:09 +01:00
Jakub Konka
64eae8f392 stage2 macho: move PIE fixups to link file; fix tests 2020-11-26 11:50:09 +01:00
Jakub Konka
c749b78df5 stage2 macho: add orr and orn instructions 2020-11-26 11:50:09 +01:00
Jakub Konka
10942e3f86 stage2 macho: Hello, Silicon! 2020-11-26 11:50:09 +01:00
Jakub Konka
2cd84b1b3f stage2 macho: refactor PIE generation on x86_64 2020-11-26 11:50:09 +01:00
Jakub Konka
ef5132c508 stage2 macho: first, rough draft at trampolining 2020-11-26 11:50:09 +01:00
Jakub Konka
80b1041c21 stage2 macho: use RIP-relative for memory-set regs x86_64 2020-11-26 11:50:09 +01:00
Jakub Konka
59fe3d447d stage2 macho: make file structure compatible with codesign tool 2020-11-26 11:50:09 +01:00
Jakub Konka
e7db372864 stage2 macho: cleanup logs 2020-11-26 11:50:09 +01:00
Jakub Konka
cd79c6dda1 stage2 macho: fix issues with codesigning 2020-11-26 11:50:09 +01:00
Jakub Konka
a6e93da717 stage2 macho: generate a code sig (not valid yet) 2020-11-26 11:50:09 +01:00
Jakub Konka
9dcf7ee9c9 stage2 macho: add info about __TEXT segment 2020-11-26 11:50:09 +01:00
Jakub Konka
79381dc4fb stage2 macho: add empty CodeDirectory blob 2020-11-26 11:50:09 +01:00
Jakub Konka
d14cd59ef0 stage2 macho: move code signature logic into struct 2020-11-26 11:50:09 +01:00
Jakub Konka
3ac804628f stage2 macho: write out constants in CS 2020-11-26 11:50:09 +01:00
Jakub Konka
2bd963ad6a stage2 macho: don't pad out holes between sections 2020-11-26 11:50:09 +01:00
Jakub Konka
403dc50ff7 stage2 macho: preallocate empty code sig space 2020-11-26 11:50:09 +01:00
Jakub Konka
bbc4ee3f17 stage2 macho: refactor 2020-11-26 11:50:09 +01:00
Jakub Konka
a2e0e33249 stage2 macho: bring back incremental symbol commits 2020-11-26 11:50:09 +01:00
Jakub Konka
e1b65ff8d2 stage2 macho: cleanup minimum version command 2020-11-26 11:50:09 +01:00
Jakub Konka
be0d5571d2 stage2 macho: revert required alignment always at 4 2020-11-26 11:50:09 +01:00
Jakub Konka
e8dd62accd stage2 macho: fix incorrect rebase 2020-11-26 11:50:09 +01:00
Jakub Konka
2972f630a4 stage2 macho: start reverting some tweaks 2020-11-26 11:50:09 +01:00
Jakub Konka
4e3520a2f7 stage2 macho: make page size target cpu arch dependent 2020-11-26 11:50:09 +01:00
Jakub Konka
8450e6f156 stage2 macho: pages need to be 16kb aligned! 2020-11-26 11:50:09 +01:00
Jakub Konka
4a3d757f3e stage2 MachO: reduce size of __TEXT segment 2020-11-26 11:50:09 +01:00
Jakub Konka
7a407246ed stage2 MachO: remove discontinuities between segments 2020-11-26 11:50:09 +01:00
Jakub Konka
6ac7e99dad Write local symbols when flushing 2020-11-26 11:50:09 +01:00
Jakub Konka
b3fdfe5ca0 stage2 MachO: clean up segment protection flags 2020-11-26 11:50:09 +01:00
Jakub Konka
7dd5ce2527 stage2 macOS: make exe flagged as pie 2020-11-26 11:50:09 +01:00
Jakub Konka
1bec531cf2 stage2 MachO: add source version load cmd 2020-11-26 11:50:09 +01:00
Jakub Konka
72310db1da stage2 MachO: add min OS version load cmd 2020-11-26 11:50:09 +01:00
Isaac Freund
58365c4e79 std/os: fix prctl constants 2020-11-25 15:45:55 -08:00
Andrew Kelley
a06afa4579 Merge pull request #6411 from LemonBoy/fff
More std.fmt goodness
2020-11-25 15:43:19 -08:00
daurnimator
b7b3c1dfae std: use mem.asBytes in Ip4Address.parse so it works at comptime 2020-11-25 15:40:46 -08:00
Frank Denis
83abb32247 std/crypto - edwards25519 precomp: prefer doublings over adds
Doublings are a little bit faster than additions, so use them half
the time during precomputations.
2020-11-25 15:37:43 -08:00
LemonBoy
58c2bec589 stage1: Fix ICE when generating struct fields with padding
Make gen_const_ptr_struct_recursive aware of the possible presence of
some trailing padding by always bitcasting the pointer to its expected
type.

Not an elegant solution but makes LLVM happy and is consistent with how
the other callsites are handling this case.

Fixes #5398
2020-11-25 15:36:33 -08:00
Andrew Kelley
500fbdad57 update stack trace test with new start.zig line number 2020-11-25 00:40:50 -07:00
Andrew Kelley
479f259ea4 make start code more versatile
* always align the stack to 16. I saw an instance on x86_64 linux where
   it was needed.

 * detect at runtime if being interpreted by a dynamic loader and if so
   avoid clobbering the fs register.
2020-11-24 19:51:24 -07:00
LemonBoy
8ed7561422 std: Re-enable the use of O_EXLOCK/O_SHLOCK on macos 2020-11-24 10:23:54 +01:00
Jonathan Marler
a1fb10b766 fix for GCC 9.2: -Wno-maybe-uninitialized 2020-11-23 17:55:48 -08:00
Frank Denis
70c8cabb34 Update the minimum cmake version we require
Recent versions of cmake complain about it:

<<
  CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.
>>

We don't require anything from version 2.8.5, and version 2.8.12 was
released in 2011, so it is very unlikely that anyone still uses 2.8.5.
2020-11-23 12:44:54 -08:00
LemonBoy
26d20e39fc std: Close dangling fd on error
This patch was already submitted for openFileZ, createFileZ was left
unpatched.
2020-11-23 18:00:05 +01:00
LemonBoy
0d4f05bb8a std: Remove O_NONBLOCK flag after locking
We only need O_NONBLOCK when O_SHLOCK/O_EXLOCK are used and we don't
want open() to block, don't let this bit leak to the user fd.
2020-11-23 18:00:05 +01:00
LemonBoy
f8ddc3d873 std: Fix file locking logic for BSD targets 2020-11-23 18:00:05 +01:00
Andrew Kelley
9d2fe1682f Merge pull request #7204 from LemonBoy/piecrash
Fix logic for detecting _DYNAMIC symbol
2020-11-23 08:55:34 -08:00
LemonBoy
3e22077d46 Fix the ELF base calculation
Find the effective ELF load address in dl_iterate_phdr by computing the
difference between the in-memory phdr and its p_vaddr specified in the
ELF file.

This makes the dl_iterate_phdr test pass and restores the stack traces.
2020-11-23 15:06:07 +01:00
LemonBoy
0a84f85945 Minor code cleanup in start_pie.zig
Thanks @daurnimator for catching this.
2020-11-23 12:36:40 +01:00
LemonBoy
bfa7e5c743 Update stack_traces test 2020-11-23 12:36:03 +01:00
LemonBoy
560043dadf Fix logic for detecting _DYNAMIC symbol
Prevent spurious crashes for non-PIE executables.
2020-11-23 12:00:12 +01:00
Andrew Kelley
c7170e4a54 Support PIE (Position Independent Executables)
Closes #4503
Revives #3960
Merges branch 'pie' into master
2020-11-22 17:30:34 -07:00
Andrew Kelley
abc717f203 modernize the PIE patch for the latest master branch
This is the part of #3960 that has to be rewritten to apply to latest
master branch code.
2020-11-22 17:28:11 -07:00
Andrew Kelley
55ab50efbd Merge branch 'piepiepie' of https://github.com/LemonBoy/zig into pie
Conflicts:
 lib/std/dynamic_library.zig (fixed in this commit)
 src/all_types.hpp
 src/codegen.cpp
 src/link.cpp
 src/main.cpp

Will manually apply the diffs to these deleted files to the new zig
code in a followup commit.
2020-11-22 12:39:44 -07:00
Vexu
98d5bfbd4d update grammar in langref 2020-11-22 21:30:09 +02:00
Aransentin
c8723beda8 UnregisterClassW needs WINAPI as well 2020-11-22 14:58:10 +00:00
Aransentin
6fd536a50c Fixed bugs, style suggestions 2020-11-22 14:51:32 +00:00
Jens Goldberg
bbc2c7c268 Ensure the dynamic function has the same type as the static one
Co-authored-by: daurnimator <quae@daurnimator.com>
2020-11-22 14:24:36 +00:00
Aransentin
fcf3f61c28 user32 cleanup, added wrappers and additional functions 2020-11-22 13:00:57 +00:00
Žiga Željko
2fbe9519ac std: add support for ppoll 2020-11-21 14:06:04 -08:00
LemonBoy
a2e9554699 std: Add test for meta.declarations on opaque{} 2020-11-21 14:03:49 -08:00
Andrew Kelley
7dcda5b0e8 Merge pull request #7182 from LemonBoy/externnnn
Initial implementation of @extern builtin
2020-11-21 09:41:49 -08:00
LemonBoy
ccdaf946b9 Rename back to extern, extend a stage1 parser hack
Make it recognize extern/export symbols prefixed by @ as a builtin
rather than stand-alone keywords.
2020-11-21 09:48:21 +01:00
Andrew Kelley
bf0cc32aa6 Merge pull request #7165 from LemonBoy/ppc64final
Make the PPC64 port usable
2020-11-20 17:40:17 -08:00
Isaac Freund
8cf319d206 std/os: define and use dev_t for linux x86_64 2020-11-20 17:35:52 -08:00
Sébastien Marie
87eb498d89 openbsd: malloc_usable_size is unavailable on OpenBSD 2020-11-20 17:31:29 -08:00
Isaac Freund
f473b3e87c std/os: add time_t definiton for x86_64 linux 2020-11-20 17:23:43 -08:00
LemonBoy
6029114f84 stage1: Resolve usingnamespace decls when calling @typeInfo
Closes #7176
2020-11-20 17:01:23 -08:00
LemonBoy
9b7d9c72b0 stage1: Initial implementation of @extern 2020-11-20 22:32:43 +01:00
LemonBoy
2193bbfd93 Skip f16 to f128 conversion test for ppc64
As for aarch64 we're waiting for LLVM to emit calls to the specific
builtins that implement this conversion.
2020-11-20 08:38:11 +01:00
LemonBoy
f2b4e6b2e7 Better coverage in @splat tests
Cover more common and uncommon cases.
2020-11-20 08:38:10 +01:00
LemonBoy
9c5eea9f40 stage2: Use correct ppc generic feature set 2020-11-20 08:38:10 +01:00
LemonBoy
e374ae3598 std: Use newfstatat on PPC64
One more variation in the syscall table, hooray!
2020-11-20 08:38:10 +01:00
LemonBoy
4e2a4e194b std: Use correct clone() stub
The previous clone() definition was written for 32bit PPC targets,
trying to execute it on a PPC64 machine lead to countless crashes.

Use the clone() definition kindly lifted from Musl libc.
2020-11-20 08:38:10 +01:00
LemonBoy
3da6b1218a std: Implement named arguments & runtime width/precision 2020-11-20 08:36:47 +01:00
LemonBoy
6b39167fdc std: Rewrite the fmt parser
Turn the FSM parser into a linear one so that's easier to implement new
features and/or more error checking without adding more and more states.
Functionally-speaking the two parsers are at feature parity.
2020-11-20 08:36:10 +01:00
Andrew Kelley
73be59433f Merge pull request #6928 from data-man/reduce_tests
Add more tests for reduce
2020-11-19 17:48:18 -08:00
Jakub Konka
c25cb39d17 Merge pull request #7160 from semarie/openbsd-getdents
openbsd: getdents could return invalid entry with d_fileno==0
2020-11-20 00:23:57 +01:00
Isaac Freund
a5691ee363 std.meta.declarations: support opaque {} 2020-11-19 15:04:38 -08:00
Andrew Kelley
473cb1fd74 Merge pull request #6390 from LemonBoy/reboot-3970
std.fmt meets UTF-8
2020-11-19 14:58:11 -08:00
LemonBoy
d526b0ffb0 std: Disable _only_ the flaky part of the ResetEvent test
The remaining part is working just fine as it's not time-dependent.
2020-11-19 15:46:20 -07:00
LemonBoy
8eaaa905f7 stage2: Make zig cc more verbose (#7166)
* stage2: Make zig cc more verbose

Make `zig cc` print more info from Clang itself and from our own linker
invocation, this is needed for CMake to properly discover all the
include directories and library search paths.

Closes #7110

* Update `update_clang_options`

* Typo fixes

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2020-11-19 23:30:16 +01:00
Andrew Kelley
647c6e0d09 tfw you can't even disable a test without getting the logic wrong 2020-11-19 13:28:54 -07:00
LemonBoy
60638f0c82 Nicer code for the error code path 2020-11-19 18:16:23 +01:00
Veikka Tuominen
cf819b95fe Merge pull request #6829 from tadeokondrak/error-unsupported-callconv
stage1: Compile error instead of falling back to C for unsupported cc
2020-11-19 19:03:08 +02:00
Tadeo Kondrak
25ec2dbc1e Add builtin.Signedness, use it instead of is_signed 2020-11-19 18:59:21 +02:00
Sébastien Marie
b174942e6a openbsd, netbsd: getdents: entry with d_fileno==0 should be skipped 2020-11-19 13:55:46 +00:00
Sébastien Marie
7579ce180f Iterator: rename freebsd_entry to bsd_entry to reflect that nextBsd is not freebsd only 2020-11-19 13:54:47 +00:00
Sébastien Marie
ad2ff9e65d darwin: getdents: entry with d_ino==0 should be skipped 2020-11-19 13:54:29 +00:00
Vexu
3a28b659bd add compile-error tests for unsupported calling convention 2020-11-19 14:25:46 +02:00
Tadeo Kondrak
51b362c350 stage1: Check calling convention correctly for subsystem detection 2020-11-19 14:18:35 +02:00
Tadeo Kondrak
c002a5026a Update code to not use unsupported calling conventions for target 2020-11-19 14:01:07 +02:00
Tadeo Kondrak
6b9dc82fa5 stage1: Compile error instead of falling back to C for unsupported cc 2020-11-19 13:59:11 +02:00
LemonBoy
2b7781d82a stage1: Fix undefined assignment for bitfields
Prevents silent memory corruption.

Closes #7055
2020-11-18 21:49:39 -08:00
Andrew Kelley
13cccdd92c add std.heap.raw_c_allocator
This API does what `std.heap.c_allocator` previously did. See the new
doc comments for more details.
2020-11-18 22:09:34 -07:00
Andrew Kelley
02a4e5a4bf Merge pull request #6385 from LemonBoy/callocator
std: Make C allocator respect the required alignment
2020-11-18 20:16:57 -08:00
breakin
6d3c176c12 Change seed for Murmur2_64 from u32 to u64 2020-11-18 17:05:38 -08:00
Veikka Tuominen
2418c8206a Merge pull request #7154 from daurnimator/std.atomic
std.atomic.{Int,Bool}
2020-11-18 21:48:17 +02:00
pfg
cf7de64f1a stage1: improve error for missing a number type on a runtime var 2020-11-18 21:45:51 +02:00
Jakub Konka
663e112773 std: add chdir smoke test 2020-11-18 15:37:44 +01:00
Lee Cannon
64feae3ac3 Move utf8->utf16 up one level into os.zig 2020-11-18 15:37:44 +01:00
Lee Cannon
dbbe709dc7 use else in err switch 2020-11-18 15:37:44 +01:00
Lee Cannon
32c998e03c Switch to RtlSetCurrentDirectory_U 2020-11-18 15:37:44 +01:00
Lee Cannon
80b1e82b1b Implement chdir and chdirZ for Windows 2020-11-18 15:37:44 +01:00
Veikka Tuominen
a6470088c6 Merge pull request #6434 from daurnimator/fifo.pump
std: add LinearFifo(...).pump(src_reader, dest_writer)
2020-11-18 16:35:13 +02:00
Veikka Tuominen
ee1d21bbef Merge pull request #6649 from Rocknest/verparse
make Version.parse less strict
2020-11-18 16:06:52 +02:00
daurnimator
767dd772c0 std: add std.atomic.Bool 2020-11-19 00:58:13 +11:00
daurnimator
d89d6374be std: add tests for std.atomic.Int 2020-11-19 00:57:54 +11:00
daurnimator
8fa29bc0a2 std: fix missing operation argument to @atomicRmw 2020-11-19 00:57:35 +11:00
daurnimator
eb4d93ece3 std: some more docs for std.atomic.Int 2020-11-19 00:44:38 +11:00
daurnimator
513e8161dd std: mark std.atomic.Int as extern so it can be used in public ABIs 2020-11-19 00:41:43 +11:00
daurnimator
c492ef97fd std: expose all atomic operations from std.atomic.Int 2020-11-18 15:36:40 +02:00
Vexu
da84ef2a9c make help in commands more consistent
Closes #7101

Co-authored-by: pfg <pfg@pfg.pw>
2020-11-18 13:58:27 +02:00
frmdstryr
a39d3155b4 Change error when runtime value passed to comptime arg 2020-11-18 13:33:45 +02:00
LemonBoy
129ccad434 stage1: Reject undefined values when taking union ptr
The code rightfully assumes the union_val object to be fully initialized.

Closes #7019
2020-11-18 13:21:36 +02:00
Alexandros Naskos
252924ae33 Added std.meta.fieldNames 2020-11-18 13:16:56 +02:00
Veikka Tuominen
6d5b76a75d Merge pull request #7005 from jshholland/deprecate-span
Remove ArrayList.span
2020-11-18 13:14:48 +02:00
Timon Kruiper
66d6930b5c Allow Zig to be built with clang 11 and -Werror
This was brought to the horizon when using zig-bootstrap to cross compile
Zig for windows-gnu.
2020-11-18 13:09:44 +02:00
LemonBoy
bef140c0a2 stage1: Add architecture-specific clobbers to asm()
We're basically following Clang's lead, add the necessary clobbers to
minimize the risk of generating wrong code.
2020-11-18 13:08:04 +02:00
Veikka Tuominen
1e1a490600 Merge pull request #7084 from xackus/mem-volatile
std.mem: make sliceAsBytes, etc. respect volatile
2020-11-18 13:06:35 +02:00
xackus
27b73cc395 std: make meta.IntType a compile error
the function signature changed
also update langref
2020-11-18 12:57:49 +02:00
Jakub Konka
39336fd2e9 stage2 aarch64: assert register is 64bits in PCrel
Thanks @joachimschmidt557 for pointing out this fix!
2020-11-18 10:12:39 +01:00
Jakub Konka
5ff8dd179e stage2 aarch64: add PC relative address instructions 2020-11-18 08:46:52 +01:00
g-w1
a0226ab05b std: openDirAbsolute and accessAbsolute (#7082)
* add more abosolutes

* added wrong files

* adding 2 tests and changing the function signatures because of lazy analysis not checking them

* fix a bug that got uncovered by lazy eval

* Add compile error when using WASI with openDirAbsolute and accessAbsolute

* typo
2020-11-18 08:42:35 +01:00
Andrew Kelley
238718b93a disable the flaky ResetEvent test
See #7009
2020-11-17 18:08:10 -07:00
Frank Denis
9c2b014ea8 std/crypto: use NAF for multi-scalar edwards25519 multiplication
Transforming scalars to non-adjacent form shrinks the number of
precomputations down to 8, while still processing 4 bits at a time.

However, real-world benchmarks show that the transform is only
really useful with large precomputation tables and for batch
signature verification. So, do it for batch verification only.
2020-11-17 17:07:32 -08:00
Frank Denis
0d9c474ecf std/crypto: implement the Hash-To-Curve standard for Edwards25519
https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve

This is quite an important feature to have since many other standards
being worked on depend on this operation.

Brings a couple useful arithmetic operations on field elements by the way.

This PR also adds comments to the functions we expose in 25519/field
so that they can appear in the generated documentation.
2020-11-17 17:06:38 -08:00
LemonBoy
fa27420b72 stage1: Fix asyncCall with non-abi-aligned arguments
Make the code used to calculate the variable slot index into the frame
match what's done during the structure layout calculation.

Prevents a few nasty LLVM errors when such types are passed around.
2020-11-17 15:55:12 -08:00
Andrew Kelley
af4727814b cli: make -h, --help consistent in usage text and parsing
also trivial fixes in the general usage text
2020-11-17 16:53:45 -07:00
Felix (xq) Queißner
b3af2f68b3 Changes behaviour from std.fs.path.extension from returning null to returning "". 2020-11-18 00:03:34 +01:00
Vexu
bace1181b2 stage2: handle opaque containers 2020-11-18 00:52:56 +02:00
Andrew Kelley
2eee0582f8 macOS libc headers: downgrade to 10.15.7 (Catalina)
See ziglang/fetch-them-macos-headers#2 for more details. The path
forward looks like one of the following:

 * Ony provide headers for the oldest supported macOS (currently 10.13
   but soon to be bumped to 10.14).
 * Provide headers for multiple versions, and select based on the Zig
   target OS version range minimum.
 * Don't try to provide macOS headers.

If we don't tackle the version problem, we would have to re-introduce
the ability to detect and depend on native system headers if we wanted
to support C/C++ code that used newer OS definitions.

This patch also adds support for `#include <mach/mach_time.h>`.

Also related: #5236
2020-11-17 11:40:24 -08:00
Vexu
c1e19f4c0a stage2: initial container astgen 2020-11-17 21:19:49 +02:00
Alexandros Naskos
21a77f7ac3 Merge pull request #7032 from GuoxinYin/master
Add -h alias for --help
2020-11-17 15:52:39 +02:00
data-man
86b86bef23 Added links to the relevant issue 2020-11-17 14:41:05 +05:00
Andrew Kelley
e6bfa377d1 std.crypto.isap: fix callsites of secureZero 2020-11-16 18:10:41 -07:00
Andrew Kelley
8b3c1ed734 Merge branch 'johnLate-issue-6724-cmake' into master
closes #7078
closes #6724
2020-11-16 18:03:06 -07:00
Andrew Kelley
3348cb915f cmake: add the correct set of zig stage2 sources 2020-11-16 17:57:22 -07:00
johnLate
77d67aa662 CMake: try to avoid compilation for install target
This is andrewrk's patch from ziglang#6724 (rebased)

CMake: Fix dependency problem

I don't know whether the error was expected cmake behavior or a bug.
This change seems to fix the issue. See ziglang#6724 for details.
2020-11-16 17:45:13 -07:00
Frank Denis
f9d209787b std/crypto: add ISAPv2 (ISAP-A-128a) AEAD
We currently have ciphers optimized for performance, for
compatibility, for size and for specific CPUs.

However we lack a class of ciphers that is becoming increasingly
important, as Zig is being used for embedded systems, but also as
hardware-level side channels keep being found on (Intel) CPUs.

Here is ISAPv2, a construction specifically designed for resilience
against leakage and fault attacks.

ISAPv2 is obviously not optimized for performance, but can be an
option for highly sensitive data, when the runtime environment cannot
be trusted.
2020-11-16 16:02:19 -08:00
Jonathan Marler
4df75645ce start.zig: call wWinMain with root's type
I have an alternative set of windows bindings I'm working on: https://github.com/marler8997/zig-os-windows.  So I'm declaring my wWinMain function with my own HINSTANCE type rather than the one from std.os.windows.  This change allows start to call wWinMain using any pointer type.
2020-11-16 16:01:18 -08:00
tgschultz
48d60834fd Move leb128 and remove trivial *mem functions as discussed in #5588 (#6876)
* Move leb128 out of debug and remove trivial *mem functions as discussed in #5588

* Turns out one of the *Mem functions was used by MachO. Replaced with trivial use of FixedBufferStream.
2020-11-16 18:51:54 -05:00
Andrew Kelley
d9c36cb250 Merge pull request #6878 from frmdstryr/multiline-string-comments
Support comments in multiline string literals
2020-11-16 14:05:15 -08:00
heidezomp
9ea4ddae97 linuxWaitFd: make NetworkSubsystemFailed error unreachable
This error from os.poll is Windows-specific, so unreachable on Linux.
2020-11-16 14:03:19 -08:00
Alex Cameron
a2582df5b2 Prevent double file close in MachO linking 2020-11-16 13:59:27 -08:00
Frank Denis
0c520cd32d Enable loop interleaving when unrolling is enabled
This mimics clang's default behavior.
2020-11-16 13:40:52 -08:00
Andrew Kelley
ba967ae9a1 Merge pull request #7002 from jedisct1/timingSafeEqlMinimal
Add mem.timingSafeEql() for constant-time array comparison
2020-11-16 13:39:31 -08:00
Jakub Konka
8f47e8feb6 stage2 aarch64: add NOP instruction 2020-11-16 13:37:38 -08:00
Jakub Konka
cd4b54fd38 libstd: add more MachO consts and structs 2020-11-16 13:37:07 -08:00
LemonBoy
36c869dc14 std: Make windows.ReadFile allow short reads
Make it behave like the read() wrapper for unix systems.
Reading the whole buffer breaks some use-cases like buffered readers
over sockets.

Closes #7121
2020-11-16 13:35:06 -08:00
xackus
109a3ebcca std.mem: make args comptime, fix test names 2020-11-16 12:50:05 +01:00
Alexandros Naskos
6e2e747b0b Merge pull request #7112 from LemonBoy/fix-7104
stage1: Fix generation of pass-by-value args in async fns
2020-11-16 09:12:42 +02:00
Vexu
f173d078c7 stage2: outline container types 2020-11-15 13:03:48 +02:00
Frank Denis
7b9af0592d Azure Pipelines CI: update msys2 to the current version 2020-11-15 00:27:18 +01:00
LemonBoy
7ebbc717c0 stage1: Fix generation of pass-by-value args in async fns
The mismatch between the argument slot type in the frame structure and
the one used in the store operation made the generated code write
garbage over the nearby fields.

Fixes #7104
2020-11-14 15:30:06 +01:00
xackus
92e45ee3a1 std.mem: make sliceAsBytes, etc. respect volatile 2020-11-14 13:59:29 +01:00
xackus
c814fdbfaf std.mem: improve doc comments 2020-11-14 13:59:29 +01:00
Felix (xq) Queißner
0bbf170514 Adapts to @andrewrk​s comment to include dot. 2020-11-14 11:01:47 +01:00
Andrew Kelley
bf03ae7acc std.fs.path.dirname: return null when input path is root
This intentionally diverges from the unix dirname command, as well as
Python and Node.js standard libraries, which all have this edge case
return the input path, unmodified. This is a footgun, and nobody should
have ever done it this way.

Even the man page contradicts the behavior. It says:
"strip last component from file name". Now consider, if you
remove the last item from an array of length 1, then you
have now an array of length 0. After you strip the last component, there
should be no components remaining. Clearly, returning the input parameter
unmodified in this case does not match the documented behavior. This is
my justification for taking a stand on this API design.

closes #6746
closes #6727
closes #6584
closes #6592
closes #6602
2020-11-13 17:36:49 -07:00
LemonBoy
211feea914 stage1: Disambiguate Wasm imports with same name
Closes #7088
2020-11-13 16:32:42 -05:00
LemonBoy
c4fd3fc270 stage1: Resolve ErrorUnion children types
Since the code is accessing the abi_size field compute the full type
size for both err_set_type and payload_type, not only for the latter.
2020-11-13 14:28:40 -07:00
Sébastien Marie
ab4b34f75f openbsd: skip tests using Dir.realpath 2020-11-13 12:30:14 -05:00
LemonBoy
b52a28a802 stage1: Ask LLVM to produce compact code in ReleaseSize mode
Let's follow what Clang does for -Oz and apply the `minsize` and
`optsize` attributes by default.

Closes #7048
Supersedes #7077
2020-11-13 12:25:13 -05:00
Vexu
643f526cd1 stage2: add zir instructions for creating container types 2020-11-13 17:32:52 +02:00
Felix (xq) Queißner
2ced0316eb Makes @haze happy. 2020-11-13 13:54:41 +01:00
Felix (xq) Queißner
f51064f79e Respects leading . and ignores it. 2020-11-13 12:48:01 +01:00
Felix (xq) Queißner
2554273805 Implements std.fs.path.extension. 2020-11-13 11:53:51 +01:00
Jakub Konka
51717314e4 Merge pull request #6900 from joachimschmidt557/stage2-aarch64
Add stage2 AArch64 backend
2020-11-12 20:41:15 +01:00
joachimschmidt557
c6d46a9b82 stage2 ARM & AArch64: ensure correct function alignment 2020-11-12 16:24:51 +01:00
Andrew Kelley
2d42532fec main: clean up the error message for missing positional args 2020-11-11 19:35:07 -07:00
joachimschmidt557
b17859b568 stage2 AArch64: add Linux Hello World test 2020-11-11 23:29:18 +01:00
Hubert Jasudowicz
bf73db71f5 std: Fix code model argument 2020-11-11 21:28:10 +02:00
Veikka Tuominen
93844a5ef9 Merge pull request #7061 from Vexu/std
std: fix HashMap.putAssumeCapacity
2020-11-11 18:50:34 +02:00
Jakub Konka
5b92d0ea45 stage2 aarch64: add macOS incremental test 2020-11-11 15:36:47 +01:00
Vexu
08270d72b4 ensure TypeInfo payload is not undefined 2020-11-11 16:04:46 +02:00
g-w1
61c51f0ac9 Add error for missing positional arguments in zig build-*
Closes #6938
2020-11-11 15:54:08 +02:00
LemonBoy
5872ae5111 stage1: Fix crash in comptime struct generation
Using the gen_index rather than the src_index is needed to handle
structures containing zero-sized or comptime only types.

Closes #7027
2020-11-11 15:35:19 +02:00
Jakub Konka
a6bc19ea2a stage2 aarch64: add genCall for aarch64 MachO 2020-11-11 14:34:53 +01:00
Jakub Konka
993eb22a77 stage2 aarch64: add .memory prong in genSetReg 2020-11-11 14:34:53 +01:00
Jakub Konka
f512676d0b stage2 aarch64: add str instruction 2020-11-11 14:34:53 +01:00
Jakub Konka
f1960302d1 stage2 aarch64: add ldr instruction + smoke tests 2020-11-11 14:34:53 +01:00
joachimschmidt557
ca0016a225 stage2 ARM: start implementing genCall for ELF + genSetReg immediates 2020-11-11 14:34:53 +01:00
joachimschmidt557
aa9df72f71 stage2 AArch64: MoveWideImmediate instructions + test coverage 2020-11-11 14:34:53 +01:00
joachimschmidt557
4c8f69241a stage2 aarch64: add more instructions 2020-11-11 14:34:53 +01:00
joachimschmidt557
3c75d723ac stage2 aarch64: add codegen/aarch64.zig 2020-11-11 14:34:53 +01:00
Jakub Konka
4ef6864a15 Add move wide with zero (movz) instruction 2020-11-11 14:34:53 +01:00
Jakub Konka
d601b0f4eb Add basic genSetReg for aarch64 2020-11-11 14:34:53 +01:00
Jakub Konka
68bb1e91aa Add testcase for serializing svc #0x80 2020-11-11 14:34:53 +01:00
Jakub Konka
d542e88706 Implement genAsm on aarch64
Add remaining PCS info: param and return registers in procedure calls.
2020-11-11 14:34:53 +01:00
joachimschmidt557
5ad501c00b stage2 aarch64: add codegen/aarch64.zig 2020-11-11 14:34:53 +01:00
Jonas Carpay
c9dc30daf7 Fix backticked code in langref 2020-11-11 15:34:01 +02:00
Vexu
ae6f3291c0 std: fix HashMap.clearRetainingCapacity 2020-11-11 14:05:43 +02:00
Vexu
f70160f89c std: fix HashMap.putAssumeCapacity 2020-11-11 13:57:08 +02:00
LemonBoy
f0b1b74d21 stage1: Avoid resolving type entry in [0]T
The logic was already there but this rule was only applied in some
places, apply it in the remaining code paths.

Closes #7058
2020-11-11 13:53:24 +02:00
Andrew Kelley
8b9195282e Merge pull request #7044 from semarie/openbsd-simples
Simple sets of commits for OpenBSD support
2020-11-10 18:06:30 -05:00
Andrew Kelley
6904cd828e add missing -m<os>-version-min CLI args to clang
This fixes some code generation issues when targeting macOS and
compiling C/C++ code.
2020-11-10 15:24:10 -07:00
Andrew Kelley
3110b21c4b std.Target: bump default version max for macos 2020-11-10 15:24:10 -07:00
LemonBoy
4d4ab1e69a stage1: Fix comparison of unions containing zero-sized types
The code tried to be too smart and skipped the equality (returning true)
if the payload type was zero-sized.
This optimization is completely wrong when the union payload is a
metatype!

Fixes #7047
2020-11-10 17:21:49 -05:00
Sébastien Marie
678bd4fc89 "ResetEvent" test seems to have a too short timeout: the test is failing randomly on OpenBSD
raise the timeout to 100ms to be sure that if it fails (timeout is returned) it is due to a real problem.
the test shouldn't be longer: it will wait more time only on failure.
2020-11-10 05:29:53 +00:00
Sébastien Marie
9d306e5c77 openbsd: mutex or cond destroy function could return EINVAL 2020-11-10 05:26:35 +00:00
Sébastien Marie
8784c7b581 openbsd: proper implementation for Thread.cpuCount() 2020-11-10 05:25:59 +00:00
Sébastien Marie
20b19d0092 openbsd: add time definitions for gettimeofday() 2020-11-10 05:24:56 +00:00
Sébastien Marie
e4bc595bc6 openbsd: add sockets constants 2020-11-10 05:24:03 +00:00
Sébastien Marie
17276df488 openbsd: add dlfcn.h definitions for dlopen() 2020-11-10 05:23:13 +00:00
Andrew Kelley
06a3a69e6f main: updateModule returns an error when there are any compile errors
closes #6976
2020-11-09 20:51:09 -07:00
daurnimator
73f3f01670 Fix json parser close tracking (#6865)
* std: fix json parsing with unmatched closing tokens

* std: fix swapped json parsing errors
2020-11-09 18:29:02 -05:00
xackus
15dbab9a0c std: json: fix misleading endianness conversion 2020-11-09 18:27:07 -05:00
LemonBoy
e00356d6b1 stage1: Print correct error message for vector @intCast 2020-11-09 18:24:48 -05:00
Frank Denis
427a212e38 Don't prevent compilation on platforms where debug info is unsupported
We don't support debug information on platforms that are not tier-1,
but it shouldn't be a hard error that completely prevents compilation.
2020-11-09 18:22:50 -05:00
Alexandros Naskos
fc67e5f843 Windows TLS startup symbols are already provided by libcrt when linking against libc 2020-11-09 17:46:46 -05:00
Jakub Konka
0bc9fd5e8e Merge pull request #7035 from ziglang/macos-posix-headers
macOS libc headers: add POSIX headers
2020-11-09 23:41:55 +01:00
Andrew Kelley
83a1523b1a std.ResetEvent: disable flaky test on Windows
See #7009
2020-11-09 15:33:40 -07:00
Jakub Konka
db2ac8ae49 macOS libc headers: add objc/message.h and runtime.h 2020-11-09 19:57:07 +01:00
Jakub Konka
09cc61bfe4 Add more missing libc headers used by frameworks
See
76f22c3905.
2020-11-09 18:47:09 +01:00
Jakub Konka
267116d626 macOS libc headers: add mach/clock.h
LLVM depends on it.
2020-11-09 15:02:03 +01:00
data-man
99932042dc Fix reduce documentation 2020-11-09 11:47:43 +01:00
Andrew Kelley
9af53f8e02 langref: add 0.7.0 link 2020-11-09 00:37:35 -07:00
Andrew Kelley
e78e0f57be macos: avoid --export-dynamic when using system linker 2020-11-08 23:04:38 -08:00
Andrew Kelley
b0cbd0ad2d macos libc headers: add more
these new files are generated by recursively including:

sysexits.h
mach/mach.h
sys/attr.h
sys/mount.h
crt_externs.h
execinfo.h

all of which are depended on by LLVM libraries.
2020-11-08 21:12:18 -08:00
Andrew Kelley
cd221b9df9 macOS libc headers: add sys/sysctl.h
libcxx depends on it
2020-11-08 20:26:33 -08:00
Andrew Kelley
16b7be34a1 macOS libc headers: add sys/param.h
libcxx depends on it
2020-11-08 20:21:29 -08:00
Andrew Kelley
1213e26ba8 macOS libc headers: add mach-o/dyld.h
libcxx depends on it
2020-11-08 20:21:29 -08:00
Andrew Kelley
25e78bd007 add copyfile.h
libcxx depends on it
2020-11-08 20:21:29 -08:00
Andrew Kelley
fdd775b3bf macOS libc headers: add xlocale.h and Block.h
These are both included by libcxx.
2020-11-08 20:21:29 -08:00
Andrew Kelley
eed5814d75 macOS libc headers: add POSIX headers 2020-11-08 20:21:29 -08:00
Andrew Kelley
4d67c3d887 macOS: depend on bundled headers even for native
This is an alternate fix for #6773. Reverts
872bc787b5.
2020-11-08 18:51:12 -07:00
Alexandros Naskos
4236518e3a Merge pull request #7033 from jedisct1/bump0.7
Bump Zig version to 0.7.0
2020-11-09 00:52:51 +02:00
Frank Denis
9bc3442e41 Bump Zig version to 0.7.0 2020-11-08 23:50:44 +01:00
Guoxin Yin
7b8cb002cb fix issue 6798 2020-11-09 02:58:45 +08:00
Guoxin Yin
b6c85df55a fix issue 6798 2020-11-09 02:48:17 +08:00
Frank Denis
7f9e3e419c Use @reduce 2020-11-07 20:30:13 +01:00
Frank Denis
bd07154242 Add mem.timingSafeEql() for constant-time array comparison
This is a trivial implementation that just does a or[xor] loop.

However, this pattern is used by virtually all crypto libraries and
in practice, even without assembly barriers, LLVM never turns it into
code with conditional jumps, even if one of the parameters is constant.

This has been verified to still be the case with LLVM 11.0.0.
2020-11-07 20:18:43 +01:00
Josh Holland
a1ec5448c7 make ArrayList.span into a compile error 2020-11-07 11:15:47 +00:00
Josh Holland
c25b157dda remove deprecated uses of ArrayList.span 2020-11-07 11:15:44 +00:00
LemonBoy
53c1624074 std: Make utf8CountCodepoints much faster
Make the code easier for the optimizer to work with and introduce a fast
path for ASCII sequences.

Introduce a benchmark harness to start tracking the performance of ops
on utf8.
2020-11-05 16:10:34 +01:00
LemonBoy
3a1f515e09 Address review comments 2020-11-05 16:10:34 +01:00
LemonBoy
1982e0c18a Fix typo in documentation 2020-11-05 16:10:34 +01:00
LemonBoy
0316ac959c Make std.formatBuf UTF-8 aware 2020-11-05 16:10:34 +01:00
LemonBoy
675de8d6b7 Clean up the unicode codepoint formatter a bit 2020-11-05 16:10:34 +01:00
LemonBoy
44533f10fe std: Introduce std.unicode.utf8ValidCodepoint 2020-11-05 16:10:34 +01:00
LemonBoy
6c4efab106 std: Introduce std.unicode.utf8CountCodepoints 2020-11-05 16:10:33 +01:00
LemonBoy
2cce23062b Update the API and add add error-recovery path 2020-11-05 16:10:33 +01:00
data-man
678ecc94ca Add 'u' specifier to std.format 2020-11-05 16:10:33 +01:00
LemonBoy
e749ab1d63 Fix typo, remove debug leftover, rename few fns 2020-11-05 16:10:15 +01:00
LemonBoy
53433cdea2 Implement a fallback mechanism for posix_memalign
Do the alignment dance by ourselves whenever posix_memalign is not
available.
Don't try to use malloc as it has too many edge cases, figuring out
whether a block of memory is manually aligned by the mechanism above or
is directly coming from malloc becomes too hard to be valuable.
2020-11-05 16:10:15 +01:00
LemonBoy
4664eae1e4 stage1: Fix type mapping for c_longdouble
A quick and dirty job to let the compiler use the correct size and
alignment.
2020-11-05 16:10:15 +01:00
LemonBoy
806097c165 std: Make C allocator respect the required alignment
Use posix_memalign where available and the _aligned_{malloc,free} API on
Windows.

Closes #3783
2020-11-05 16:10:15 +01:00
data-man
df4fd94525 remove f128 tests, disable min/max for NaNs 2020-11-04 17:42:57 +05:00
data-man
ae73e0911d Remove min/max tests for NaNs 2020-11-02 20:40:41 +05:00
data-man
f0610d99f1 Add more tests for reduce 2020-11-02 16:48:59 +05:00
frmdstryr
1d22591299 Add tests and fix \n between comments 2020-10-30 11:20:16 -04:00
frmdstryr
5dd36ee6ce Add support for comments in multiline string literal 2020-10-30 10:52:30 -04:00
Rocknest
39841d5e2c remove workaround 2020-10-12 15:18:50 +03:00
Rocknest
47d7bf1a0e add a test for Version.parse 2020-10-11 16:30:51 +03:00
Rocknest
cd4200ccef make Version.parse less strict 2020-10-11 16:29:19 +03:00
daurnimator
4786eaedda test/standalone/cat: use fifo.pump() 2020-09-27 15:06:44 +10:00
daurnimator
cffab89730 test/standalone/cat: fix leaks 2020-09-27 15:06:31 +10:00
daurnimator
ed5c778c10 test/standalone/cat: update to new std library 2020-09-27 15:00:41 +10:00
daurnimator
a1abbb8eac std: add LinearFifo(...).pump(src_reader, dest_writer) 2020-09-27 14:43:44 +10:00
LemonBoy
333eec557f Initial support for static PIE executables 2019-12-21 17:34:05 +01:00
6502 changed files with 673200 additions and 134699 deletions

13
.gitattributes vendored
View File

@@ -3,9 +3,10 @@
langref.html.in text eol=lf
deps/SoftFloat-3e/*.txt text eol=crlf
deps/* linguist-vendored
lib/include/* linguist-vendored
lib/libc/* linguist-vendored
lib/libcxx/* linguist-vendored
lib/libcxxabi/* linguist-vendored
lib/libunwind/* linguist-vendored
deps/** linguist-vendored
lib/include/** linguist-vendored
lib/libc/** linguist-vendored
lib/libcxx/** linguist-vendored
lib/libcxxabi/** linguist-vendored
lib/libunwind/** linguist-vendored
lib/tsan/** linguist-vendored

3
.gitignore vendored
View File

@@ -10,6 +10,9 @@
# -andrewrk
zig-cache/
zig-out/
/release/
/debug/
/build/
/build-*/
/docgen_tmp/

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.5)
cmake_minimum_required(VERSION 2.8.12)
# Use ccache if possible
FIND_PROGRAM(CCACHE_PROGRAM ccache)
@@ -25,8 +25,8 @@ project(zig C CXX)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(ZIG_VERSION_MAJOR 0)
set(ZIG_VERSION_MINOR 7)
set(ZIG_VERSION_PATCH 0)
set(ZIG_VERSION_MINOR 8)
set(ZIG_VERSION_PATCH 1)
set(ZIG_VERSION "" CACHE STRING "Override Zig version string. Default is to find out with git.")
if("${ZIG_VERSION}" STREQUAL "")
@@ -34,18 +34,31 @@ if("${ZIG_VERSION}" STREQUAL "")
find_program(GIT_EXE NAMES git)
if(GIT_EXE)
execute_process(
COMMAND ${GIT_EXE} -C ${CMAKE_SOURCE_DIR} name-rev HEAD --tags --name-only --no-undefined --always
COMMAND ${GIT_EXE} -C ${CMAKE_SOURCE_DIR} describe --match *.*.* --tags
RESULT_VARIABLE EXIT_STATUS
OUTPUT_VARIABLE ZIG_GIT_REV
OUTPUT_VARIABLE GIT_DESCRIBE
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)
if(EXIT_STATUS EQUAL "0")
if(ZIG_GIT_REV MATCHES "\\^0$")
if(NOT("${ZIG_GIT_REV}" STREQUAL "${ZIG_VERSION}^0"))
message("WARNING: Tag does not match configured Zig version")
if(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)$")
# Tagged release version.
set(GIT_TAG ${CMAKE_MATCH_1})
if(NOT GIT_TAG VERSION_EQUAL ZIG_VERSION)
message(SEND_ERROR "Zig version (${ZIG_VERSION}) does not match Git tag (${GIT_TAG}).")
endif()
elseif(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-g(.+)$")
# Untagged pre-release. The Zig version is updated to include the number of commits
# since the last tagged version and the commit hash. The version is formatted in
# accordance with the https://semver.org specification.
set(GIT_TAG ${CMAKE_MATCH_1})
set(GIT_COMMITS_AFTER_TAG ${CMAKE_MATCH_2})
set(GIT_COMMIT ${CMAKE_MATCH_3})
if(NOT ZIG_VERSION VERSION_GREATER GIT_TAG)
message(SEND_ERROR "Zig version (${ZIG_VERSION}) must be greater than tagged ancestor (${GIT_TAG}).")
endif()
set(ZIG_VERSION "${ZIG_VERSION}-dev.${GIT_COMMITS_AFTER_TAG}+${GIT_COMMIT}")
else()
set(ZIG_VERSION "${ZIG_VERSION}+${ZIG_GIT_REV}")
message(WARNING "Failed to parse version from output of `git describe`.")
endif()
endif()
endif()
@@ -54,6 +67,7 @@ message("Configuring zig version ${ZIG_VERSION}")
set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
set(ZIG_STATIC_ZLIB off CACHE BOOL "Prefer linking against static zlib")
set(ZIG_PREFER_CLANG_CPP_DYLIB off CACHE BOOL "Try to link against -lclang-cpp")
set(ZIG_USE_CCACHE off CACHE BOOL "Use ccache if available")
@@ -62,10 +76,8 @@ if(CCACHE_PROGRAM AND ZIG_USE_CCACHE)
endif()
if(ZIG_STATIC)
set(ZIG_STATIC_LLVM "on")
set(ZIG_LINK_MODE "Static")
else()
set(ZIG_LINK_MODE "Dynamic")
set(ZIG_STATIC_LLVM ON)
set(ZIG_STATIC_ZLIB ON)
endif()
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_LIB_DIR_ESCAPED "${ZIG_LIBC_LIB_DIR}")
@@ -77,17 +89,27 @@ option(ZIG_TEST_COVERAGE "Build Zig with test coverage instrumentation" OFF)
set(ZIG_TARGET_TRIPLE "native" CACHE STRING "arch-os-abi to output binaries for")
set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries for")
set(ZIG_EXECUTABLE "" CACHE STRING "(when cross compiling) path to already-built zig binary")
set(ZIG_PREFER_LLVM_CONFIG off CACHE BOOL "(when cross compiling) use llvm-config to find target llvm dependencies if needed")
set(ZIG_SINGLE_THREADED off CACHE BOOL "limit the zig compiler to use only 1 thread")
set(ZIG_OMIT_STAGE2 off CACHE BOOL "omit the stage2 backend from stage1")
set(ZIG_ENABLE_LOGGING off CACHE BOOL "enable logging")
if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")
set(ZIG_USE_LLVM_CONFIG ON CACHE BOOL "use llvm-config to find LLVM libraries")
else()
set(ZIG_USE_LLVM_CONFIG OFF CACHE BOOL "use llvm-config to find LLVM libraries")
endif()
find_package(llvm)
find_package(clang)
find_package(lld)
if(APPLE AND ZIG_STATIC)
if(ZIG_STATIC_ZLIB)
list(REMOVE_ITEM LLVM_LIBRARIES "-lz")
find_library(ZLIB NAMES libz.a z zlib libz)
find_library(ZLIB NAMES libz.a libzlibstatic.a z zlib libz)
list(APPEND LLVM_LIBRARIES "${ZLIB}")
endif()
if(APPLE AND ZIG_STATIC)
list(REMOVE_ITEM LLVM_LIBRARIES "-lcurses")
find_library(CURSES NAMES libcurses.a curses libcurses libncurses.a ncurses libncurses)
list(APPEND LLVM_LIBRARIES "${CURSES}")
@@ -258,6 +280,15 @@ set(SOFTFLOAT_LIBRARIES embedded_softfloat)
find_package(Threads)
set(ZIG_LIB_DIR "lib/zig")
set(C_HEADERS_DEST "${ZIG_LIB_DIR}/include")
set(LIBC_FILES_DEST "${ZIG_LIB_DIR}/libc")
set(LIBUNWIND_FILES_DEST "${ZIG_LIB_DIR}/libunwind")
set(LIBCXX_FILES_DEST "${ZIG_LIB_DIR}/libcxx")
set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")
set(ZIG_CONFIG_H_OUT "${CMAKE_BINARY_DIR}/config.h")
set(ZIG_CONFIG_ZIG_OUT "${CMAKE_BINARY_DIR}/config.zig")
# This is our shim which will be replaced by stage1.zig.
set(ZIG0_SOURCES
"${CMAKE_SOURCE_DIR}/src/stage1/zig0.cpp"
@@ -265,7 +296,7 @@ set(ZIG0_SOURCES
set(STAGE1_SOURCES
"${CMAKE_SOURCE_DIR}/src/stage1/analyze.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/ast_render.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/astgen.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/bigfloat.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/bigint.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/buffer.cpp"
@@ -280,11 +311,11 @@ set(STAGE1_SOURCES
"${CMAKE_SOURCE_DIR}/src/stage1/os.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/parser.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/range_set.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/softfloat_ext.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/stage1.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/target.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/tokenizer.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/util.cpp"
"${CMAKE_SOURCE_DIR}/src/stage1/softfloat_ext.cpp"
)
set(OPTIMIZED_C_SOURCES
"${CMAKE_SOURCE_DIR}/src/stage1/parse_f128.c"
@@ -292,6 +323,7 @@ set(OPTIMIZED_C_SOURCES
set(ZIG_CPP_SOURCES
# These are planned to stay even when we are self-hosted.
"${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp"
"${CMAKE_SOURCE_DIR}/src/zig_llvm-ar.cpp"
"${CMAKE_SOURCE_DIR}/src/zig_clang.cpp"
"${CMAKE_SOURCE_DIR}/src/zig_clang_driver.cpp"
"${CMAKE_SOURCE_DIR}/src/zig_clang_cc1_main.cpp"
@@ -299,6 +331,277 @@ set(ZIG_CPP_SOURCES
# https://github.com/ziglang/zig/issues/6363
"${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp"
)
# Needed because we use cmake, not the zig build system, to build zig1.o.
# This list is generated by building zig and then clearing the zig-cache directory,
# then manually running the build-obj command (see BUILD_ZIG1_ARGS), and then looking
# in the zig-cache directory for the compiler-generated list of zig file dependencies.
set(ZIG_STAGE2_SOURCES
"${ZIG_CONFIG_ZIG_OUT}"
"${CMAKE_SOURCE_DIR}/lib/std/array_hash_map.zig"
"${CMAKE_SOURCE_DIR}/lib/std/array_list.zig"
"${CMAKE_SOURCE_DIR}/lib/std/ascii.zig"
"${CMAKE_SOURCE_DIR}/lib/std/atomic.zig"
"${CMAKE_SOURCE_DIR}/lib/std/atomic/Atomic.zig"
"${CMAKE_SOURCE_DIR}/lib/std/atomic/queue.zig"
"${CMAKE_SOURCE_DIR}/lib/std/atomic/stack.zig"
"${CMAKE_SOURCE_DIR}/lib/std/base64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/buf_map.zig"
"${CMAKE_SOURCE_DIR}/lib/std/builtin.zig"
"${CMAKE_SOURCE_DIR}/lib/std/c.zig"
"${CMAKE_SOURCE_DIR}/lib/std/c/linux.zig"
"${CMAKE_SOURCE_DIR}/lib/std/c/tokenizer.zig"
"${CMAKE_SOURCE_DIR}/lib/std/child_process.zig"
"${CMAKE_SOURCE_DIR}/lib/std/coff.zig"
"${CMAKE_SOURCE_DIR}/lib/std/comptime_string_map.zig"
"${CMAKE_SOURCE_DIR}/lib/std/crypto.zig"
"${CMAKE_SOURCE_DIR}/lib/std/crypto/blake3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/crypto/siphash.zig"
"${CMAKE_SOURCE_DIR}/lib/std/debug.zig"
"${CMAKE_SOURCE_DIR}/lib/std/dwarf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/dwarf_bits.zig"
"${CMAKE_SOURCE_DIR}/lib/std/elf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/event.zig"
"${CMAKE_SOURCE_DIR}/lib/std/event/batch.zig"
"${CMAKE_SOURCE_DIR}/lib/std/event/loop.zig"
"${CMAKE_SOURCE_DIR}/lib/std/fifo.zig"
"${CMAKE_SOURCE_DIR}/lib/std/fmt.zig"
"${CMAKE_SOURCE_DIR}/lib/std/fmt/errol.zig"
"${CMAKE_SOURCE_DIR}/lib/std/fmt/errol/enum3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/fmt/errol/lookup.zig"
"${CMAKE_SOURCE_DIR}/lib/std/fmt/parse_float.zig"
"${CMAKE_SOURCE_DIR}/lib/std/fs.zig"
"${CMAKE_SOURCE_DIR}/lib/std/fs/file.zig"
"${CMAKE_SOURCE_DIR}/lib/std/fs/get_app_data_dir.zig"
"${CMAKE_SOURCE_DIR}/lib/std/fs/path.zig"
"${CMAKE_SOURCE_DIR}/lib/std/hash.zig"
"${CMAKE_SOURCE_DIR}/lib/std/hash/auto_hash.zig"
"${CMAKE_SOURCE_DIR}/lib/std/hash/wyhash.zig"
"${CMAKE_SOURCE_DIR}/lib/std/hash_map.zig"
"${CMAKE_SOURCE_DIR}/lib/std/heap.zig"
"${CMAKE_SOURCE_DIR}/lib/std/heap/arena_allocator.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/buffered_atomic_file.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/buffered_writer.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/change_detection_stream.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/counting_reader.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/counting_writer.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/find_byte_writer.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/fixed_buffer_stream.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/limited_reader.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/reader.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/seekable_stream.zig"
"${CMAKE_SOURCE_DIR}/lib/std/io/writer.zig"
"${CMAKE_SOURCE_DIR}/lib/std/json.zig"
"${CMAKE_SOURCE_DIR}/lib/std/json/write_stream.zig"
"${CMAKE_SOURCE_DIR}/lib/std/leb128.zig"
"${CMAKE_SOURCE_DIR}/lib/std/linked_list.zig"
"${CMAKE_SOURCE_DIR}/lib/std/log.zig"
"${CMAKE_SOURCE_DIR}/lib/std/macho.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/big.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/big/int.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/floor.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/frexp.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/inf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/isinf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/isnan.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/ln.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/log.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/log10.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/log2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/nan.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/signbit.zig"
"${CMAKE_SOURCE_DIR}/lib/std/math/sqrt.zig"
"${CMAKE_SOURCE_DIR}/lib/std/mem.zig"
"${CMAKE_SOURCE_DIR}/lib/std/mem/Allocator.zig"
"${CMAKE_SOURCE_DIR}/lib/std/meta.zig"
"${CMAKE_SOURCE_DIR}/lib/std/meta/trailer_flags.zig"
"${CMAKE_SOURCE_DIR}/lib/std/meta/trait.zig"
"${CMAKE_SOURCE_DIR}/lib/std/multi_array_list.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/errno-generic.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/netlink.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/prctl.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/securebits.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/bits/linux/x86_64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/io_uring.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/linux/x86_64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/windows.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/bits.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/ntstatus.zig"
"${CMAKE_SOURCE_DIR}/lib/std/os/windows/win32error.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Progress.zig"
"${CMAKE_SOURCE_DIR}/lib/std/pdb.zig"
"${CMAKE_SOURCE_DIR}/lib/std/process.zig"
"${CMAKE_SOURCE_DIR}/lib/std/rand.zig"
"${CMAKE_SOURCE_DIR}/lib/std/sort.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/addXf3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/atomics.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/clear_cache.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/clzsi2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/compareXf2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divdf3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divsf3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divtf3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/divti3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/extendXfYf2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixdfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixdfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixdfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixint.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixsfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixsfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixsfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixtfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixtfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixtfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixuint.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunsdfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunsdfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunsdfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunssfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunssfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunssfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunstfdi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunstfsi.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/fixunstfti.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatXisf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatdidf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatditf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatsiXf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floattidf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floattitf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatundidf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatundisf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatunditf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatunsidf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatunsisf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatunsitf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatuntidf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatuntisf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/floatuntitf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/int.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/modti3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/mulXf3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/muldi3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/mulodi4.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/muloti4.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/multi3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/negXf2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/popcountdi2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/shift.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/stack_probe.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/truncXfYf2.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/udivmod.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/udivmodti4.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/udivti3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt/umodti3.zig"
"${CMAKE_SOURCE_DIR}/lib/std/start.zig"
"${CMAKE_SOURCE_DIR}/lib/std/std.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/aarch64.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/amdgpu.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/arm.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/avr.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/bpf.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/hexagon.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/mips.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/msp430.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/nvptx.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/powerpc.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/riscv.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/sparc.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/systemz.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/wasm.zig"
"${CMAKE_SOURCE_DIR}/lib/std/target/x86.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/AutoResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/Mutex.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/ResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/Thread/StaticResetEvent.zig"
"${CMAKE_SOURCE_DIR}/lib/std/time.zig"
"${CMAKE_SOURCE_DIR}/lib/std/unicode.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/ast.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/cross_target.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/parse.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/render.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/string_literal.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/system.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/system/x86.zig"
"${CMAKE_SOURCE_DIR}/lib/std/zig/tokenizer.zig"
"${CMAKE_SOURCE_DIR}/src/Cache.zig"
"${CMAKE_SOURCE_DIR}/src/Compilation.zig"
"${CMAKE_SOURCE_DIR}/src/DepTokenizer.zig"
"${CMAKE_SOURCE_DIR}/src/Module.zig"
"${CMAKE_SOURCE_DIR}/src/Package.zig"
"${CMAKE_SOURCE_DIR}/src/RangeSet.zig"
"${CMAKE_SOURCE_DIR}/src/ThreadPool.zig"
"${CMAKE_SOURCE_DIR}/src/TypedValue.zig"
"${CMAKE_SOURCE_DIR}/src/WaitGroup.zig"
"${CMAKE_SOURCE_DIR}/src/AstGen.zig"
"${CMAKE_SOURCE_DIR}/src/clang.zig"
"${CMAKE_SOURCE_DIR}/src/clang_options.zig"
"${CMAKE_SOURCE_DIR}/src/clang_options_data.zig"
"${CMAKE_SOURCE_DIR}/src/codegen.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/aarch64.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/arm.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/c.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/llvm.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/llvm/bindings.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/riscv64.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/wasm.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/x86_64.zig"
"${CMAKE_SOURCE_DIR}/src/glibc.zig"
"${CMAKE_SOURCE_DIR}/src/introspect.zig"
"${CMAKE_SOURCE_DIR}/src/air.zig"
"${CMAKE_SOURCE_DIR}/src/libc_installation.zig"
"${CMAKE_SOURCE_DIR}/src/libcxx.zig"
"${CMAKE_SOURCE_DIR}/src/libtsan.zig"
"${CMAKE_SOURCE_DIR}/src/libunwind.zig"
"${CMAKE_SOURCE_DIR}/src/link.zig"
"${CMAKE_SOURCE_DIR}/src/link/C.zig"
"${CMAKE_SOURCE_DIR}/src/link/Coff.zig"
"${CMAKE_SOURCE_DIR}/src/link/Elf.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Archive.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/CodeSignature.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/DebugSymbols.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Dylib.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Object.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Symbol.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Trie.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Zld.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/bind.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/commands.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/reloc.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/reloc/aarch64.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/reloc/x86_64.zig"
"${CMAKE_SOURCE_DIR}/src/link/Wasm.zig"
"${CMAKE_SOURCE_DIR}/src/link/C/zig.h"
"${CMAKE_SOURCE_DIR}/src/link/msdos-stub.bin"
"${CMAKE_SOURCE_DIR}/src/liveness.zig"
"${CMAKE_SOURCE_DIR}/src/main.zig"
"${CMAKE_SOURCE_DIR}/src/mingw.zig"
"${CMAKE_SOURCE_DIR}/src/musl.zig"
"${CMAKE_SOURCE_DIR}/src/print_env.zig"
"${CMAKE_SOURCE_DIR}/src/print_targets.zig"
"${CMAKE_SOURCE_DIR}/src/stage1.zig"
"${CMAKE_SOURCE_DIR}/src/target.zig"
"${CMAKE_SOURCE_DIR}/src/tracy.zig"
"${CMAKE_SOURCE_DIR}/src/translate_c.zig"
"${CMAKE_SOURCE_DIR}/src/translate_c/ast.zig"
"${CMAKE_SOURCE_DIR}/src/type.zig"
"${CMAKE_SOURCE_DIR}/src/value.zig"
"${CMAKE_SOURCE_DIR}/src/wasi_libc.zig"
"${CMAKE_SOURCE_DIR}/src/windows_sdk.zig"
"${CMAKE_SOURCE_DIR}/src/Zir.zig"
"${CMAKE_SOURCE_DIR}/src/Sema.zig"
)
if(MSVC)
set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
@@ -308,14 +611,18 @@ if(MSVC)
endif()
endif()
set(ZIG_LIB_DIR "lib/zig")
set(C_HEADERS_DEST "${ZIG_LIB_DIR}/include")
set(LIBC_FILES_DEST "${ZIG_LIB_DIR}/libc")
set(LIBUNWIND_FILES_DEST "${ZIG_LIB_DIR}/libunwind")
set(LIBCXX_FILES_DEST "${ZIG_LIB_DIR}/libcxx")
set(ZIG_STD_DEST "${ZIG_LIB_DIR}/std")
set(ZIG_CONFIG_H_OUT "${CMAKE_BINARY_DIR}/config.h")
set(ZIG_CONFIG_ZIG_OUT "${CMAKE_BINARY_DIR}/config.zig")
if(ZIG_OMIT_STAGE2)
set(ZIG_OMIT_STAGE2_BOOL "true")
else()
set(ZIG_OMIT_STAGE2_BOOL "false")
endif()
if(ZIG_ENABLE_LOGGING)
set(ZIG_ENABLE_LOGGING_BOOL "true")
else()
set(ZIG_ENABLE_LOGGING_BOOL "false")
endif()
configure_file (
"${CMAKE_SOURCE_DIR}/src/stage1/config.h.in"
"${ZIG_CONFIG_H_OUT}"
@@ -339,6 +646,12 @@ else(MSVC)
set(EXE_CFLAGS "-std=c++14")
endif(MSVC)
if(ZIG_STATIC)
set(EXE_CFLAGS "${EXE_CFLAGS} -DZIG_LINK_MODE=Static")
else()
set(EXE_CFLAGS "${EXE_CFLAGS} -DZIG_LINK_MODE=Dynamic")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
if(MSVC)
set(EXE_CFLAGS "${EXE_CFLAGS} /w")
@@ -348,6 +661,10 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0)
set(EXE_CFLAGS "${EXE_CFLAGS} -Werror=implicit-fallthrough")
endif()
# GCC 9.2 and older are unable to detect valid variable initialization in some cases
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS_EQUAL 9.2)
set(EXE_CFLAGS "${EXE_CFLAGS} -Wno-maybe-uninitialized")
endif()
endif()
endif()
@@ -434,12 +751,14 @@ if(MSVC OR MINGW)
target_link_libraries(zigstage1 LINK_PUBLIC version)
endif()
add_executable(zig0 ${ZIG0_SOURCES})
set_target_properties(zig0 PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
LINK_FLAGS ${EXE_LDFLAGS}
)
target_link_libraries(zig0 zigstage1)
if("${ZIG_EXECUTABLE}" STREQUAL "")
add_executable(zig0 ${ZIG0_SOURCES})
set_target_properties(zig0 PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
LINK_FLAGS ${EXE_LDFLAGS}
)
target_link_libraries(zig0 zigstage1)
endif()
if(MSVC)
set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.obj")
@@ -451,6 +770,11 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
else()
set(ZIG1_RELEASE_ARG -OReleaseFast --strip)
endif()
if(ZIG_SINGLE_THREADED)
set(ZIG1_SINGLE_THREADED_ARG "--single-threaded")
else()
set(ZIG1_SINGLE_THREADED_ARG "")
endif()
set(BUILD_ZIG1_ARGS
"src/stage1.zig"
@@ -460,6 +784,7 @@ set(BUILD_ZIG1_ARGS
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-femit-bin=${ZIG1_OBJECT}"
"${ZIG1_RELEASE_ARG}"
"${ZIG1_SINGLE_THREADED_ARG}"
-lc
--pkg-begin build_options "${ZIG_CONFIG_ZIG_OUT}"
--pkg-end
@@ -468,10 +793,10 @@ set(BUILD_ZIG1_ARGS
)
if("${ZIG_EXECUTABLE}" STREQUAL "")
add_custom_target(zig_build_zig1 ALL
add_custom_command(
OUTPUT "${ZIG1_OBJECT}"
COMMAND zig0 ${BUILD_ZIG1_ARGS}
DEPENDS zig0
BYPRODUCTS "${ZIG1_OBJECT}"
DEPENDS zig0 "${ZIG_STAGE2_SOURCES}"
COMMENT STATUS "Building self-hosted component ${ZIG1_OBJECT}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
@@ -480,56 +805,57 @@ if("${ZIG_EXECUTABLE}" STREQUAL "")
set(ZIG_EXECUTABLE "${ZIG_EXECUTABLE}.exe")
endif()
else()
add_custom_target(zig_build_zig1 ALL
add_custom_command(
OUTPUT "${ZIG1_OBJECT}"
COMMAND "${ZIG_EXECUTABLE}" "build-obj" ${BUILD_ZIG1_ARGS}
BYPRODUCTS "${ZIG1_OBJECT}"
DEPENDS ${ZIG_STAGE2_SOURCES}
COMMENT STATUS "Building self-hosted component ${ZIG1_OBJECT}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
endif()
# cmake won't let us configure an executable without C sources.
add_executable(zig "${CMAKE_SOURCE_DIR}/src/stage1/empty.cpp")
add_executable(zig "${CMAKE_SOURCE_DIR}/src/stage1/empty.cpp" "${ZIG1_OBJECT}")
set_target_properties(zig PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
LINK_FLAGS ${EXE_LDFLAGS}
)
target_link_libraries(zig "${ZIG1_OBJECT}" zigstage1)
target_link_libraries(zig zigstage1)
if(MSVC)
target_link_libraries(zig ntdll.lib)
elseif(MINGW)
target_link_libraries(zig ntdll)
endif()
add_dependencies(zig zig_build_zig1)
install(TARGETS zig DESTINATION bin)
set(ZIG_INSTALL_ARGS "build"
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-Dlib-files-only"
--prefix "${CMAKE_INSTALL_PREFIX}"
"-Dconfig_h=${ZIG_CONFIG_H_OUT}"
install
)
set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL
"Disable copying lib/ files to install prefix during the build phase")
# CODE has no effect with Visual Studio build system generator, therefore
# when using Visual Studio build system generator we resort to running
# `zig build install` during the build phase.
if(MSVC)
set(ZIG_SKIP_INSTALL_LIB_FILES off CACHE BOOL
"Windows-only: Disable copying lib/ files to install prefix during the build phase")
if(NOT ZIG_SKIP_INSTALL_LIB_FILES)
if(NOT ZIG_SKIP_INSTALL_LIB_FILES)
set(ZIG_INSTALL_ARGS "build"
--override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-Dlib-files-only"
--prefix "${CMAKE_INSTALL_PREFIX}"
"-Dconfig_h=${ZIG_CONFIG_H_OUT}"
install
)
# CODE has no effect with Visual Studio build system generator, therefore
# when using Visual Studio build system generator we resort to running
# `zig build install` during the build phase.
if(MSVC)
add_custom_target(zig_install_lib_files ALL
COMMAND zig ${ZIG_INSTALL_ARGS}
DEPENDS zig
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
)
else()
get_target_property(zig_BINARY_DIR zig BINARY_DIR)
install(CODE "set(zig_EXE \"${ZIG_EXECUTABLE}\")")
install(CODE "set(ZIG_INSTALL_ARGS \"${ZIG_INSTALL_ARGS}\")")
install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")")
install(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.cmake)
endif()
else()
get_target_property(zig_BINARY_DIR zig BINARY_DIR)
install(CODE "set(zig_EXE \"${ZIG_EXECUTABLE}\")")
install(CODE "set(ZIG_INSTALL_ARGS \"${ZIG_INSTALL_ARGS}\")")
install(CODE "set(CMAKE_SOURCE_DIR \"${CMAKE_SOURCE_DIR}\")")
install(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/cmake/install.cmake)
endif()

View File

@@ -9,7 +9,7 @@ a link. There is no concept of "official" or "unofficial", however, each
gathering place has its own moderators and rules.
This is Andrew Kelley speaking. At least for now, I'm the moderator of the
ziglang organization GitHub repositories and the #zig IRC channel on Freenode.
ziglang organization GitHub repositories and the #zig IRC channel on Libera.chat.
**This document contains the rules that govern these two spaces only**.
The rules here are strict. This space is for focused, on topic, technical work

View File

@@ -7,7 +7,10 @@ personal project. Here are some great examples:
* [Oxid](https://github.com/dbandstra/oxid) - arcade style game
* [TM35-Metronome](https://github.com/TM35-Metronome) - tools for modifying and randomizing Pokémon games
* [trOS](https://github.com/sjdh02/trOS) - tiny aarch64 baremetal OS thingy
* [River](https://github.com/ifreund/river/) - a dynamic tiling wayland compositor
More examples can be found on the
[Community Projects Wiki](https://github.com/ziglang/zig/wiki/Community-Projects).
Without fail, these projects lead to discovering bugs and helping flesh out use
cases, which lead to further design iterations of Zig. Importantly, each issue
@@ -51,7 +54,8 @@ knowledge of Zig internals.**
### Editing Source Code
First, build the Stage 1 compiler as described in [Building from Source](README.md#Building-from-Source).
First, build the Stage 1 compiler as described in
[Building Zig From Source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source).
Zig locates lib files relative to executable path by searching up the
filesystem tree for a sub-path of `lib/zig/std/std.zig` or `lib/std/std.zig`.
@@ -129,6 +133,14 @@ This will enable running behavior tests and std lib tests with Wine. It's
recommended for Linux users to install Wine and enable this testing option
when editing the standard library or anything Windows-related.
#### Testing WebAssembly using wasmtime
If you have [wasmtime](https://wasmtime.dev/) installed, take advantage of the
`-Denable-wasmtime` flag which will enable running WASI behavior tests and std
lib tests. It's recommended for all users to install wasmtime and enable this
testing option when editing the standard library and especially anything
WebAssembly-related.
#### Improving Translate-C
Please read the [Editing Source Code](#editing-source-code) section as a
@@ -152,7 +164,7 @@ The relevant tests for this feature are:
same, and that the program exits cleanly. This kind of test coverage is preferred, when
possible, because it makes sure that the resulting Zig code is actually viable.
* `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
* `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
which checks that the relevant macros in `test/stage1/behavior/translate_c_macros.h`.
have the correct values. Macros have to be tested separately since they are expanded by
Clang in `run_translated_c` tests.
@@ -173,21 +185,21 @@ repo, we maintain a C API on top of Clang's C++ API:
Clang's C++ API changes. This one file necessarily does include Clang's C++ headers, which
makes it the slowest-to-compile source file in all of Zig's codebase.
* `src-self-hosted/clang.zig` - the Zig equivalent of `src/zig_clang.h`. This is a manually
* `src/clang.zig` - the Zig equivalent of `src/zig_clang.h`. This is a manually
maintained list of types and functions that are ABI-compatible with the Clang C API we
maintain. In theory this could be generated by running translate-c on `src/zig_clang.h`,
but that would introduce a dependency cycle, since we are using this file to implement
translate-c.
Finally, the actual source code for the translate-c feature is
`src-self-hosted/translate_c.zig`. This code uses the Clang C API exposed by
`src-self-hosted/clang.zig`, and produces Zig AST.
`src/translate_c.zig`. This code uses the Clang C API exposed by
`src/clang.zig`, and produces Zig AST.
The steps for contributing to translate-c look like this:
1. Identify a test case you want to improve. Add it as a run-translated-c test
case (usually preferable), or as a translate-c test case.
2. Edit `src-self-hosted/translate_c.zig` to improve the behavior.
2. Edit `src/translate_c.zig` to improve the behavior.
3. Run the relevant tests: `./zig build test-run-translated-c test-translate-c`

View File

@@ -1,6 +1,6 @@
The MIT License (Expat)
Copyright (c) 2015 Andrew Kelley
Copyright (c) 2015-2021, Zig contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -5,7 +5,7 @@ A general-purpose programming language and toolchain for maintaining
## Resources
* [Introduction](https://ziglang.org/#Introduction)
* [Introduction](https://ziglang.org/learn/#introduction)
* [Download & Documentation](https://ziglang.org/download)
* [Chapter 0 - Getting Started | ZigLearn.org](https://ziglearn.org/)
* [Community](https://github.com/ziglang/zig/wiki/Community)
@@ -14,98 +14,12 @@ A general-purpose programming language and toolchain for maintaining
* [Frequently Asked Questions](https://github.com/ziglang/zig/wiki/FAQ)
* [Community Projects](https://github.com/ziglang/zig/wiki/Community-Projects)
## Building from Source
## Installation
[![Build Status](https://dev.azure.com/ziglang/zig/_apis/build/status/ziglang.zig?branchName=master)](https://dev.azure.com/ziglang/zig/_build/latest?definitionId=1&branchName=master)
Note that you can
[download a binary of the master branch](https://ziglang.org/download/#release-master) or
[install Zig from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager).
### Stage 1: Build Zig from C++ Source Code
This step must be repeated when you make changes to any of the C++ source code.
#### Dependencies
##### POSIX
* cmake >= 2.8.5
* gcc >= 5.0.0 or clang >= 3.6.0
* LLVM, Clang, LLD development libraries == 11.x, compiled with the same gcc or clang version above
- Use the system package manager, or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#posix).
##### Windows
* cmake >= 3.15.3
* Microsoft Visual Studio. Supported versions:
- 2017 (version 15.8)
- 2019 (version 16)
* LLVM, Clang, LLD development libraries == 11.x
- Use the [pre-built binaries](https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows) or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#windows).
#### Instructions
##### POSIX
```
mkdir build
cd build
cmake ..
make install
```
Need help? [Troubleshooting Build Issues](https://github.com/ziglang/zig/wiki/Troubleshooting-Build-Issues)
##### MacOS
```
brew install cmake llvm
brew outdated llvm || brew upgrade llvm
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix llvm)
make install
```
##### Windows
See https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows
### Stage 2: Build Self-Hosted Zig from Zig Source Code
Now we use the stage1 binary:
```
zig build --prefix $(pwd)/stage2 -Denable-llvm
```
This produces `stage2/bin/zig` which can be used for testing and development.
Once it is feature complete, it will be used to build stage 3 - the final compiler
binary.
### Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler
*Note: Stage 2 compiler is not yet able to build Stage 3. Building Stage 3 is
not yet supported.*
Once the self-hosted compiler can build itself, this will be the actual
compiler binary that we will install to the system. Until then, users should
use stage 1.
#### Debug / Development Build
```
stage2/bin/zig build
```
This produces `zig-cache/bin/zig`.
#### Release / Install Build
```
stage2/bin/zig build install -Drelease
```
* [download a pre-built binary](https://ziglang.org/download/)
* [install from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
* [build from source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source)
* [bootstrap zig for any target](https://github.com/ziglang/zig-bootstrap)
## License

1002
build.zig

File diff suppressed because it is too large Load Diff

View File

@@ -3,54 +3,108 @@
set -x
set -e
BUILDDIR="$(pwd)"
sudo sh -c 'echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list'
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update -q
sudo apt-get install -y cmake s3cmd tidy
sudo apt-get remove -y llvm-*
sudo rm -rf /usr/local/*
sudo apt-get install -y libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd gcc-7 g++-7 ninja-build tidy
ZIGDIR="$(pwd)"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.1-dev.94+535615117"
PREFIX="$HOME/$CACHE_BASENAME"
MCPU="baseline"
JOBS="-j$(nproc)"
QEMUBASE="qemu-linux-x86_64-5.1.0"
wget https://ziglang.org/deps/$QEMUBASE.tar.xz
tar xf $QEMUBASE.tar.xz
PATH=$PWD/$QEMUBASE/bin:$PATH
rm -rf $PREFIX
cd $HOME
WASMTIME="wasmtime-v0.20.0-x86_64-linux"
wget https://github.com/bytecodealliance/wasmtime/releases/download/v0.20.0/$WASMTIME.tar.xz
tar xf $WASMTIME.tar.xz
PATH=$PWD/$WASMTIME:$PATH
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
QEMUBASE="qemu-linux-x86_64-5.2.0.1"
wget -nv "https://ziglang.org/deps/$QEMUBASE.tar.xz"
tar xf "$QEMUBASE.tar.xz"
export PATH="$(pwd)/$QEMUBASE/bin:$PATH"
# Bump to v0.23 once this issue is resolved:
# https://github.com/ziglang/zig/issues/8742
WASMTIME="wasmtime-v0.22.1-x86_64-linux"
wget -nv "https://github.com/bytecodealliance/wasmtime/releases/download/v0.22.1/$WASMTIME.tar.xz"
tar xf "$WASMTIME.tar.xz"
export PATH="$(pwd)/$WASMTIME:$PATH"
ZIG="$PREFIX/bin/zig"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
export CC=gcc-7
export CXX=g++-7
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja
ninja install
./zig build test -Denable-qemu -Denable-wasmtime
cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON
# look for HTML errors
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
make $JOBS install
# Here we rebuild zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"
make $JOBS install
for step in test-toolchain test-std docs; do
release/bin/zig build $step -Denable-qemu -Denable-wasmtime
done
# Look for HTML errors.
tidy -qe ../zig-cache/langref.html
VERSION="$(./zig version)"
if [ "${BUILD_REASON}" != "PullRequest" ]; then
ARTIFACTSDIR="$BUILDDIR/artifacts"
mkdir "$ARTIFACTSDIR"
docker run -i --mount type=bind,source="$ARTIFACTSDIR",target=/z ziglang/static-base:llvm11-x86_64-1 -j2 $BUILD_SOURCEVERSION
TARBALL="$(ls $ARTIFACTSDIR)"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$ARTIFACTSDIR/$TARBALL" s3://ziglang.org/builds/
# Produce the experimental std lib documentation.
mkdir -p release/docs/std
release/bin/zig test ../lib/std/std.zig \
--override-lib-dir ../lib \
-femit-docs=release/docs/std \
-fno-emit-bin
SHASUM=$(sha256sum $ARTIFACTSDIR/$TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $ARTIFACTSDIR/$TARBALL)
mv ../LICENSE release/
mv ../zig-cache/langref.html release/docs/
# Remove the unnecessary bin dir in $prefix/bin/zig
mv release/bin/zig release/
rmdir release/bin
# Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig
mv release/lib/zig release/lib2
rmdir release/lib
mv release/lib2 release/lib
VERSION=$(release/zig version)
DIRNAME="zig-linux-$ARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(sha256sum $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="linux-$GITBRANCH.json"
touch $JSONFILE
@@ -59,7 +113,7 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/x86_64-linux-$VERSION.json"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-linux-$VERSION.json"
# `set -x` causes these variables to be mangled.
# See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html

131
ci/azure/macos_arm64_script Executable file
View File

@@ -0,0 +1,131 @@
#!/bin/sh
set -x
set -e
brew update && brew install s3cmd
ZIGDIR="$(pwd)"
HOST_ARCH="x86_64"
HOST_TARGET="$HOST_ARCH-macos-gnu"
HOST_MCPU="baseline"
HOST_CACHE_BASENAME="zig+llvm+lld+clang-$HOST_TARGET-0.8.0-dev.2703+c12704a33"
HOST_PREFIX="$HOME/$HOST_CACHE_BASENAME"
ARCH="aarch64"
TARGET="$ARCH-macos-gnu"
MCPU="apple_a14"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2703+c12704a33"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j2"
rm -rf $HOST_PREFIX $PREFIX
cd $HOME
wget -nv "https://ziglang.org/deps/$HOST_CACHE_BASENAME.tar.xz"
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$HOST_CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
# Build host zig compiler in debug so that we can get the
# current version when packaging
ZIG="$HOST_PREFIX/bin/zig"
export CC="$ZIG cc -target $HOST_TARGET -mcpu=$HOST_MCPU"
export CXX="$ZIG c++ -target $HOST_TARGET -mcpu=$HOST_MCPU"
mkdir build.host
cd build.host
cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$HOST_PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$HOST_TARGET" \
-DZIG_TARGET_MCPU="$HOST_MCPU" \
-DZIG_STATIC=ON
unset CC
unset CXX
make $JOBS install
# Build zig compiler cross-compiled for arm64
cd $ZIGDIR
ZIG="$ZIGDIR/build.host/release/bin/zig"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_EXECUTABLE="$ZIG" \
-DZIG_STATIC=ON
unset CC
unset CXX
make $JOBS install
if [ "${BUILD_REASON}" != "PullRequest" ]; then
mv ../LICENSE release/
# We do not run test suite but still need langref.
mkdir -p release/docs
$ZIG run ../doc/docgen.zig -- $ZIG ../doc/langref.html.in release/docs/langref.html
# Produce the experimental std lib documentation.
mkdir -p release/docs/std
$ZIG test ../lib/std/std.zig \
--override-lib-dir ../lib \
-femit-docs=release/docs/std \
-fno-emit-bin
mv release/bin/zig release/
rmdir release/bin
VERSION=$(../build.host/release/bin/zig version)
DIRNAME="zig-macos-$ARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="macos-$GITBRANCH.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-macos-$VERSION.json"
# `set -x` causes these variables to be mangled.
# See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html
set +x
echo "##vso[task.setvariable variable=tarball;isOutput=true]$TARBALL"
echo "##vso[task.setvariable variable=shasum;isOutput=true]$SHASUM"
echo "##vso[task.setvariable variable=bytesize;isOutput=true]$BYTESIZE"
fi

View File

@@ -3,31 +3,33 @@
set -x
set -e
brew install s3cmd
brew update && brew install s3cmd
ZIGDIR="$(pwd)"
ARCH="x86_64"
CACHE_BASENAME="zig+llvm+lld+clang-$ARCH-macos-gnu-0.6.0+1c9ef63a"
TARGET="$ARCH-macos-gnu"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.1-dev.94+535615117"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j2"
rm -rf $PREFIX
cd $HOME
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
ZIG="$PREFIX/bin/zig"
NATIVE_LIBC_TXT="$HOME/native_libc.txt"
$ZIG libc > "$NATIVE_LIBC_TXT"
export ZIG_LIBC="$NATIVE_LIBC_TXT"
export CC="$ZIG cc"
export CXX="$ZIG c++"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
mkdir build
cd build
@@ -35,15 +37,14 @@ cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$ARCH-native-gnu" \
-DZIG_TARGET_MCPU="baseline" \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
unset ZIG_LIBC
make $JOBS install
@@ -53,7 +54,9 @@ make $JOBS install
cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"
make $JOBS install
release/bin/zig build test
for step in test-toolchain test-std docs; do
release/bin/zig build $step
done
if [ "${BUILD_REASON}" != "PullRequest" ]; then
mv ../LICENSE release/

View File

@@ -2,9 +2,7 @@ jobs:
- job: BuildMacOS
pool:
vmImage: 'macOS-10.15'
timeoutInMinutes: 360
steps:
- task: DownloadSecureFile@1
inputs:
@@ -12,12 +10,21 @@ jobs:
- script: ci/azure/macos_script
name: main
displayName: 'Build and test'
- job: BuildMacOS_arm64
pool:
vmImage: 'macOS-10.15'
timeoutInMinutes: 180
steps:
- task: DownloadSecureFile@1
inputs:
secureFile: s3cfg
- script: ci/azure/macos_arm64_script
name: main
displayName: 'Build'
- job: BuildLinux
pool:
vmImage: 'ubuntu-18.04'
timeoutInMinutes: 360
steps:
- task: DownloadSecureFile@1
inputs:
@@ -31,7 +38,7 @@ jobs:
timeoutInMinutes: 360
steps:
- powershell: |
(New-Object Net.WebClient).DownloadFile("https://github.com/msys2/msys2-installer/releases/download/2020-09-03/msys2-base-x86_64-20200903.sfx.exe", "sfx.exe")
(New-Object Net.WebClient).DownloadFile("https://github.com/msys2/msys2-installer/releases/download/2021-06-04/msys2-base-x86_64-20210604.sfx.exe", "sfx.exe")
.\sfx.exe -y -o\
del sfx.exe
displayName: Download/Extract/Install MSYS2
@@ -53,6 +60,7 @@ jobs:
- job: OnMasterSuccess
dependsOn:
- BuildMacOS
- BuildMacOS_arm64
- BuildLinux
- BuildWindows
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))

View File

@@ -3,9 +3,9 @@
set -x
set -e
pacman -Su --needed --noconfirm
pacman -Suy --needed --noconfirm
pacman -S --needed --noconfirm wget p7zip python3-pip tar xz
pip install s3cmd
wget -nv "https://ziglang.org/deps/llvm%2bclang%2blld-11.0.0-x86_64-windows-msvc-release-mt.tar.xz"
tar xf llvm+clang+lld-11.0.0-x86_64-windows-msvc-release-mt.tar.xz
wget -nv "https://ziglang.org/deps/llvm%2bclang%2blld-12.0.1-rc1-x86_64-windows-msvc-release-mt.tar.xz"
tar xf llvm+clang+lld-12.0.1-rc1-x86_64-windows-msvc-release-mt.tar.xz

View File

@@ -11,32 +11,23 @@ SET "MSYSTEM=%PREVMSYSTEM%"
SET "ZIGBUILDDIR=%SRCROOT%\build"
SET "ZIGINSTALLDIR=%ZIGBUILDDIR%\dist"
SET "ZIGPREFIXPATH=%SRCROOT%\llvm+clang+lld-11.0.0-x86_64-windows-msvc-release-mt"
SET "ZIGPREFIXPATH=%SRCROOT%\llvm+clang+lld-12.0.1-rc1-x86_64-windows-msvc-release-mt"
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
REM Make the `zig version` number consistent.
REM This will affect the cmake command below.
git.exe config core.abbrev 9
git.exe fetch --unshallow
git.exe fetch --tags
mkdir %ZIGBUILDDIR%
cd %ZIGBUILDDIR%
cmake.exe .. -Thost=x64 -G"Visual Studio 16 2019" -A x64 "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release || exit /b
cmake.exe .. -Thost=x64 -G"Visual Studio 16 2019" -A x64 "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release -DZIG_OMIT_STAGE2=ON || exit /b
msbuild /maxcpucount /p:Configuration=Release INSTALL.vcxproj || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-behavior -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-stage2 -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-fmt -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-toolchain -Dskip-non-native -Dskip-stage2-tests || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-std -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-compiler-rt -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-compare-output -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-standalone -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-stack-traces -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-cli -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-asm-link -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-runtime-safety -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-translate-c -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-run-translated-c -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build docs || exit /b
set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"

View File

@@ -6,8 +6,39 @@ platform:
arch: arm64
steps:
- name: build-and-test
image: ziglang/static-base:llvm11-aarch64-1
- name: build
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_build
- name: test-1
depends_on:
- build
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_test 1
- name: test-2
depends_on:
- build
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_test 2
- name: test-3
depends_on:
- build
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_test 3
- name: finalize
depends_on:
- build
- test-1
- test-2
- test-3
image: ziglang/static-base:llvm12-aarch64-5
environment:
SRHT_OAUTH_TOKEN:
from_secret: SRHT_OAUTH_TOKEN
@@ -16,4 +47,4 @@ steps:
AWS_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY
commands:
- ./ci/drone/linux_script
- ./ci/drone/linux_script_finalize

View File

@@ -1,58 +0,0 @@
#!/bin/sh
set -x
set -e
TRIPLEARCH="$(uname -m)"
BUILDDIR="$(pwd)"
DISTDIR="$(pwd)/dist"
apk update
apk add py3-pip xz perl-utils jq curl samurai
pip3 install s3cmd
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release "-DCMAKE_INSTALL_PREFIX=$DISTDIR" -DZIG_STATIC=ON -DCMAKE_PREFIX_PATH=/deps/local -GNinja
samu install
./zig build test -Dskip-release -Dskip-non-native
if [ -z "$DRONE_PULL_REQUEST" ]; then
mv ../LICENSE "$DISTDIR/"
mv ../zig-cache/langref.html "$DISTDIR/"
mv "$DISTDIR/bin/zig" "$DISTDIR/"
rmdir "$DISTDIR/bin"
GITBRANCH="$DRONE_BRANCH"
VERSION="$("$DISTDIR/zig" version)"
DIRNAME="zig-linux-$TRIPLEARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv "$DISTDIR" "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="$TRIPLEARCH-linux-$GITBRANCH.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$TRIPLEARCH-linux-$VERSION.json"
if [ "$GITBRANCH" = "master" ]; then
# avoid leaking oauth token
set +x
cd "$BUILDDIR"
./ci/srht/on_master_success "$VERSION" "$SRHT_OAUTH_TOKEN"
fi
fi

22
ci/drone/linux_script_base Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/sh
# https://docs.drone.io/pipeline/docker/syntax/workspace/
#
# Drone automatically creates a temporary volume, known as your workspace,
# where it clones your repository. The workspace is the current working
# directory for each step in your pipeline.
#
# Because the workspace is a volume, filesystem changes are persisted between
# pipeline steps. In other words, individual steps can communicate and share
# state using the filesystem.
#
# Workspace volumes are ephemeral. They are created when the pipeline starts
# and destroyed after the pipeline completes.
set -x
set -e
TRIPLEARCH="$(uname -m)"
DISTDIR="$DRONE_WORKSPACE/dist"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"

59
ci/drone/linux_script_build Executable file
View File

@@ -0,0 +1,59 @@
#!/bin/sh
. ./ci/drone/linux_script_base
PREFIX="/deps/local"
ZIG="$PREFIX/bin/zig"
TARGET="$TRIPLEARCH-linux-musl"
MCPU="baseline"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
# The `CMAKE_AR` parameter will consider any spaces to
# be part of the executable path rather than CLI args, so we have
# to create wrapper scripts for `zig ar` and zig ranlib`.
cat <<'ENDFILE' >$PREFIX/bin/ar
#!/bin/sh
/deps/local/bin/zig ar $@
ENDFILE
cat <<'ENDFILE' >$PREFIX/bin/ranlib
#!/bin/sh
/deps/local/bin/zig ranlib $@
ENDFILE
chmod +x $PREFIX/bin/ar
chmod +x $PREFIX/bin/ranlib
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX="$DISTDIR" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_AR="$PREFIX/bin/ar" \
-DCMAKE_RANLIB="$PREFIX/bin/ranlib" \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-GNinja
# Now CMake will use Zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
samu install
# Here we rebuild Zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
cmake .. -DZIG_EXECUTABLE="$DISTDIR/bin/zig"
samu install

46
ci/drone/linux_script_finalize Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
. ./ci/drone/linux_script_base
if [ -n "$DRONE_PULL_REQUEST" ]; then
exit 0
fi
apk update
apk add py3-pip perl-utils jq curl
pip3 install s3cmd
cd build
mv ../LICENSE "$DISTDIR/"
# docs are disabled due to: https://github.com/ziglang/zig/issues/8597
#mv ../zig-cache/langref.html "$DISTDIR/"
mv "$DISTDIR/bin/zig" "$DISTDIR/"
rmdir "$DISTDIR/bin"
GITBRANCH="$DRONE_BRANCH"
VERSION="$("$DISTDIR/zig" version)"
DIRNAME="zig-linux-$TRIPLEARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv "$DISTDIR" "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="tarball.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$TRIPLEARCH-linux-$VERSION.json"
if [ "$GITBRANCH" = "master" ]; then
# avoid leaking oauth token
set +x
cd "$DRONE_WORKSPACE"
./ci/srht/on_master_success "$VERSION" "$SRHT_OAUTH_TOKEN"
fi

46
ci/drone/linux_script_test Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
. ./ci/drone/linux_script_base
# only release-fast builds of test suite due to: https://github.com/ziglang/zig/issues/8597
#
# Some test suite components will be missing because they do not support
# forcing -OReleaseFast
#
# see `zig build --help` for the full list of test-* components
case "$1" in
1)
steps="\
test-stage2 \
test-fmt \
test-behavior"
;;
2)
steps="test-std"
;;
3)
steps="\
test-compiler-rt \
test-minilibc \
test-compare-output \
test-translate-c \
test-run-translated-c"
;;
'')
echo "error: expecting test group argument"
exit 1
;;
*)
echo "error: unknown test group: $1"
exit 1
;;
esac
# only release-fast builds of test suite due to: https://github.com/ziglang/zig/issues/8597
./build/zig build \
-Drelease \
-Dskip-debug \
-Dskip-release-small \
-Dskip-release-safe \
-Dskip-non-native \
$steps

View File

@@ -4,12 +4,11 @@ set -x
set -e
sudo pkg update -fq
sudo pkg install -y cmake py27-s3cmd wget curl jq
sudo pkg install -y cmake py38-s3cmd wget curl jq samurai
ZIGDIR="$(pwd)"
CACHE_BASENAME="llvm+clang+lld-11.0.0-x86_64-freebsd-release"
CACHE_BASENAME="zig+llvm+lld+clang-x86_64-freebsd-gnu-0.8.0-dev.2703+c12704a33"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j$(sysctl -n hw.ncpu)"
cd $HOME
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
@@ -20,6 +19,8 @@ cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
# SourceHut reports that it is a terminal that supports escape codes, but it
# is a filthy liar. Here we tell Zig to not try to send any terminal escape
@@ -28,8 +29,14 @@ export TERM=dumb
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PREFIX "-DCMAKE_INSTALL_PREFIX=$(pwd)/release" -DZIG_STATIC=ON
make $JOBS install
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$PREFIX \
"-DCMAKE_INSTALL_PREFIX=$(pwd)/release" \
-DZIG_STATIC=ON \
-DZIG_TARGET_TRIPLE=x86_64-freebsd-gnu \
-GNinja
samu install
# Here we skip some tests to save time.
release/bin/zig build test -Dskip-compile-errors -Dskip-non-native

737
ci/srht/index.html Normal file
View File

@@ -0,0 +1,737 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Releases ⚡ The Zig Programming Language</title>
<link rel="icon" href="/favicon.png">
<style>
body{
font-family: system-ui, -apple-system, Roboto, "Segoe UI", sans-serif;
line-height: 1.45;
margin-left: 0;
margin-right: 0;
}
p {
margin: 0.8em 0;
}
h1, h2, h3, h4 {
margin: 0.5em 0 0.5em;
line-height: 1.2;
font-weight: bold;
color: #666;
}
h1 a, h2 a, h3 a, h4 a {
text-decoration: none;
color: #666;
}
a.hdr {
visibility: hidden;
}
h1:hover > a.hdr, h2:hover > a.hdr, h3:hover > a.hdr, h4:hover > a.hdr, h5:hover > a.hdr {
visibility: visible;
}
h1 { font-size: 2.0em; }
h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; }
h4 { font-size: 1.0em; }
a {
color: #2A6286;
}
a:not(:hover) {
text-decoration: none;
}
th, td {
padding: 0.6em;
text-align: left;
white-space: nowrap;
}
td {
font-size: 0.96em;
}
th {
border-bottom: 2px solid #f2f3f3;
}
tr:nth-child(even) {
background: #f2f3f3;
}
.container {
margin: 0 auto;
position: relative;
max-width: 1000px;
}
#navbar {
background-color: #737475;
padding: 5px 0;
border-top: 4px solid #f7a41d;
margin-bottom: 30px;
}
#navbar .navbar-item, #navbar .navbar-item:visited {
color: white;
padding-right: 5px;
padding-left: 5px;
}
.code {
font-family: monospace;
font-size: 0.8em;
}
#header-image {
background-image: url(https://ziglang.org/img/zig-logo-dark.svg);
background-repeat: no-repeat;
width: 340px;
height: 90px;
display: block;
padding: 0;
margin: 0;
}
@media (prefers-color-scheme: dark) {
body{
background-color:#111;
color: #bbb;
}
a {
color: #88f;
}
table, th, td {
border-color: grey;
}
tr:nth-child(even) {
background: #1e1e1e;
}
h1 a, h2 a, h3 a, h4 a, h5 a {
color: #aaa;
}
#header-image {
background-image: url(https://ziglang.org/img/zig-logo-light.svg);
}
}
</style>
</head>
<body>
<div class="container">
<a href="/"><span id="header-image"></span></a>
</div>
<nav id="navbar">
<div class="container">
<a href="/download/" class="navbar-item">Download &amp; Documentation</a>
<a href="https://github.com/ziglang/zig" class="navbar-item">Source Code</a>
<a href="/news/" class="navbar-item">News</a>
<a href="https://github.com/ziglang/zig/wiki/Community" class="navbar-item">Join a Community</a>
<a href="/zsf/" class="navbar-item">
<svg style="color: #ea4aaa; vertical-align: middle;fill: currentColor; margin-right: 5px" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M9 2c-.97 0-1.69.42-2.2 1-.51.58-.78.92-.8 1-.02-.08-.28-.42-.8-1-.52-.58-1.17-1-2.2-1-1.632.086-2.954 1.333-3 3 0 .52.09 1.52.67 2.67C1.25 8.82 3.01 10.61 6 13c2.98-2.39 4.77-4.17 5.34-5.33C11.91 6.51 12 5.5 12 5c-.047-1.69-1.342-2.913-3-3z"></path></svg>Sponsor the Zig Software Foundation</a>
</div>
</nav>
<div class="container">
<h1>Releases</h1>
<p>You can also
<a href="https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager">install Zig from a package manager</a>.
</p>
<p>
There is a <a href="index.json">JSON version of this page</a>.
</p>
<h2 id="release-master">master</h2>
<ul>
<li>{{MASTER_DATE}}</li>
<li><a href="/documentation/master/">Language Reference</a></li>
<li><a href="/documentation/master/std/">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/builds/{{SRC_TARBALL}}">{{SRC_TARBALL}}</a></td>
<td>Source</td>
<td>{{SRC_BYTESIZE}}</td>
<td class="code">{{SRC_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_LINUX_TARBALL}}">{{X86_64_LINUX_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_LINUX_BYTESIZE}}</td>
<td class="code">{{X86_64_LINUX_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{AARCH64_LINUX_TARBALL}}">{{AARCH64_LINUX_TARBALL}}</a></td>
<td>Binary</td>
<td>{{AARCH64_LINUX_BYTESIZE}}</td>
<td class="code">{{AARCH64_LINUX_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_WINDOWS_TARBALL}}">{{X86_64_WINDOWS_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_WINDOWS_BYTESIZE}}</td>
<td class="code">{{X86_64_WINDOWS_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_MACOS_TARBALL}}">{{X86_64_MACOS_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_MACOS_BYTESIZE}}</td>
<td class="code">{{X86_64_MACOS_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{AARCH64_MACOS_TARBALL}}">{{AARCH64_MACOS_TARBALL}}</a></td>
<td>Binary</td>
<td>{{AARCH64_MACOS_BYTESIZE}}</td>
<td class="code">{{AARCH64_MACOS_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_FREEBSD_TARBALL}}">{{X86_64_FREEBSD_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_FREEBSD_BYTESIZE}}</td>
<td class="code">{{X86_64_FREEBSD_SHASUM}}</td>
</tr>
</tbody>
</table>
<h2 id="release-0.7.1">0.7.1</h2>
<ul>
<li>2020-12-13</li>
<li><a href="0.7.1/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.7.1/">Language Reference</a></li>
<li><a href="/documentation/0.7.1/std">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-0.7.1.tar.xz">zig-0.7.1.tar.xz</a></td>
<td>Source</td>
<td>11MiB</td>
<td class="code">2db3b944ab368d955b48743d9f7c963b8f96de1a441ba5a35e197237cc6dae44</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-bootstrap-0.7.1.tar.xz">zig-bootstrap-0.7.1.tar.xz</a></td>
<td>Source</td>
<td>39MiB</td>
<td class="code">040f27c1fae4b0cac0a2782aecdb691f6a2f8e89db6a6ed35024c31c304fd9b2</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-freebsd-x86_64-0.7.1.tar.xz">zig-freebsd-x86_64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">e73c1dca35791a3183fdd5ecde0443ebbe180942efceafe651886034fb8def09</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-aarch64-0.7.1.tar.xz">zig-linux-aarch64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>33MiB</td>
<td class="code">48ec90eba407e4587ddef7eecef25fec7e13587eb98e3b83c5f2f5fff2a5cbe7</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-armv7a-0.7.1.tar.xz">zig-linux-armv7a-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>35MiB</td>
<td class="code">5a0662e07b4c4968665e1f97558f8591f6facec45d2e0ff5715e661743107ceb</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-i386-0.7.1.tar.xz">zig-linux-i386-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">4882e052e5f83690bd0334bb4fc1702b5403cb3a3d2aa63fd7d6043d8afecba3</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-riscv64-0.7.1.tar.xz">zig-linux-riscv64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">187294bfd35983348c3fe042901b42e67e7e36ab7f77a5f969d21c0051f4d21f</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-x86_64-0.7.1.tar.xz">zig-linux-x86_64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>37MiB</td>
<td class="code">18c7b9b200600f8bcde1cd8d7f1f578cbc3676241ce36d771937ce19a8159b8d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-macos-x86_64-0.7.1.tar.xz">zig-macos-x86_64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>35MiB</td>
<td class="code">845cb17562978af0cf67e3993f4e33330525eaf01ead9386df9105111e3bc519</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-windows-i386-0.7.1.zip">zig-windows-i386-0.7.1.zip</a></td>
<td>Binary</td>
<td>52MiB</td>
<td class="code">a1b9a7421e13153e07fd2e2c93ff29aad64d83105b8fcdafa633dbe689caf1c0</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-windows-x86_64-0.7.1.zip">zig-windows-x86_64-0.7.1.zip</a></td>
<td>Binary</td>
<td>53MiB</td>
<td class="code">4818a8a65b4672bc52c0ae7f14d014e0eb8caf10f12c0745176820384cea296a</td>
</tr>
</tbody>
</table>
<h2 id="release-0.7.0">0.7.0</h2>
<ul>
<li>2020-11-08</li>
<li><a href="0.7.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.7.0/">Language Reference</a></li>
<li><a href="/documentation/0.7.0/std">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-0.7.0.tar.xz">zig-0.7.0.tar.xz</a></td>
<td>Source</td>
<td>11MiB</td>
<td class="code">0efd2cf6c3b05723db80e9cf193bc55150bba84ca41f855a90f53fc756445f83</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-bootstrap-0.7.0.tar.xz">zig-bootstrap-0.7.0.tar.xz</a></td>
<td>Source</td>
<td>39MiB</td>
<td class="code">f073beaf5c53c8c57c0d374cbfcb332ef92ad703173edba0d9e0f2ed28401b72</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-freebsd-x86_64-0.7.0.tar.xz">zig-freebsd-x86_64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>34MiB</td>
<td class="code">a0c926272ee4ae720034b4a6a1dc98399d76156dd84182554740f0ca8a41fc99</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-aarch64-0.7.0.tar.xz">zig-linux-aarch64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>32MiB</td>
<td class="code">f89933bac87d44be82325754ff88423020c81c7032a6fc41cfeb81e982eeab9b</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-armv7a-0.7.0.tar.xz">zig-linux-armv7a-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>34MiB</td>
<td class="code">011c267e25a96ee160505a560c441daa045359a9d50e13ab1bada9d75c95db2d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-i386-0.7.0.tar.xz">zig-linux-i386-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>37MiB</td>
<td class="code">4bb2072cd363bcb1cbeb4872ff5cbc1f683b02d0cc1f90c46e3ea7422ce53222</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-riscv64-0.7.0.tar.xz">zig-linux-riscv64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">40dff81faa6f232ac40abbf88b9371f3cc932b6e09c423b94387c9ea580cb7be</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-x86_64-0.7.0.tar.xz">zig-linux-x86_64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">e619b1c6094c095b932767f527aee2507f847ea981513ff8a08aab0fd730e0ac</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-macos-aarch64-0.7.0.tar.xz">zig-macos-aarch64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>33MiB</td>
<td class="code">338238035734db74ea4f30e500a4893bf741d38305c10952d5e39fa05bdb057d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-macos-x86_64-0.7.0.tar.xz">zig-macos-x86_64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>35MiB</td>
<td class="code">94063f9a311cbbf7a2e0a12295e09437182cf950f18cb0eb30ea9893f3677f24</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-windows-i386-0.7.0.zip">zig-windows-i386-0.7.0.zip</a></td>
<td>Binary</td>
<td>51MiB</td>
<td class="code">b1e520aacbfbd645ff3521b3eb4d44166d9a0288b8725e4b001f8b50a425eb2e</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-windows-x86_64-0.7.0.zip">zig-windows-x86_64-0.7.0.zip</a></td>
<td>Binary</td>
<td>52MiB</td>
<td class="code">965f56c0a36f9cda2125e3a348bc654f7f155e2804c3667d231775ec228f8553</td>
</tr>
</tbody>
</table>
<h2 id="release-0.6.0">0.6.0</h2>
<ul>
<li>2020-04-13</li>
<li><a href="0.6.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.6.0">Language Reference</a></li>
<li><a href="/documentation/0.6.0/std">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-0.6.0.tar.xz">zig-0.6.0.tar.xz</a></td>
<td>Source</td>
<td>9.9MiB</td>
<td class="code">5d167dc19354282dd35dd17b38e99e1763713b9be8a4ba9e9e69284e059e7204</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-bootstrap-0.6.0.tar.xz">zig-bootstrap-0.6.0.tar.xz</a></td>
<td>Source</td>
<td>36.7MiB</td>
<td class="code">5e0e4dc878b3dd0c1852a442b174f0732e8c07869a8fcd226b71a93b89b381ab</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-freebsd-x86_64-0.6.0.tar.xz">zig-freebsd-x86_64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">190ff79c1eb56805a315d7c7a51082e32f62926250c0702b36760c225e1634a3</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-aarch64-0.6.0.tar.xz">zig-linux-aarch64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">e7520efd42cfa02be48c2e430d08fe1f3cbb999d21d9f0d3ffd0febb976b2f41</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-armv6kz-0.6.0.tar.xz">zig-linux-armv6kz-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">36b6493b3fed43eb1f0000e765798ad31a6bb7d7fd3f553ac1c3761dbc919b82</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-armv7a-0.6.0.tar.xz">zig-linux-armv7a-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">946969abe357def95ca9cbbfcebfcf2d90cf967bcd3f48ee87662e32d91d8f35</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-i386-0.6.0.tar.xz">zig-linux-i386-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>43MiB</td>
<td class="code">a97a2f9ae21575743cdd763c1917d49400d83fc562ef64582b18bade43eb24ce</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-riscv64-0.6.0.tar.xz">zig-linux-riscv64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>41MiB</td>
<td class="code">68ddee43f7503c8ae5f26a921f3602c34719a02ed2241f528c0b8b888cc14b38</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-x86_64-0.6.0.tar.xz">zig-linux-x86_64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>43MiB</td>
<td class="code">08fd3c757963630645441c2772362e9c2294020c44f14fce1b89f45de0dc1253</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-macos-x86_64-0.6.0.tar.xz">zig-macos-x86_64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>41MiB</td>
<td class="code">17270360e87ddc49f737e760047b2fac49f1570a824a306119b1194ac4093895</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-windows-i386-0.6.0.zip">zig-windows-i386-0.6.0.zip</a></td>
<td>Binary</td>
<td>58MiB</td>
<td class="code">3b0a02618743e92175990dc6d1a787bb95ff62c4cda016f1c14c7786f575f8ca</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-windows-x86_64-0.6.0.zip">zig-windows-x86_64-0.6.0.zip</a></td>
<td>Binary</td>
<td>47MiB</td>
<td class="code">c3b897832523e1026e10b2d8d55d7f895185c0a27a63681f3a23219c3f1c38f4</td>
</tr>
</tbody>
</table>
<h2 id="release-0.5.0">0.5.0</h2>
<ul>
<li>2019-09-30</li>
<li><a href="0.5.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.5.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-0.5.0.tar.xz">zig-0.5.0.tar.xz</a></td>
<td>Source</td>
<td>10.4MiB</td>
<td class="code">55ae16960f152bcb9cf98b4f8570902d0e559a141abf927f0d3555b7cc838a31</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-linux-x86_64-0.5.0.tar.xz">zig-linux-x86_64-0.5.0.tar.xz</a></td>
<td>Binary</td>
<td>39.0MiB</td>
<td class="code">43e8f8a8b8556edd373ddf9c1ef3ca6cf852d4d09fe07d5736d12fefedd2b4f7</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-windows-x86_64-0.5.0.zip">zig-windows-x86_64-0.5.0.zip</a></td>
<td>Binary</td>
<td>42.8MiB</td>
<td class="code">58141323db8d84a5af62746be5f9140bc161ee760ef33dc91a887bf9ac021976</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-macos-x86_64-0.5.0.tar.xz">zig-macos-x86_64-0.5.0.tar.xz</a></td>
<td>Binary</td>
<td>36.1MiB</td>
<td class="code">28702cc05745c7c0bd450487d5f4091bf0a1ad279b35eb9a640ce3e3a15b300d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-freebsd-x86_64-0.5.0.tar.xz">zig-freebsd-x86_64-0.5.0.tar.xz</a></td>
<td>Binary</td>
<td>32.1MiB</td>
<td class="code">9e1f4d36c3d584c0aa01f20eb4cd0a0eef3eee5af23e483b8414de55feab6ab6</td>
</tr>
</tbody>
</table>
<h2 id="release-0.4.0">0.4.0</h2>
<ul>
<li>2019-04-08</li>
<li><a href="0.4.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.4.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-0.4.0.tar.xz">zig-0.4.0.tar.xz</a></td>
<td>Source</td>
<td>5.1MiB</td>
<td class="code">fec1f3f6b359a3d942e0a7f9157b3b30cde83927627a0e1ea95c54de3c526cfc</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-linux-x86_64-0.4.0.tar.xz">zig-linux-x86_64-0.4.0.tar.xz</a></td>
<td>Binary</td>
<td>31.4MiB</td>
<td class="code">fb1954e2fb556a01f8079a08130e88f70084e08978ff853bb2b1986d8c39d84e</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-windows-x86_64-0.4.0.zip">zig-windows-x86_64-0.4.0.zip</a></td>
<td>Binary</td>
<td>34.1MiB</td>
<td class="code">fbc3dd205e064c263063f69f600bedb18e3d0aa2efa747a63ef6cafb6d73f127</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-macos-x86_64-0.4.0.tar.xz">zig-macos-x86_64-0.4.0.tar.xz</a></td>
<td>Binary</td>
<td>29.4MiB</td>
<td class="code">67c932982484d017c5111e54af9f33f15e8e05c6bc5346a55e04052159c964a8</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-freebsd-x86_64-0.4.0.tar.xz">zig-freebsd-x86_64-0.4.0.tar.xz</a></td>
<td>Binary</td>
<td>26.0MiB</td>
<td class="code">3d557c91ac36d8262eb1733bb5f261c95944f9b635e43386e3d00a3272818c30</td>
</tr>
</tbody>
</table>
<h2 id="release-0.3.0">0.3.0</h2>
<ul>
<li>2018-09-28</li>
<li><a href="0.3.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.3.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-0.3.0.tar.xz">zig-0.3.0.tar.xz</a></td>
<td>Source</td>
<td>2.2MiB</td>
<td class="code">d70af604f3a8622f3393d93abb3e056bf60351e32d121e6fa4fe03d8d41e1f5a</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-linux-x86_64-0.3.0.tar.xz">zig-linux-x86_64-0.3.0.tar.xz</a></td>
<td>Binary</td>
<td>24.0MiB</td>
<td class="code">b378d0aae30cb54f28494e7bc4efbc9bfb6326f47bfb302e8b5287af777b2f3c</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-windows-x86_64-0.3.0.zip">zig-windows-x86_64-0.3.0.zip</a></td>
<td>Binary</td>
<td>21.5MiB</td>
<td class="code">bb568c03950958f8bb3472139c3ab5ed74547c8c694ab50f404c202faf51baf4</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-macos-x86_64-0.3.0.tar.xz">zig-macos-x86_64-0.3.0.tar.xz</a></td>
<td>Binary</td>
<td>22.6MiB</td>
<td class="code">19dec1f1943ab7be26823376d466f7e456143deb34e17502778a949034dc2e7e</td>
</tr>
</tbody>
</table>
<h2 id="release-0.2.0">0.2.0</h2>
<ul>
<li>2018-03-15</li>
<li><a href="0.2.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.2.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.2.0/zig-0.2.0.tar.xz">zig-0.2.0.tar.xz</a></td>
<td>Source</td>
<td>1.9MiB</td>
<td class="code">29c9beb172737f4d5019b88ceae829ae8bc6512fb4386cfbf895ae2b42aa6965</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.2.0/zig-linux-x86_64-0.2.0.tar.xz">zig-linux-x86_64-0.2.0.tar.xz</a></td>
<td>Binary</td>
<td>23.5MiB</td>
<td class="code">209c6fb745d42474c0a73d6f291c7ae3a38b6a1b6b641eea285a7f840cc1a890</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.2.0/zig-win64-0.2.0.zip">zig-win64-0.2.0.zip</a></td>
<td>Binary</td>
<td>20.6MiB</td>
<td class="code">4f8a2979941a1f081ec8e545cca0b72608c0db1c5a3fd377a94db40649dcd3d4</td>
</tr>
</tbody>
</table>
<h2 id="release-0.1.1">0.1.1</h2>
<ul>
<li>2017-10-17</li>
<li><a href="0.1.1/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.1.1">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.1.1/zig-0.1.1.tar.xz">zig-0.1.1.tar.xz</a></td>
<td>Source</td>
<td>1.62MiB</td>
<td class="code">ffca0cfb263485287e19cc997b08701fcd5f24b700345bcdc3dd8074f5a104e0</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.1.1/zig-win64-0.1.1.zip">zig-win64-0.1.1.zip</a></td>
<td>Binary</td>
<td>19.3MiB</td>
<td class="code">6fc88bef531af7e567fe30bf60da1487b86833cbee84c7a2f3e317030aa5b660</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

356
ci/srht/index.json Normal file
View File

@@ -0,0 +1,356 @@
{
"master": {
"version": "{{MASTER_VERSION}}",
"date": "{{MASTER_DATE}}",
"docs": "https://ziglang.org/documentation/master/",
"stdDocs": "https://ziglang.org/documentation/master/std/",
"src": {
"tarball": "https://ziglang.org/builds/{{SRC_TARBALL}}",
"shasum": "{{SRC_SHASUM}}",
"size": "{{SRC_BYTESIZE}}"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/builds/{{X86_64_FREEBSD_TARBALL}}",
"shasum": "{{X86_64_FREEBSD_SHASUM}}",
"size": "{{X86_64_FREEBSD_BYTESIZE}}"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/builds/{{X86_64_MACOS_TARBALL}}",
"shasum": "{{X86_64_MACOS_SHASUM}}",
"size": "{{X86_64_MACOS_BYTESIZE}}"
},
"aarch64-macos": {
"tarball": "https://ziglang.org/builds/{{AARCH64_MACOS_TARBALL}}",
"shasum": "{{AARCH64_MACOS_SHASUM}}",
"size": "{{AARCH64_MACOS_BYTESIZE}}"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/builds/{{X86_64_WINDOWS_TARBALL}}",
"shasum": "{{X86_64_WINDOWS_SHASUM}}",
"size": "{{X86_64_WINDOWS_BYTESIZE}}"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/builds/{{X86_64_LINUX_TARBALL}}",
"shasum": "{{X86_64_LINUX_SHASUM}}",
"size": "{{X86_64_LINUX_BYTESIZE}}"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/builds/{{AARCH64_LINUX_TARBALL}}",
"shasum": "{{AARCH64_LINUX_SHASUM}}",
"size": "{{AARCH64_LINUX_BYTESIZE}}"
}
},
"0.7.1": {
"date": "2020-12-13",
"docs": "https://ziglang.org/documentation/0.7.1/",
"stdDocs": "https://ziglang.org/documentation/0.7.1/std/",
"notes": "https://ziglang.org/download/0.7.1/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.7.1/zig-0.7.1.tar.xz",
"shasum": "2db3b944ab368d955b48743d9f7c963b8f96de1a441ba5a35e197237cc6dae44",
"size": "10711824"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.7.1/zig-bootstrap-0.7.1.tar.xz",
"shasum": "040f27c1fae4b0cac0a2782aecdb691f6a2f8e89db6a6ed35024c31c304fd9b2",
"size": "40232612"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.7.1/zig-freebsd-x86_64-0.7.1.tar.xz",
"shasum": "e73c1dca35791a3183fdd5ecde0443ebbe180942efceafe651886034fb8def09",
"size": "39066808"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-aarch64-0.7.1.tar.xz",
"shasum": "48ec90eba407e4587ddef7eecef25fec7e13587eb98e3b83c5f2f5fff2a5cbe7",
"size": "33780552"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-armv7a-0.7.1.tar.xz",
"shasum": "5a0662e07b4c4968665e1f97558f8591f6facec45d2e0ff5715e661743107ceb",
"size": "35813504"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-i386-0.7.1.tar.xz",
"shasum": "4882e052e5f83690bd0334bb4fc1702b5403cb3a3d2aa63fd7d6043d8afecba3",
"size": "39230912"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-riscv64-0.7.1.tar.xz",
"shasum": "187294bfd35983348c3fe042901b42e67e7e36ab7f77a5f969d21c0051f4d21f",
"size": "37454812"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-x86_64-0.7.1.tar.xz",
"shasum": "18c7b9b200600f8bcde1cd8d7f1f578cbc3676241ce36d771937ce19a8159b8d",
"size": "37848176"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.7.1/zig-macos-x86_64-0.7.1.tar.xz",
"shasum": "845cb17562978af0cf67e3993f4e33330525eaf01ead9386df9105111e3bc519",
"size": "36211076"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.7.1/zig-windows-i386-0.7.1.zip",
"shasum": "a1b9a7421e13153e07fd2e2c93ff29aad64d83105b8fcdafa633dbe689caf1c0",
"size": "54374983"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.7.1/zig-windows-x86_64-0.7.1.zip",
"shasum": "4818a8a65b4672bc52c0ae7f14d014e0eb8caf10f12c0745176820384cea296a",
"size": "54909997"
}
},
"0.7.0": {
"date": "2020-11-08",
"docs": "https://ziglang.org/documentation/0.7.0/",
"stdDocs": "https://ziglang.org/documentation/0.7.0/std/",
"notes": "https://ziglang.org/download/0.7.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.7.0/zig-0.7.0.tar.xz",
"shasum": "0efd2cf6c3b05723db80e9cf193bc55150bba84ca41f855a90f53fc756445f83",
"size": "10683920"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.7.0/zig-bootstrap-0.7.0.tar.xz",
"shasum": "f073beaf5c53c8c57c0d374cbfcb332ef92ad703173edba0d9e0f2ed28401b72",
"size": "40200436"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.7.0/zig-freebsd-x86_64-0.7.0.tar.xz",
"shasum": "a0c926272ee4ae720034b4a6a1dc98399d76156dd84182554740f0ca8a41fc99",
"size": "34798992"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-aarch64-0.7.0.tar.xz",
"shasum": "f89933bac87d44be82325754ff88423020c81c7032a6fc41cfeb81e982eeab9b",
"size": "33096140"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-armv7a-0.7.0.tar.xz",
"shasum": "011c267e25a96ee160505a560c441daa045359a9d50e13ab1bada9d75c95db2d",
"size": "35157584"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-i386-0.7.0.tar.xz",
"shasum": "4bb2072cd363bcb1cbeb4872ff5cbc1f683b02d0cc1f90c46e3ea7422ce53222",
"size": "38530596"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-riscv64-0.7.0.tar.xz",
"shasum": "40dff81faa6f232ac40abbf88b9371f3cc932b6e09c423b94387c9ea580cb7be",
"size": "36759992"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-x86_64-0.7.0.tar.xz",
"shasum": "e619b1c6094c095b932767f527aee2507f847ea981513ff8a08aab0fd730e0ac",
"size": "37154432"
},
"aarch64-macos": {
"tarball": "https://ziglang.org/download/0.7.0/zig-macos-aarch64-0.7.0.tar.xz",
"shasum": "338238035734db74ea4f30e500a4893bf741d38305c10952d5e39fa05bdb057d",
"size": "33739424"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.7.0/zig-macos-x86_64-0.7.0.tar.xz",
"shasum": "94063f9a311cbbf7a2e0a12295e09437182cf950f18cb0eb30ea9893f3677f24",
"size": "35258328"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.7.0/zig-windows-i386-0.7.0.zip",
"shasum": "b1e520aacbfbd645ff3521b3eb4d44166d9a0288b8725e4b001f8b50a425eb2e",
"size": "53390517"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.7.0/zig-windows-x86_64-0.7.0.zip",
"shasum": "965f56c0a36f9cda2125e3a348bc654f7f155e2804c3667d231775ec228f8553",
"size": "53943784"
}
},
"0.6.0": {
"date": "2020-04-13",
"docs": "https://ziglang.org/documentation/0.6.0/",
"stdDocs": "https://ziglang.org/documentation/0.6.0/std/",
"notes": "https://ziglang.org/download/0.6.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.6.0/zig-0.6.0.tar.xz",
"shasum": "5d167dc19354282dd35dd17b38e99e1763713b9be8a4ba9e9e69284e059e7204",
"size": "10349552"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.6.0/zig-bootstrap-0.6.0.tar.xz",
"shasum": "5e0e4dc878b3dd0c1852a442b174f0732e8c07869a8fcd226b71a93b89b381ab",
"size": "38469948"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.6.0/zig-freebsd-x86_64-0.6.0.tar.xz",
"shasum": "190ff79c1eb56805a315d7c7a51082e32f62926250c0702b36760c225e1634a3",
"size": "36974604"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-aarch64-0.6.0.tar.xz",
"shasum": "e7520efd42cfa02be48c2e430d08fe1f3cbb999d21d9f0d3ffd0febb976b2f41",
"size": "37090044"
},
"armv6kz-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-armv6kz-0.6.0.tar.xz",
"shasum": "36b6493b3fed43eb1f0000e765798ad31a6bb7d7fd3f553ac1c3761dbc919b82",
"size": "39133452"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-armv7a-0.6.0.tar.xz",
"shasum": "946969abe357def95ca9cbbfcebfcf2d90cf967bcd3f48ee87662e32d91d8f35",
"size": "39143748"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-i386-0.6.0.tar.xz",
"shasum": "a97a2f9ae21575743cdd763c1917d49400d83fc562ef64582b18bade43eb24ce",
"size": "44877640"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-riscv64-0.6.0.tar.xz",
"shasum": "68ddee43f7503c8ae5f26a921f3602c34719a02ed2241f528c0b8b888cc14b38",
"size": "41993144"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-x86_64-0.6.0.tar.xz",
"shasum": "08fd3c757963630645441c2772362e9c2294020c44f14fce1b89f45de0dc1253",
"size": "44766320"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.6.0/zig-macos-x86_64-0.6.0.tar.xz",
"shasum": "17270360e87ddc49f737e760047b2fac49f1570a824a306119b1194ac4093895",
"size": "42573184"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.6.0/zig-windows-i386-0.6.0.zip",
"shasum": "3b0a02618743e92175990dc6d1a787bb95ff62c4cda016f1c14c7786f575f8ca",
"size": "60446431"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.6.0/zig-windows-x86_64-0.6.0.zip",
"shasum": "c3b897832523e1026e10b2d8d55d7f895185c0a27a63681f3a23219c3f1c38f4",
"size": "49065511"
}
},
"0.5.0": {
"date": "2019-09-30",
"docs": "https://ziglang.org/documentation/0.5.0/",
"notes": "https://ziglang.org/download/0.5.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.5.0/zig-0.5.0.tar.xz",
"shasum": "55ae16960f152bcb9cf98b4f8570902d0e559a141abf927f0d3555b7cc838a31",
"size": "10956132"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.5.0/zig-freebsd-x86_64-0.5.0.tar.xz",
"shasum": "9e1f4d36c3d584c0aa01f20eb4cd0a0eef3eee5af23e483b8414de55feab6ab6",
"size": "33650744"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.5.0/zig-macos-x86_64-0.5.0.tar.xz",
"shasum": "28702cc05745c7c0bd450487d5f4091bf0a1ad279b35eb9a640ce3e3a15b300d",
"size": "37898664"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.5.0/zig-windows-x86_64-0.5.0.zip",
"shasum": "58141323db8d84a5af62746be5f9140bc161ee760ef33dc91a887bf9ac021976",
"size": "44871804"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.5.0/zig-linux-x86_64-0.5.0.tar.xz",
"shasum": "43e8f8a8b8556edd373ddf9c1ef3ca6cf852d4d09fe07d5736d12fefedd2b4f7",
"size": "40895068"
}
},
"0.4.0": {
"date": "2019-04-08",
"docs": "https://ziglang.org/documentation/0.4.0/",
"notes": "https://ziglang.org/download/0.4.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.4.0/zig-0.4.0.tar.xz",
"shasum": "fec1f3f6b359a3d942e0a7f9157b3b30cde83927627a0e1ea95c54de3c526cfc",
"size": "5348776"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.4.0/zig-freebsd-x86_64-0.4.0.tar.xz",
"shasum": "3d557c91ac36d8262eb1733bb5f261c95944f9b635e43386e3d00a3272818c30",
"size": "27269672"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.4.0/zig-macos-x86_64-0.4.0.tar.xz",
"shasum": "67c932982484d017c5111e54af9f33f15e8e05c6bc5346a55e04052159c964a8",
"size": "30841504"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.4.0/zig-windows-x86_64-0.4.0.zip",
"shasum": "fbc3dd205e064c263063f69f600bedb18e3d0aa2efa747a63ef6cafb6d73f127",
"size": "35800101"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.4.0/zig-linux-x86_64-0.4.0.tar.xz",
"shasum": "fb1954e2fb556a01f8079a08130e88f70084e08978ff853bb2b1986d8c39d84e",
"size": "32876100"
}
},
"0.3.0": {
"date": "2018-09-28",
"docs": "https://ziglang.org/documentation/0.3.0/",
"notes": "https://ziglang.org/download/0.3.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.3.0/zig-0.3.0.tar.xz",
"shasum": "d70af604f3a8622f3393d93abb3e056bf60351e32d121e6fa4fe03d8d41e1f5a",
"size": "2335592"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.3.0/zig-macos-x86_64-0.3.0.tar.xz",
"shasum": "19dec1f1943ab7be26823376d466f7e456143deb34e17502778a949034dc2e7e",
"size": "23712696"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.3.0/zig-windows-x86_64-0.3.0.zip",
"shasum": "bb568c03950958f8bb3472139c3ab5ed74547c8c694ab50f404c202faf51baf4",
"size": "22524425"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.3.0/zig-linux-x86_64-0.3.0.tar.xz",
"shasum": "b378d0aae30cb54f28494e7bc4efbc9bfb6326f47bfb302e8b5287af777b2f3c",
"size": "25209304"
}
},
"0.2.0": {
"date": "2018-03-15",
"docs": "https://ziglang.org/documentation/0.2.0/",
"notes": "https://ziglang.org/download/0.2.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.2.0/zig-0.2.0.tar.xz",
"shasum": "29c9beb172737f4d5019b88ceae829ae8bc6512fb4386cfbf895ae2b42aa6965",
"size": "1940832"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.2.0/zig-win64-0.2.0.zip",
"shasum": "4f8a2979941a1f081ec8e545cca0b72608c0db1c5a3fd377a94db40649dcd3d4",
"size": "21076274"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.2.0/zig-linux-x86_64-0.2.0.tar.xz",
"shasum": "209c6fb745d42474c0a73d6f291c7ae3a38b6a1b6b641eea285a7f840cc1a890",
"size": "22551928"
}
},
"0.1.1": {
"date": "2017-10-17",
"docs": "https://ziglang.org/documentation/0.1.1/",
"notes": "https://ziglang.org/download/0.1.1/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.1.1/zig-0.1.1.tar.xz",
"shasum": "ffca0cfb263485287e19cc997b08701fcd5f24b700345bcdc3dd8074f5a104e0",
"size": "1659716"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.1.1/zig-win64-0.1.1.zip",
"shasum": "6fc88bef531af7e567fe30bf60da1487b86833cbee84c7a2f3e317030aa5b660",
"size": "19757776"
}
}
}

View File

@@ -24,6 +24,7 @@ packages:
- xz
secrets:
- 51bfddf5-86a6-4e01-8576-358c72a4a0a4
- 44e2bd57-1d07-42bf-925e-22a36119041d
sources:
- https://github.com/ziglang/zig
tasks:

View File

@@ -0,0 +1,104 @@
const std = @import("std");
const path = std.fs.path;
const mem = std.mem;
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
const out_dir = "out";
try std.fs.cwd().makePath(out_dir);
{
const out_file = out_dir ++ path.sep_str ++ "index.html";
const in_file = "index.html";
try render(allocator, in_file, out_file, .html);
}
{
const out_file = out_dir ++ path.sep_str ++ "index.json";
const in_file = "index.json";
try render(allocator, in_file, out_file, .plain);
}
}
fn render(
allocator: *mem.Allocator,
in_file: []const u8,
out_file: []const u8,
fmt: enum {
html,
plain,
},
) !void {
const in_contents = try std.fs.cwd().readFileAlloc(allocator, in_file, 1 * 1024 * 1024);
var vars = try std.process.getEnvMap(allocator);
var buffer = std.ArrayList(u8).init(allocator);
defer buffer.deinit();
const State = enum {
Start,
OpenBrace,
VarName,
EndBrace,
};
const writer = buffer.writer();
var state = State.Start;
var var_name_start: usize = undefined;
var line: usize = 1;
for (in_contents) |byte, index| {
switch (state) {
State.Start => switch (byte) {
'{' => {
state = State.OpenBrace;
},
else => try writer.writeByte(byte),
},
State.OpenBrace => switch (byte) {
'{' => {
state = State.VarName;
var_name_start = index + 1;
},
else => {
try writer.writeByte('{');
try writer.writeByte(byte);
state = State.Start;
},
},
State.VarName => switch (byte) {
'}' => {
const var_name = in_contents[var_name_start..index];
if (vars.get(var_name)) |value| {
const trimmed = mem.trim(u8, value, " \r\n");
if (fmt == .html and mem.endsWith(u8, var_name, "BYTESIZE")) {
const size = try std.fmt.parseInt(u64, trimmed, 10);
try writer.print("{:.1}", .{std.fmt.fmtIntSizeDec(size)});
} else {
try writer.writeAll(trimmed);
}
} else {
std.debug.warn("line {d}: missing variable: {s}\n", .{ line, var_name });
try writer.writeAll("(missing)");
}
state = State.EndBrace;
},
else => {},
},
State.EndBrace => switch (byte) {
'}' => {
state = State.Start;
},
else => {
std.debug.warn("line {d}: invalid byte: '0x{x}'", .{ line, byte });
std.process.exit(1);
},
},
}
if (byte == '\n') {
line += 1;
}
}
try std.fs.cwd().writeFile(out_file, buffer.items);
}

View File

@@ -12,6 +12,7 @@ NATIVE_TARBALL="zig-linux-$(uname -m)-$VERSION.tar.xz"
AARCH64_LINUX_JSON_URL="https://ziglang.org/builds/aarch64-linux-$VERSION.json"
X86_64_LINUX_JSON_URL="https://ziglang.org/builds/x86_64-linux-$VERSION.json"
X86_64_WINDOWS_JSON_URL="https://ziglang.org/builds/x86_64-windows-$VERSION.json"
AARCH64_MACOS_JSON_URL="https://ziglang.org/builds/aarch64-macos-$VERSION.json"
X86_64_MACOS_JSON_URL="https://ziglang.org/builds/x86_64-macos-$VERSION.json"
X86_64_FREEBSD_JSON_URL="https://ziglang.org/builds/x86_64-freebsd-$VERSION.json"
@@ -20,6 +21,7 @@ X86_64_FREEBSD_JSON_URL="https://ziglang.org/builds/x86_64-freebsd-$VERSION.json
curl --fail -I "$AARCH64_LINUX_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_LINUX_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_WINDOWS_JSON_URL" >/dev/null || exit 0
curl --fail -I "$AARCH64_MACOS_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_MACOS_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_FREEBSD_JSON_URL" >/dev/null || exit 0
@@ -28,14 +30,23 @@ curl --fail -I "$X86_64_FREEBSD_JSON_URL" >/dev/null || exit 0
pip3 install s3cmd --user
S3CMD="$HOME/.local/bin/s3cmd"
# This is the user when pushing to the website repo.
git config --global user.email "ziggy@ziglang.org"
git config --global user.name "Ziggy"
# Refresh this with `ssh-keyscan github.com` from a trusted Internet connection.
# We hard code the public key here to detect man-in-the-middle attacks.
echo "github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" >> ~/.ssh/known_hosts
# We don't want the .git folder inside the tarball.
rm -rf .git
cd "$HOME"
wget "https://ziglang.org/builds/$NATIVE_TARBALL"
tar xf "$NATIVE_TARBALL"
ZIGDIR=$(basename $NATIVE_TARBALL .tar.xz)
ZIGDIR="$(pwd)/$(basename $NATIVE_TARBALL .tar.xz)"
ZIG="$ZIGDIR/zig"
LANGREF="$ZIGDIR/langref.html"
LANGREF="$ZIGDIR/docs/langref.html"
SRCTARBALLDIR="zig-$VERSION"
export SRC_TARBALL="$SRCTARBALLDIR.tar.xz"
mv "$SRCDIR" "$SRCTARBALLDIR"
@@ -48,6 +59,11 @@ export X86_64_WINDOWS_TARBALL="$(echo "$X86_64_WINDOWS_JSON" | jq .tarball -r)"
export X86_64_WINDOWS_BYTESIZE="$(echo "$X86_64_WINDOWS_JSON" | jq .size -r)"
export X86_64_WINDOWS_SHASUM="$(echo "$X86_64_WINDOWS_JSON" | jq .shasum -r)"
AARCH64_MACOS_JSON=$(curl --fail "$AARCH64_MACOS_JSON_URL" || exit 1)
export AARCH64_MACOS_TARBALL="$(echo "$AARCH64_MACOS_JSON" | jq .tarball -r)"
export AARCH64_MACOS_BYTESIZE="$(echo "$AARCH64_MACOS_JSON" | jq .size -r)"
export AARCH64_MACOS_SHASUM="$(echo "$AARCH64_MACOS_JSON" | jq .shasum -r)"
X86_64_MACOS_JSON=$(curl --fail "$X86_64_MACOS_JSON_URL" || exit 1)
export X86_64_MACOS_TARBALL="$(echo "$X86_64_MACOS_JSON" | jq .tarball -r)"
export X86_64_MACOS_BYTESIZE="$(echo "$X86_64_MACOS_JSON" | jq .size -r)"
@@ -68,13 +84,29 @@ export X86_64_FREEBSD_TARBALL="$(echo "$X86_64_FREEBSD_JSON" | jq .tarball -r)"
export X86_64_FREEBSD_BYTESIZE="$(echo "$X86_64_FREEBSD_JSON" | jq .size -r)"
export X86_64_FREEBSD_SHASUM="$(echo "$X86_64_FREEBSD_JSON" | jq .shasum -r)"
git clone https://github.com/ziglang/www.ziglang.org --depth 1
cd www.ziglang.org
export MASTER_DATE="$(date +%Y-%m-%d)"
export MASTER_VERSION="$VERSION"
"../$ZIG" run update-download-page.zig
$S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536000, immutable" "../$SRC_TARBALL" s3://ziglang.org/builds/
$S3CMD put -P --no-mime-magic "../$LANGREF" s3://ziglang.org/documentation/master/index.html --add-header="Cache-Control: max-age=0, must-revalidate"
$S3CMD put -P --no-mime-magic www/download/index.html s3://ziglang.org/download/index.html --add-header="Cache-Control: max-age=0, must-revalidate"
$S3CMD put -P --no-mime-magic www/download/index.json s3://ziglang.org/download/index.json --add-header="Cache-Control: max-age=0, must-revalidate"
cd "$SRCTARBALLDIR/ci/srht"
"$ZIG" run update-download-page.zig
CIDIR="$(pwd)"
# Create index.json and index.html and update the website repo.
cd "$HOME"
git clone git@github.com:ziglang/www.ziglang.org.git
cd www.ziglang.org
WWWDIR="$(pwd)"
$S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536000, immutable" "$HOME/$SRC_TARBALL" s3://ziglang.org/builds/
cd "$WWWDIR"
cp "$CIDIR/out/index.json" data/releases.json
mkdir -p content/documentation/master/std
cp "$LANGREF" content/documentation/master/index.html
cp "$ZIGDIR/docs/std/index.html" content/documentation/master/std/index.html
cp "$ZIGDIR/docs/std/data.js" content/documentation/master/std/data.js
cp "$ZIGDIR/docs/std/main.js" content/documentation/master/std/main.js
git add data/releases.json
git add content/
git commit -m "CI: update releases and docs"
git push origin master

View File

@@ -9,27 +9,27 @@
find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
PATHS
/usr/lib/llvm/11/include
/usr/lib/llvm-11/include
/usr/lib/llvm-11.0/include
/usr/local/llvm110/include
/usr/local/llvm11/include
/usr/lib/llvm/12/include
/usr/lib/llvm-12/include
/usr/lib/llvm-12.0/include
/usr/local/llvm120/include
/usr/local/llvm12/include
/mingw64/include
)
if(ZIG_PREFER_CLANG_CPP_DYLIB)
find_library(CLANG_LIBRARIES
NAMES
clang-cpp-11.0
clang-cpp110
clang-cpp-12.0
clang-cpp120
clang-cpp
PATHS
${CLANG_LIBDIRS}
/usr/lib/llvm/11/lib
/usr/lib/llvm/11/lib64
/usr/lib/llvm-11/lib
/usr/local/llvm110/lib
/usr/local/llvm11/lib
/usr/lib/llvm/12/lib
/usr/lib/llvm/12/lib64
/usr/lib/llvm-12/lib
/usr/local/llvm120/lib
/usr/local/llvm12/lib
)
endif()
@@ -39,11 +39,11 @@ if(NOT CLANG_LIBRARIES)
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_}
PATHS
${CLANG_LIBDIRS}
/usr/lib/llvm/11/lib
/usr/lib/llvm-11/lib
/usr/lib/llvm-11.0/lib
/usr/local/llvm110/lib
/usr/local/llvm11/lib
/usr/lib/llvm/12/lib
/usr/lib/llvm-12/lib
/usr/lib/llvm-12.0/lib
/usr/local/llvm120/lib
/usr/local/llvm12/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:\\msys64\\mingw64\\lib

View File

@@ -8,16 +8,16 @@
find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
PATHS
/usr/lib/llvm-11/include
/usr/local/llvm110/include
/usr/local/llvm11/include
/usr/lib/llvm-12/include
/usr/local/llvm120/include
/usr/local/llvm12/include
/mingw64/include)
find_library(LLD_LIBRARY NAMES lld-11.0 lld110 lld
find_library(LLD_LIBRARY NAMES lld-12.0 lld120 lld
PATHS
/usr/lib/llvm-11/lib
/usr/local/llvm110/lib
/usr/local/llvm11/lib
/usr/lib/llvm-12/lib
/usr/local/llvm120/lib
/usr/local/llvm12/lib
)
if(EXISTS ${LLD_LIBRARY})
set(LLD_LIBRARIES ${LLD_LIBRARY})
@@ -27,9 +27,9 @@ else()
find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_}
PATHS
${LLD_LIBDIRS}
/usr/lib/llvm-11/lib
/usr/local/llvm110/lib
/usr/local/llvm11/lib
/usr/lib/llvm-12/lib
/usr/local/llvm120/lib
/usr/local/llvm12/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:/msys64/mingw64/lib)

View File

@@ -9,37 +9,37 @@
find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h
PATHS
/usr/lib/llvm/11/include
/usr/lib/llvm-11/include
/usr/lib/llvm-11.0/include
/usr/local/llvm11/include
/usr/local/llvm110/include
/usr/lib/llvm/12/include
/usr/lib/llvm-12/include
/usr/lib/llvm-12.0/include
/usr/local/llvm12/include
/usr/local/llvm120/include
/mingw64/include
)
if(ZIG_PREFER_CLANG_CPP_DYLIB)
find_library(LLVM_LIBRARIES
NAMES
LLVM-11.0
LLVM-11
LLVM-110
LLVM-12.0
LLVM-12
LLVM-120
LLVM
PATHS
${LLVM_LIBDIRS}
/usr/lib/llvm/11/lib
/usr/lib/llvm/11/lib64
/usr/lib/llvm-11/lib
/usr/local/llvm11/lib
/usr/local/llvm110/lib
/usr/lib/llvm/12/lib
/usr/lib/llvm/12/lib64
/usr/lib/llvm-12/lib
/usr/local/llvm12/lib
/usr/local/llvm120/lib
)
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-11 llvm-config-11.0 llvm-config110 llvm-config11 llvm-config
NAMES llvm-config-12 llvm-config-12.0 llvm-config120 llvm-config12 llvm-config
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-11.0.0/bin")
"C:/Libraries/llvm-12.0.0/bin")
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
@@ -54,23 +54,23 @@ if(ZIG_PREFER_CLANG_CPP_DYLIB)
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 11)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 12)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 12)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 12)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
elseif(("${ZIG_TARGET_TRIPLE}" STREQUAL "native") OR ZIG_PREFER_LLVM_CONFIG)
elseif(ZIG_USE_LLVM_CONFIG)
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-11 llvm-config-11.0 llvm-config110 llvm-config11 llvm-config
NAMES llvm-config-12 llvm-config-12.0 llvm-config120 llvm-config12 llvm-config
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-11.0.0/bin")
"C:/Libraries/llvm-12.0.0/bin")
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
@@ -85,14 +85,14 @@ elseif(("${ZIG_TARGET_TRIPLE}" STREQUAL "native") OR ZIG_PREFER_LLVM_CONFIG)
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 11)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 12)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 12)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 12)
message(FATAL_ERROR "expected LLVM 11.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
execute_process(
@@ -166,7 +166,7 @@ elseif(("${ZIG_TARGET_TRIPLE}" STREQUAL "native") OR ZIG_PREFER_LLVM_CONFIG)
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
if(NOT LLVM_LIBRARIES)
find_library(LLVM_LIBRARIES NAMES LLVM LLVM-11 LLVM-11.0)
find_library(LLVM_LIBRARIES NAMES LLVM LLVM-12 LLVM-12.0)
endif()
link_directories("${CMAKE_PREFIX_PATH}/lib")
@@ -180,11 +180,11 @@ else()
find_library(LLVM_${_prettylibname_}_LIB NAMES ${_libname_}
PATHS
${LLVM_LIBDIRS}
/usr/lib/llvm/11/lib
/usr/lib/llvm-11/lib
/usr/lib/llvm-11.0/lib
/usr/local/llvm110/lib
/usr/local/llvm11/lib
/usr/lib/llvm/12/lib
/usr/lib/llvm-12/lib
/usr/lib/llvm-12.0/lib
/usr/local/llvm120/lib
/usr/local/llvm12/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:\\msys64\\mingw64\\lib)
@@ -194,78 +194,57 @@ else()
# This list can be re-generated with `llvm-config --libfiles` and then
# reformatting using your favorite text editor. Note we do not execute
# `llvm-config` here because we are cross compiling.
FIND_AND_ADD_LLVM_LIB(LLVMXRay)
FIND_AND_ADD_LLVM_LIB(LLVMWindowsManifest)
FIND_AND_ADD_LLVM_LIB(LLVMSymbolize)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)
FIND_AND_ADD_LLVM_LIB(LLVMOrcError)
FIND_AND_ADD_LLVM_LIB(LLVMJITLink)
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
FIND_AND_ADD_LLVM_LIB(LLVMMCA)
FIND_AND_ADD_LLVM_LIB(LLVMLTO)
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
FIND_AND_ADD_LLVM_LIB(LLVMObjCARCOpts)
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
FIND_AND_ADD_LLVM_LIB(LLVMLineEditor)
FIND_AND_ADD_LLVM_LIB(LLVMXRay)
FIND_AND_ADD_LLVM_LIB(LLVMLibDriver)
FIND_AND_ADD_LLVM_LIB(LLVMInterpreter)
FIND_AND_ADD_LLVM_LIB(LLVMFuzzMutate)
FIND_AND_ADD_LLVM_LIB(LLVMMCJIT)
FIND_AND_ADD_LLVM_LIB(LLVMExecutionEngine)
FIND_AND_ADD_LLVM_LIB(LLVMRuntimeDyld)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinker)
FIND_AND_ADD_LLVM_LIB(LLVMDlltoolDriver)
FIND_AND_ADD_LLVM_LIB(LLVMOption)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
FIND_AND_ADD_LLVM_LIB(LLVMCoverage)
FIND_AND_ADD_LLVM_LIB(LLVMLineEditor)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDesc)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreInfo)
FIND_AND_ADD_LLVM_LIB(LLVMX86Disassembler)
FIND_AND_ADD_LLVM_LIB(LLVMX86CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMX86AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMX86CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMX86Desc)
FIND_AND_ADD_LLVM_LIB(LLVMX86Info)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyDesc)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyInfo)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZDesc)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZInfo)
FIND_AND_ADD_LLVM_LIB(LLVMSparcDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMSparcCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMSparcAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMSparcCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMSparcDesc)
FIND_AND_ADD_LLVM_LIB(LLVMSparcInfo)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVDesc)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVUtils)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVInfo)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCDesc)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCInfo)
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXDesc)
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXInfo)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Disassembler)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Desc)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Info)
FIND_AND_ADD_LLVM_LIB(LLVMMipsDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMMipsCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMMipsAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMipsCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMMipsDesc)
FIND_AND_ADD_LLVM_LIB(LLVMMipsInfo)
FIND_AND_ADD_LLVM_LIB(LLVMLanaiDisassembler)
@@ -279,44 +258,73 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMHexagonDesc)
FIND_AND_ADD_LLVM_LIB(LLVMHexagonInfo)
FIND_AND_ADD_LLVM_LIB(LLVMBPFDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMBPFCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMBPFAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMBPFCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMBPFDesc)
FIND_AND_ADD_LLVM_LIB(LLVMBPFInfo)
FIND_AND_ADD_LLVM_LIB(LLVMAVRDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMAVRCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMAVRAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAVRCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMAVRDesc)
FIND_AND_ADD_LLVM_LIB(LLVMAVRInfo)
FIND_AND_ADD_LLVM_LIB(LLVMARMDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMARMCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMARMAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMARMCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMARMDesc)
FIND_AND_ADD_LLVM_LIB(LLVMARMUtils)
FIND_AND_ADD_LLVM_LIB(LLVMARMInfo)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMMIRParser)
FIND_AND_ADD_LLVM_LIB(LLVMipo)
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
FIND_AND_ADD_LLVM_LIB(LLVMIRReader)
FIND_AND_ADD_LLVM_LIB(LLVMAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUDesc)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUUtils)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUInfo)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Disassembler)
FIND_AND_ADD_LLVM_LIB(LLVMMCDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Desc)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Utils)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Info)
FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)
FIND_AND_ADD_LLVM_LIB(LLVMMCJIT)
FIND_AND_ADD_LLVM_LIB(LLVMJITLink)
FIND_AND_ADD_LLVM_LIB(LLVMOrcTargetProcess)
FIND_AND_ADD_LLVM_LIB(LLVMOrcShared)
FIND_AND_ADD_LLVM_LIB(LLVMInterpreter)
FIND_AND_ADD_LLVM_LIB(LLVMExecutionEngine)
FIND_AND_ADD_LLVM_LIB(LLVMRuntimeDyld)
FIND_AND_ADD_LLVM_LIB(LLVMSymbolize)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
FIND_AND_ADD_LLVM_LIB(LLVMOption)
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
FIND_AND_ADD_LLVM_LIB(LLVMMCA)
FIND_AND_ADD_LLVM_LIB(LLVMMCDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMLTO)
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
FIND_AND_ADD_LLVM_LIB(LLVMCFGuard)
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
FIND_AND_ADD_LLVM_LIB(LLVMObjCARCOpts)
FIND_AND_ADD_LLVM_LIB(LLVMHelloNew)
FIND_AND_ADD_LLVM_LIB(LLVMipo)
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenACC)
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinker)
FIND_AND_ADD_LLVM_LIB(LLVMGlobalISel)
FIND_AND_ADD_LLVM_LIB(LLVMSelectionDAG)
FIND_AND_ADD_LLVM_LIB(LLVMMIRParser)
FIND_AND_ADD_LLVM_LIB(LLVMAsmPrinter)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARF)
FIND_AND_ADD_LLVM_LIB(LLVMSelectionDAG)
FIND_AND_ADD_LLVM_LIB(LLVMCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMIRReader)
FIND_AND_ADD_LLVM_LIB(LLVMAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMInterfaceStub)
FIND_AND_ADD_LLVM_LIB(LLVMFileCheck)
FIND_AND_ADD_LLVM_LIB(LLVMFuzzMutate)
FIND_AND_ADD_LLVM_LIB(LLVMTarget)
FIND_AND_ADD_LLVM_LIB(LLVMScalarOpts)
FIND_AND_ADD_LLVM_LIB(LLVMInstCombine)
@@ -327,19 +335,15 @@ else()
FIND_AND_ADD_LLVM_LIB(LLVMProfileData)
FIND_AND_ADD_LLVM_LIB(LLVMObject)
FIND_AND_ADD_LLVM_LIB(LLVMTextAPI)
FIND_AND_ADD_LLVM_LIB(LLVMMCParser)
FIND_AND_ADD_LLVM_LIB(LLVMMC)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoCodeView)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoMSF)
FIND_AND_ADD_LLVM_LIB(LLVMBitReader)
FIND_AND_ADD_LLVM_LIB(LLVMCore)
FIND_AND_ADD_LLVM_LIB(LLVMRemarks)
FIND_AND_ADD_LLVM_LIB(LLVMBitstreamReader)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMCParser)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Desc)
FIND_AND_ADD_LLVM_LIB(LLVMMC)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoCodeView)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoMSF)
FIND_AND_ADD_LLVM_LIB(LLVMBinaryFormat)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Utils)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Info)
FIND_AND_ADD_LLVM_LIB(LLVMSupport)
FIND_AND_ADD_LLVM_LIB(LLVMDemangle)
endif()

View File

@@ -4,6 +4,7 @@ const io = std.io;
const fs = std.fs;
const process = std.process;
const ChildProcess = std.ChildProcess;
const Progress = std.Progress;
const print = std.debug.print;
const mem = std.mem;
const testing = std.testing;
@@ -34,15 +35,24 @@ pub fn main() !void {
const out_file_name = try (args_it.next(allocator) orelse @panic("expected output arg"));
defer allocator.free(out_file_name);
var do_code_tests = true;
if (args_it.next(allocator)) |arg| {
if (mem.eql(u8, try arg, "--skip-code-tests")) {
do_code_tests = false;
} else {
@panic("unrecognized arg");
}
}
var in_file = try fs.cwd().openFile(in_file_name, .{ .read = true });
defer in_file.close();
var out_file = try fs.cwd().createFile(out_file_name, .{});
defer out_file.close();
const input_file_bytes = try in_file.inStream().readAllAlloc(allocator, max_doc_file_size);
const input_file_bytes = try in_file.reader().readAllAlloc(allocator, max_doc_file_size);
var buffered_out_stream = io.bufferedOutStream(out_file.outStream());
var buffered_writer = io.bufferedWriter(out_file.writer());
var tokenizer = Tokenizer.init(in_file_name, input_file_bytes);
var toc = try genToc(allocator, &tokenizer);
@@ -50,8 +60,8 @@ pub fn main() !void {
try fs.cwd().makePath(tmp_dir_name);
defer fs.cwd().deleteTree(tmp_dir_name) catch {};
try genHtml(allocator, &tokenizer, &toc, buffered_out_stream.outStream(), zig_exe);
try buffered_out_stream.flush();
try genHtml(allocator, &tokenizer, &toc, buffered_writer.writer(), zig_exe, do_code_tests);
try buffered_writer.flush();
}
const Token = struct {
@@ -215,9 +225,9 @@ const Tokenizer = struct {
fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: anytype) anyerror {
const loc = tokenizer.getTokenLocation(token);
const args_prefix = .{ tokenizer.source_file_name, loc.line + 1, loc.column + 1 };
print("{}:{}:{}: error: " ++ fmt ++ "\n", args_prefix ++ args);
print("{s}:{d}:{d}: error: " ++ fmt ++ "\n", args_prefix ++ args);
if (loc.line_start <= loc.line_end) {
print("{}\n", .{tokenizer.buffer[loc.line_start..loc.line_end]});
print("{s}\n", .{tokenizer.buffer[loc.line_start..loc.line_end]});
{
var i: usize = 0;
while (i < loc.column) : (i += 1) {
@@ -225,7 +235,7 @@ fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, arg
}
}
{
const caret_count = token.end - token.start;
const caret_count = std.math.min(token.end, loc.line_end) - token.start;
var i: usize = 0;
while (i < caret_count) : (i += 1) {
print("~", .{});
@@ -238,7 +248,7 @@ fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, arg
fn assertToken(tokenizer: *Tokenizer, token: Token, id: Token.Id) !void {
if (token.id != id) {
return parseError(tokenizer, token, "expected {}, found {}", .{ @tagName(id), @tagName(token.id) });
return parseError(tokenizer, token, "expected {s}, found {s}", .{ @tagName(id), @tagName(token.id) });
}
}
@@ -274,6 +284,7 @@ const Code = struct {
link_objects: []const []const u8,
target_str: ?[]const u8,
link_libc: bool,
link_mode: ?std.builtin.LinkMode,
disable_cache: bool,
const Id = union(enum) {
@@ -325,7 +336,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
var toc_buf = std.ArrayList(u8).init(allocator);
defer toc_buf.deinit();
var toc = toc_buf.outStream();
var toc = toc_buf.writer();
var nodes = std.ArrayList(Node).init(allocator);
defer nodes.deinit();
@@ -374,7 +385,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
return parseError(
tokenizer,
bracket_tok,
"unrecognized header_open param: {}",
"unrecognized header_open param: {s}",
.{param},
);
}
@@ -393,9 +404,9 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
.n = header_stack_size,
},
});
if (try urls.fetchPut(urlized, tag_token)) |entry| {
parseError(tokenizer, tag_token, "duplicate header url: #{}", .{urlized}) catch {};
parseError(tokenizer, entry.value, "other tag here", .{}) catch {};
if (try urls.fetchPut(urlized, tag_token)) |kv| {
parseError(tokenizer, tag_token, "duplicate header url: #{s}", .{urlized}) catch {};
parseError(tokenizer, kv.value, "other tag here", .{}) catch {};
return error.ParseError;
}
if (last_action == Action.Open) {
@@ -411,7 +422,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
}
last_columns = columns;
try toc.writeByteNTimes(' ', 4 + header_stack_size * 4);
try toc.print("<li><a id=\"toc-{}\" href=\"#{}\">{}</a>", .{ urlized, urlized, content });
try toc.print("<li><a id=\"toc-{s}\" href=\"#{s}\">{s}</a>", .{ urlized, urlized, content });
} else if (mem.eql(u8, tag_name, "header_close")) {
if (header_stack_size == 0) {
return parseError(tokenizer, tag_token, "unbalanced close header", .{});
@@ -515,7 +526,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
code_kind_id = Code.Id{ .Obj = null };
is_inline = true;
} else {
return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {}", .{code_kind_str});
return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {s}", .{code_kind_str});
}
var mode: builtin.Mode = .Debug;
@@ -523,6 +534,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
defer link_objects.deinit();
var target_str: ?[]const u8 = null;
var link_libc = false;
var link_mode: ?std.builtin.LinkMode = null;
var disable_cache = false;
const source_token = while (true) {
@@ -552,6 +564,8 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
target_str = "wasm32-wasi";
} else if (mem.eql(u8, end_tag_name, "link_libc")) {
link_libc = true;
} else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) {
link_mode = .Dynamic;
} else if (mem.eql(u8, end_tag_name, "code_end")) {
_ = try eatToken(tokenizer, Token.Id.BracketClose);
break content_tok;
@@ -559,13 +573,12 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
return parseError(
tokenizer,
end_code_tag,
"invalid token inside code_begin: {}",
"invalid token inside code_begin: {s}",
.{end_tag_name},
);
}
_ = try eatToken(tokenizer, Token.Id.BracketClose);
} else
unreachable; // TODO issue #707
} else unreachable; // TODO issue #707
try nodes.append(Node{
.Code = Code{
.id = code_kind_id,
@@ -576,6 +589,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
.link_objects = link_objects.toOwnedSlice(),
.target_str = target_str,
.link_libc = link_libc,
.link_mode = link_mode,
.disable_cache = disable_cache,
},
});
@@ -590,14 +604,14 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
return parseError(
tokenizer,
end_syntax_tag,
"invalid token inside syntax: {}",
"invalid token inside syntax: {s}",
.{end_tag_name},
);
}
_ = try eatToken(tokenizer, Token.Id.BracketClose);
try nodes.append(Node{ .Syntax = content_tok });
} else {
return parseError(tokenizer, tag_token, "unrecognized tag name: {}", .{tag_name});
return parseError(tokenizer, tag_token, "unrecognized tag name: {s}", .{tag_name});
}
},
else => return parseError(tokenizer, token, "invalid token", .{}),
@@ -615,7 +629,7 @@ fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
var buf = std.ArrayList(u8).init(allocator);
defer buf.deinit();
const out = buf.outStream();
const out = buf.writer();
for (input) |c| {
switch (c) {
'a'...'z', 'A'...'Z', '_', '-', '0'...'9' => {
@@ -634,7 +648,7 @@ fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
var buf = std.ArrayList(u8).init(allocator);
defer buf.deinit();
const out = buf.outStream();
const out = buf.writer();
try writeEscaped(out, input);
return buf.toOwnedSlice();
}
@@ -680,7 +694,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
var buf = std.ArrayList(u8).init(allocator);
defer buf.deinit();
var out = buf.outStream();
var out = buf.writer();
var number_start_index: usize = undefined;
var first_number: usize = undefined;
var second_number: usize = undefined;
@@ -744,7 +758,7 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
try out.writeAll("</span>");
}
if (first_number != 0 or second_number != 0) {
try out.print("<span class=\"t{}_{}\">", .{ first_number, second_number });
try out.print("<span class=\"t{d}_{d}\">", .{ first_number, second_number });
open_span_count += 1;
}
},
@@ -781,106 +795,119 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:
next_tok_is_fn = false;
const token = tokenizer.next();
try writeEscaped(out, src[index..token.loc.start]);
switch (token.id) {
.Eof => break,
if (mem.indexOf(u8, src[index..token.loc.start], "//")) |comment_start_off| {
// render one comment
const comment_start = index + comment_start_off;
const comment_end_off = mem.indexOf(u8, src[comment_start..token.loc.start], "\n");
const comment_end = if (comment_end_off) |o| comment_start + o else token.loc.start;
.Keyword_align,
.Keyword_and,
.Keyword_asm,
.Keyword_async,
.Keyword_await,
.Keyword_break,
.Keyword_catch,
.Keyword_comptime,
.Keyword_const,
.Keyword_continue,
.Keyword_defer,
.Keyword_else,
.Keyword_enum,
.Keyword_errdefer,
.Keyword_error,
.Keyword_export,
.Keyword_extern,
.Keyword_for,
.Keyword_if,
.Keyword_inline,
.Keyword_noalias,
.Keyword_noinline,
.Keyword_nosuspend,
.Keyword_opaque,
.Keyword_or,
.Keyword_orelse,
.Keyword_packed,
.Keyword_anyframe,
.Keyword_pub,
.Keyword_resume,
.Keyword_return,
.Keyword_linksection,
.Keyword_callconv,
.Keyword_struct,
.Keyword_suspend,
.Keyword_switch,
.Keyword_test,
.Keyword_threadlocal,
.Keyword_try,
.Keyword_union,
.Keyword_unreachable,
.Keyword_usingnamespace,
.Keyword_var,
.Keyword_volatile,
.Keyword_allowzero,
.Keyword_while,
.Keyword_anytype,
try writeEscaped(out, src[index..comment_start]);
try out.writeAll("<span class=\"tok-comment\">");
try writeEscaped(out, src[comment_start..comment_end]);
try out.writeAll("</span>");
index = comment_end;
tokenizer.index = index;
continue;
}
try writeEscaped(out, src[index..token.loc.start]);
switch (token.tag) {
.eof => break,
.keyword_align,
.keyword_and,
.keyword_asm,
.keyword_async,
.keyword_await,
.keyword_break,
.keyword_catch,
.keyword_comptime,
.keyword_const,
.keyword_continue,
.keyword_defer,
.keyword_else,
.keyword_enum,
.keyword_errdefer,
.keyword_error,
.keyword_export,
.keyword_extern,
.keyword_for,
.keyword_if,
.keyword_inline,
.keyword_noalias,
.keyword_noinline,
.keyword_nosuspend,
.keyword_opaque,
.keyword_or,
.keyword_orelse,
.keyword_packed,
.keyword_anyframe,
.keyword_pub,
.keyword_resume,
.keyword_return,
.keyword_linksection,
.keyword_callconv,
.keyword_struct,
.keyword_suspend,
.keyword_switch,
.keyword_test,
.keyword_threadlocal,
.keyword_try,
.keyword_union,
.keyword_unreachable,
.keyword_usingnamespace,
.keyword_var,
.keyword_volatile,
.keyword_allowzero,
.keyword_while,
.keyword_anytype,
=> {
try out.writeAll("<span class=\"tok-kw\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try out.writeAll("</span>");
},
.Keyword_fn => {
.keyword_fn => {
try out.writeAll("<span class=\"tok-kw\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try out.writeAll("</span>");
next_tok_is_fn = true;
},
.Keyword_undefined,
.Keyword_null,
.Keyword_true,
.Keyword_false,
.keyword_undefined,
.keyword_null,
.keyword_true,
.keyword_false,
=> {
try out.writeAll("<span class=\"tok-null\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try out.writeAll("</span>");
},
.StringLiteral,
.MultilineStringLiteralLine,
.CharLiteral,
.string_literal,
.multiline_string_literal_line,
.char_literal,
=> {
try out.writeAll("<span class=\"tok-str\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try out.writeAll("</span>");
},
.Builtin => {
.builtin => {
try out.writeAll("<span class=\"tok-builtin\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try out.writeAll("</span>");
},
.LineComment,
.DocComment,
.ContainerDocComment,
.ShebangLine,
.doc_comment,
.container_doc_comment,
=> {
try out.writeAll("<span class=\"tok-comment\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try out.writeAll("</span>");
},
.Identifier => {
.identifier => {
if (prev_tok_was_fn) {
try out.writeAll("<span class=\"tok-fn\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
@@ -908,71 +935,71 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: anytype, source_token:
}
},
.IntegerLiteral,
.FloatLiteral,
.integer_literal,
.float_literal,
=> {
try out.writeAll("<span class=\"tok-number\">");
try writeEscaped(out, src[token.loc.start..token.loc.end]);
try out.writeAll("</span>");
},
.Bang,
.Pipe,
.PipePipe,
.PipeEqual,
.Equal,
.EqualEqual,
.EqualAngleBracketRight,
.BangEqual,
.LParen,
.RParen,
.Semicolon,
.Percent,
.PercentEqual,
.LBrace,
.RBrace,
.LBracket,
.RBracket,
.Period,
.PeriodAsterisk,
.Ellipsis2,
.Ellipsis3,
.Caret,
.CaretEqual,
.Plus,
.PlusPlus,
.PlusEqual,
.PlusPercent,
.PlusPercentEqual,
.Minus,
.MinusEqual,
.MinusPercent,
.MinusPercentEqual,
.Asterisk,
.AsteriskEqual,
.AsteriskAsterisk,
.AsteriskPercent,
.AsteriskPercentEqual,
.Arrow,
.Colon,
.Slash,
.SlashEqual,
.Comma,
.Ampersand,
.AmpersandEqual,
.QuestionMark,
.AngleBracketLeft,
.AngleBracketLeftEqual,
.AngleBracketAngleBracketLeft,
.AngleBracketAngleBracketLeftEqual,
.AngleBracketRight,
.AngleBracketRightEqual,
.AngleBracketAngleBracketRight,
.AngleBracketAngleBracketRightEqual,
.Tilde,
.bang,
.pipe,
.pipe_pipe,
.pipe_equal,
.equal,
.equal_equal,
.equal_angle_bracket_right,
.bang_equal,
.l_paren,
.r_paren,
.semicolon,
.percent,
.percent_equal,
.l_brace,
.r_brace,
.l_bracket,
.r_bracket,
.period,
.period_asterisk,
.ellipsis2,
.ellipsis3,
.caret,
.caret_equal,
.plus,
.plus_plus,
.plus_equal,
.plus_percent,
.plus_percent_equal,
.minus,
.minus_equal,
.minus_percent,
.minus_percent_equal,
.asterisk,
.asterisk_equal,
.asterisk_asterisk,
.asterisk_percent,
.asterisk_percent_equal,
.arrow,
.colon,
.slash,
.slash_equal,
.comma,
.ampersand,
.ampersand_equal,
.question_mark,
.angle_bracket_left,
.angle_bracket_left_equal,
.angle_bracket_angle_bracket_left,
.angle_bracket_angle_bracket_left_equal,
.angle_bracket_right,
.angle_bracket_right_equal,
.angle_bracket_angle_bracket_right,
.angle_bracket_angle_bracket_right_equal,
.tilde,
=> try writeEscaped(out, src[token.loc.start..token.loc.end]),
.Invalid, .Invalid_ampersands, .Invalid_periodasterisks => return parseError(
.invalid, .invalid_ampersands, .invalid_periodasterisks => return parseError(
docgen_tokenizer,
source_token,
"syntax error",
@@ -989,24 +1016,28 @@ fn tokenizeAndPrint(docgen_tokenizer: *Tokenizer, out: anytype, source_token: To
return tokenizeAndPrintRaw(docgen_tokenizer, out, source_token, raw_src);
}
fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8) !void {
fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: anytype, zig_exe: []const u8, do_code_tests: bool) !void {
var code_progress_index: usize = 0;
var progress = Progress{};
const root_node = try progress.start("Generating docgen examples", toc.nodes.len);
defer root_node.end();
var env_map = try process.getEnvMap(allocator);
try env_map.set("ZIG_DEBUG_COLOR", "1");
try env_map.put("ZIG_DEBUG_COLOR", "1");
const builtin_code = try getBuiltinCode(allocator, &env_map, zig_exe);
for (toc.nodes) |node| {
defer root_node.completeOne();
switch (node) {
.Content => |data| {
try out.writeAll(data);
},
.Link => |info| {
if (!toc.urls.contains(info.url)) {
return parseError(tokenizer, info.token, "url not found: {}", .{info.url});
return parseError(tokenizer, info.token, "url not found: {s}", .{info.url});
}
try out.print("<a href=\"#{}\">{}</a>", .{ info.url, info.name });
try out.print("<a href=\"#{s}\">{s}</a>", .{ info.url, info.name });
},
.Nav => {
try out.writeAll(toc.toc);
@@ -1018,7 +1049,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
},
.HeaderOpen => |info| {
try out.print(
"<h{} id=\"{}\"><a href=\"#toc-{}\">{}</a> <a class=\"hdr\" href=\"#{}\">§</a></h{}>\n",
"<h{d} id=\"{s}\"><a href=\"#toc-{s}\">{s}</a> <a class=\"hdr\" href=\"#{s}\">§</a></h{d}>\n",
.{ info.n, info.url, info.url, info.name, info.url, info.n },
);
},
@@ -1027,9 +1058,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
for (items) |item| {
const url = try urlize(allocator, item.name);
if (!toc.urls.contains(url)) {
return parseError(tokenizer, item.token, "url not found: {}", .{url});
return parseError(tokenizer, item.token, "url not found: {s}", .{url});
}
try out.print("<li><a href=\"#{}\">{}</a></li>\n", .{ url, item.name });
try out.print("<li><a href=\"#{s}\">{s}</a></li>\n", .{ url, item.name });
}
try out.writeAll("</ul>\n");
},
@@ -1037,18 +1068,20 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
try tokenizeAndPrint(tokenizer, out, content_tok);
},
.Code => |code| {
code_progress_index += 1;
print("docgen example code {}/{}...", .{ code_progress_index, tokenizer.code_node_count });
const raw_source = tokenizer.buffer[code.source_token.start..code.source_token.end];
const trimmed_raw_source = mem.trim(u8, raw_source, " \n");
if (!code.is_inline) {
try out.print("<p class=\"file\">{}.zig</p>", .{code.name});
try out.print("<p class=\"file\">{s}.zig</p>", .{code.name});
}
try out.writeAll("<pre>");
try tokenizeAndPrint(tokenizer, out, code.source_token);
try out.writeAll("</pre>");
const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", .{code.name});
if (!do_code_tests) {
continue;
}
const name_plus_ext = try std.fmt.allocPrint(allocator, "{s}.zig", .{code.name});
const tmp_source_file_name = try fs.path.join(
allocator,
&[_][]const u8{ tmp_dir_name, name_plus_ext },
@@ -1057,7 +1090,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
switch (code.id) {
Code.Id.Exe => |expected_outcome| code_block: {
const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ code.name, exe_ext });
const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ code.name, exe_ext });
var build_args = std.ArrayList([]const u8).init(allocator);
defer build_args.deinit();
try build_args.appendSlice(&[_][]const u8{
@@ -1066,7 +1099,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
"--color", "on",
"--enable-cache", tmp_source_file_name,
});
try out.print("<pre><code class=\"shell\">$ zig build-exe {}.zig", .{code.name});
try out.print("<pre><code class=\"shell\">$ zig build-exe {s}.zig", .{code.name});
switch (code.mode) {
.Debug => {},
else => {
@@ -1075,7 +1108,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
},
}
for (code.link_objects) |link_object| {
const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ link_object, obj_ext });
const name_with_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ link_object, obj_ext });
const full_path_object = try fs.path.join(
allocator,
&[_][]const u8{ tmp_dir_name, name_with_ext },
@@ -1093,7 +1126,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
if (code.target_str) |triple| {
try build_args.appendSlice(&[_][]const u8{ "-target", triple });
if (!code.is_inline) {
try out.print(" -target {}", .{triple});
try out.print(" -target {s}", .{triple});
}
}
if (expected_outcome == .BuildFail) {
@@ -1106,20 +1139,22 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
switch (result.term) {
.Exited => |exit_code| {
if (exit_code == 0) {
print("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
progress.log("", .{});
print("{s}\nThe following command incorrectly succeeded:\n", .{result.stderr});
dumpArgs(build_args.items);
return parseError(tokenizer, code.source_token, "example incorrectly compiled", .{});
}
},
else => {
print("{}\nThe following command crashed:\n", .{result.stderr});
progress.log("", .{});
print("{s}\nThe following command crashed:\n", .{result.stderr});
dumpArgs(build_args.items);
return parseError(tokenizer, code.source_token, "example compile crashed", .{});
},
}
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const colored_stderr = try termColor(allocator, escaped_stderr);
try out.print("\n{}</code></pre>\n", .{colored_stderr});
try out.print("\n{s}</code></pre>\n", .{colored_stderr});
break :code_block;
}
const exec_result = exec(allocator, &env_map, build_args.items) catch
@@ -1138,7 +1173,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
}
const path_to_exe_dir = mem.trim(u8, exec_result.stdout, " \r\n");
const path_to_exe_basename = try std.fmt.allocPrint(allocator, "{}{}", .{
const path_to_exe_basename = try std.fmt.allocPrint(allocator, "{s}{s}", .{
code.name,
target.exeFileExt(),
});
@@ -1160,7 +1195,8 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
switch (result.term) {
.Exited => |exit_code| {
if (exit_code == 0) {
print("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
progress.log("", .{});
print("{s}\nThe following command incorrectly succeeded:\n", .{result.stderr});
dumpArgs(run_args);
return parseError(tokenizer, code.source_token, "example incorrectly compiled", .{});
}
@@ -1179,7 +1215,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
const colored_stderr = try termColor(allocator, escaped_stderr);
const colored_stdout = try termColor(allocator, escaped_stdout);
try out.print("\n$ ./{}\n{}{}", .{ code.name, colored_stdout, colored_stderr });
try out.print("\n$ ./{s}\n{s}{s}", .{ code.name, colored_stdout, colored_stderr });
if (exited_with_signal) {
try out.print("(process terminated by signal)", .{});
}
@@ -1190,7 +1226,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
defer test_args.deinit();
try test_args.appendSlice(&[_][]const u8{ zig_exe, "test", tmp_source_file_name });
try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name});
try out.print("<pre><code class=\"shell\">$ zig test {s}.zig", .{code.name});
switch (code.mode) {
.Debug => {},
else => {
@@ -1204,12 +1240,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
}
if (code.target_str) |triple| {
try test_args.appendSlice(&[_][]const u8{ "-target", triple });
try out.print(" -target {}", .{triple});
try out.print(" -target {s}", .{triple});
}
const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const escaped_stdout = try escapeHtml(allocator, result.stdout);
try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
try out.print("\n{s}{s}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
},
Code.Id.TestError => |error_match| {
var test_args = std.ArrayList([]const u8).init(allocator);
@@ -1222,7 +1258,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
"on",
tmp_source_file_name,
});
try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name});
try out.print("<pre><code class=\"shell\">$ zig test {s}.zig", .{code.name});
switch (code.mode) {
.Debug => {},
else => {
@@ -1239,24 +1275,27 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
switch (result.term) {
.Exited => |exit_code| {
if (exit_code == 0) {
print("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
progress.log("", .{});
print("{s}\nThe following command incorrectly succeeded:\n", .{result.stderr});
dumpArgs(test_args.items);
return parseError(tokenizer, code.source_token, "example incorrectly compiled", .{});
}
},
else => {
print("{}\nThe following command crashed:\n", .{result.stderr});
progress.log("", .{});
print("{s}\nThe following command crashed:\n", .{result.stderr});
dumpArgs(test_args.items);
return parseError(tokenizer, code.source_token, "example compile crashed", .{});
},
}
if (mem.indexOf(u8, result.stderr, error_match) == null) {
print("{}\nExpected to find '{}' in stderr\n", .{ result.stderr, error_match });
progress.log("", .{});
print("{s}\nExpected to find '{s}' in stderr\n", .{ result.stderr, error_match });
return parseError(tokenizer, code.source_token, "example did not have expected compile error", .{});
}
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const colored_stderr = try termColor(allocator, escaped_stderr);
try out.print("\n{}</code></pre>\n", .{colored_stderr});
try out.print("\n{s}</code></pre>\n", .{colored_stderr});
},
Code.Id.TestSafety => |error_match| {
@@ -1294,31 +1333,34 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
switch (result.term) {
.Exited => |exit_code| {
if (exit_code == 0) {
print("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
progress.log("", .{});
print("{s}\nThe following command incorrectly succeeded:\n", .{result.stderr});
dumpArgs(test_args.items);
return parseError(tokenizer, code.source_token, "example test incorrectly succeeded", .{});
}
},
else => {
print("{}\nThe following command crashed:\n", .{result.stderr});
progress.log("", .{});
print("{s}\nThe following command crashed:\n", .{result.stderr});
dumpArgs(test_args.items);
return parseError(tokenizer, code.source_token, "example compile crashed", .{});
},
}
if (mem.indexOf(u8, result.stderr, error_match) == null) {
print("{}\nExpected to find '{}' in stderr\n", .{ result.stderr, error_match });
progress.log("", .{});
print("{s}\nExpected to find '{s}' in stderr\n", .{ result.stderr, error_match });
return parseError(tokenizer, code.source_token, "example did not have expected runtime safety error message", .{});
}
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const colored_stderr = try termColor(allocator, escaped_stderr);
try out.print("<pre><code class=\"shell\">$ zig test {}.zig{}\n{}</code></pre>\n", .{
try out.print("<pre><code class=\"shell\">$ zig test {s}.zig {s}\n{s}</code></pre>\n", .{
code.name,
mode_arg,
colored_stderr,
});
},
Code.Id.Obj => |maybe_error_match| {
const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ code.name, obj_ext });
const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ code.name, obj_ext });
const tmp_obj_file_name = try fs.path.join(
allocator,
&[_][]const u8{ tmp_dir_name, name_plus_obj_ext },
@@ -1326,7 +1368,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
var build_args = std.ArrayList([]const u8).init(allocator);
defer build_args.deinit();
const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", .{code.name});
const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{s}.h", .{code.name});
const output_h_file_name = try fs.path.join(
allocator,
&[_][]const u8{ tmp_dir_name, name_plus_h_ext },
@@ -1345,7 +1387,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
}),
});
if (!code.is_inline) {
try out.print("<pre><code class=\"shell\">$ zig build-obj {}.zig", .{code.name});
try out.print("<pre><code class=\"shell\">$ zig build-obj {s}.zig", .{code.name});
}
switch (code.mode) {
@@ -1360,7 +1402,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
if (code.target_str) |triple| {
try build_args.appendSlice(&[_][]const u8{ "-target", triple });
try out.print(" -target {}", .{triple});
try out.print(" -target {s}", .{triple});
}
if (maybe_error_match) |error_match| {
@@ -1373,24 +1415,27 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
switch (result.term) {
.Exited => |exit_code| {
if (exit_code == 0) {
print("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
progress.log("", .{});
print("{s}\nThe following command incorrectly succeeded:\n", .{result.stderr});
dumpArgs(build_args.items);
return parseError(tokenizer, code.source_token, "example build incorrectly succeeded", .{});
}
},
else => {
print("{}\nThe following command crashed:\n", .{result.stderr});
progress.log("", .{});
print("{s}\nThe following command crashed:\n", .{result.stderr});
dumpArgs(build_args.items);
return parseError(tokenizer, code.source_token, "example compile crashed", .{});
},
}
if (mem.indexOf(u8, result.stderr, error_match) == null) {
print("{}\nExpected to find '{}' in stderr\n", .{ result.stderr, error_match });
progress.log("", .{});
print("{s}\nExpected to find '{s}' in stderr\n", .{ result.stderr, error_match });
return parseError(tokenizer, code.source_token, "example did not have expected compile error message", .{});
}
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const colored_stderr = try termColor(allocator, escaped_stderr);
try out.print("\n{}", .{colored_stderr});
try out.print("\n{s}", .{colored_stderr});
} else {
_ = exec(allocator, &env_map, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
}
@@ -1416,7 +1461,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
tmp_dir_name, fs.path.sep_str, bin_basename,
}),
});
try out.print("<pre><code class=\"shell\">$ zig build-lib {}.zig", .{code.name});
try out.print("<pre><code class=\"shell\">$ zig build-lib {s}.zig", .{code.name});
switch (code.mode) {
.Debug => {},
else => {
@@ -1426,15 +1471,26 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: any
}
if (code.target_str) |triple| {
try test_args.appendSlice(&[_][]const u8{ "-target", triple });
try out.print(" -target {}", .{triple});
try out.print(" -target {s}", .{triple});
}
if (code.link_mode) |link_mode| {
switch (link_mode) {
.Static => {
try test_args.append("-static");
try out.print(" -static", .{});
},
.Dynamic => {
try test_args.append("-dynamic");
try out.print(" -dynamic", .{});
},
}
}
const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const escaped_stdout = try escapeHtml(allocator, result.stdout);
try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
try out.print("\n{s}{s}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
},
}
print("OK\n", .{});
},
}
}
@@ -1450,13 +1506,13 @@ fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u
switch (result.term) {
.Exited => |exit_code| {
if (exit_code != 0) {
print("{}\nThe following command exited with code {}:\n", .{ result.stderr, exit_code });
print("{s}\nThe following command exited with code {}:\n", .{ result.stderr, exit_code });
dumpArgs(args);
return error.ChildExitError;
}
},
else => {
print("{}\nThe following command crashed:\n", .{result.stderr});
print("{s}\nThe following command crashed:\n", .{result.stderr});
dumpArgs(args);
return error.ChildCrashed;
},
@@ -1471,7 +1527,7 @@ fn getBuiltinCode(allocator: *mem.Allocator, env_map: *std.BufMap, zig_exe: []co
fn dumpArgs(args: []const []const u8) void {
for (args) |arg|
print("{} ", .{arg})
print("{s} ", .{arg})
else
print("\n", .{});
}

File diff suppressed because it is too large Load Diff

View File

@@ -55,7 +55,9 @@ struct __cuda_builtin_threadIdx_t {
__CUDA_DEVICE_BUILTIN(z,__nvvm_read_ptx_sreg_tid_z());
// threadIdx should be convertible to uint3 (in fact in nvcc, it *is* a
// uint3). This function is defined after we pull in vector_types.h.
__attribute__((device)) operator dim3() const;
__attribute__((device)) operator uint3() const;
private:
__CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_threadIdx_t);
};
@@ -66,7 +68,9 @@ struct __cuda_builtin_blockIdx_t {
__CUDA_DEVICE_BUILTIN(z,__nvvm_read_ptx_sreg_ctaid_z());
// blockIdx should be convertible to uint3 (in fact in nvcc, it *is* a
// uint3). This function is defined after we pull in vector_types.h.
__attribute__((device)) operator dim3() const;
__attribute__((device)) operator uint3() const;
private:
__CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_blockIdx_t);
};
@@ -78,6 +82,8 @@ struct __cuda_builtin_blockDim_t {
// blockDim should be convertible to dim3 (in fact in nvcc, it *is* a
// dim3). This function is defined after we pull in vector_types.h.
__attribute__((device)) operator dim3() const;
__attribute__((device)) operator uint3() const;
private:
__CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_blockDim_t);
};
@@ -89,6 +95,8 @@ struct __cuda_builtin_gridDim_t {
// gridDim should be convertible to dim3 (in fact in nvcc, it *is* a
// dim3). This function is defined after we pull in vector_types.h.
__attribute__((device)) operator dim3() const;
__attribute__((device)) operator uint3() const;
private:
__CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_gridDim_t);
};
@@ -108,5 +116,6 @@ __attribute__((device)) const int warpSize = 32;
#undef __CUDA_DEVICE_BUILTIN
#undef __CUDA_BUILTIN_VAR
#undef __CUDA_DISALLOW_BUILTINVAR_ACCESS
#undef __DELETE
#endif /* __CUDA_BUILTIN_VARS_H */

View File

@@ -66,10 +66,38 @@ __DEVICE__ float frexp(float __arg, int *__exp) {
}
// For inscrutable reasons, the CUDA headers define these functions for us on
// Windows. For OpenMP we omit these as some old system headers have
// non-conforming `isinf(float)` and `isnan(float)` implementations that return
// an `int`. The system versions of these functions should be fine anyway.
#if !defined(_MSC_VER) && !defined(__OPENMP_NVPTX__)
// Windows.
#if !defined(_MSC_VER) || defined(__OPENMP_NVPTX__)
// For OpenMP we work around some old system headers that have non-conforming
// `isinf(float)` and `isnan(float)` implementations that return an `int`. We do
// this by providing two versions of these functions, differing only in the
// return type. To avoid conflicting definitions we disable implicit base
// function generation. That means we will end up with two specializations, one
// per type, but only one has a base function defined by the system header.
#if defined(__OPENMP_NVPTX__)
#pragma omp begin declare variant match( \
implementation = {extension(disable_implicit_base)})
// FIXME: We lack an extension to customize the mangling of the variants, e.g.,
// add a suffix. This means we would clash with the names of the variants
// (note that we do not create implicit base functions here). To avoid
// this clash we add a new trait to some of them that is always true
// (this is LLVM after all ;)). It will only influence the mangled name
// of the variants inside the inner region and avoid the clash.
#pragma omp begin declare variant match(implementation = {vendor(llvm)})
__DEVICE__ int isinf(float __x) { return ::__isinff(__x); }
__DEVICE__ int isinf(double __x) { return ::__isinf(__x); }
__DEVICE__ int isfinite(float __x) { return ::__finitef(__x); }
__DEVICE__ int isfinite(double __x) { return ::__isfinited(__x); }
__DEVICE__ int isnan(float __x) { return ::__isnanf(__x); }
__DEVICE__ int isnan(double __x) { return ::__isnan(__x); }
#pragma omp end declare variant
#endif
__DEVICE__ bool isinf(float __x) { return ::__isinff(__x); }
__DEVICE__ bool isinf(double __x) { return ::__isinf(__x); }
__DEVICE__ bool isfinite(float __x) { return ::__finitef(__x); }
@@ -79,6 +107,11 @@ __DEVICE__ bool isfinite(float __x) { return ::__finitef(__x); }
__DEVICE__ bool isfinite(double __x) { return ::__isfinited(__x); }
__DEVICE__ bool isnan(float __x) { return ::__isnanf(__x); }
__DEVICE__ bool isnan(double __x) { return ::__isnan(__x); }
#if defined(__OPENMP_NVPTX__)
#pragma omp end declare variant
#endif
#endif
__DEVICE__ bool isgreater(float __x, float __y) {
@@ -142,6 +175,15 @@ __DEVICE__ float sqrt(float __x) { return ::sqrtf(__x); }
__DEVICE__ float tan(float __x) { return ::tanf(__x); }
__DEVICE__ float tanh(float __x) { return ::tanhf(__x); }
// There was a redefinition error for this this overload in CUDA mode.
// We restrict it to OpenMP mode for now, that is where it is actually needed
// anyway.
#ifdef __OPENMP_NVPTX__
__DEVICE__ float remquo(float __n, float __d, int *__q) {
return ::remquof(__n, __d, __q);
}
#endif
// Notably missing above is nexttoward. We omit it because
// libdevice doesn't provide an implementation, and we don't want to be in the
// business of implementing tricky libm functions in this header.

View File

@@ -16,7 +16,7 @@
// to work with CUDA and OpenMP target offloading [in C and C++ mode].)
#pragma push_macro("__DEVICE__")
#ifdef _OPENMP
#ifdef __OPENMP_NVPTX__
#pragma omp declare target
#define __DEVICE__ __attribute__((noinline, nothrow, cold, weak))
#else
@@ -26,7 +26,7 @@
// To make the algorithms available for C and C++ in CUDA and OpenMP we select
// different but equivalent function versions. TODO: For OpenMP we currently
// select the native builtins as the overload support for templates is lacking.
#if !defined(_OPENMP)
#if !defined(__OPENMP_NVPTX__)
#define _ISNANd std::isnan
#define _ISNANf std::isnan
#define _ISINFd std::isinf
@@ -41,6 +41,27 @@
#define _ABSf std::abs
#define _LOGBd std::logb
#define _LOGBf std::logb
// Rather than pulling in std::max from algorithm everytime, use available ::max.
#define _fmaxd max
#define _fmaxf max
#else
#ifdef __AMDGCN__
#define _ISNANd __ocml_isnan_f64
#define _ISNANf __ocml_isnan_f32
#define _ISINFd __ocml_isinf_f64
#define _ISINFf __ocml_isinf_f32
#define _ISFINITEd __ocml_isfinite_f64
#define _ISFINITEf __ocml_isfinite_f32
#define _COPYSIGNd __ocml_copysign_f64
#define _COPYSIGNf __ocml_copysign_f32
#define _SCALBNd __ocml_scalbn_f64
#define _SCALBNf __ocml_scalbn_f32
#define _ABSd __ocml_fabs_f64
#define _ABSf __ocml_fabs_f32
#define _LOGBd __ocml_logb_f64
#define _LOGBf __ocml_logb_f32
#define _fmaxd __ocml_fmax_f64
#define _fmaxf __ocml_fmax_f32
#else
#define _ISNANd __nv_isnand
#define _ISNANf __nv_isnanf
@@ -56,6 +77,9 @@
#define _ABSf __nv_fabsf
#define _LOGBd __nv_logb
#define _LOGBf __nv_logbf
#define _fmaxd __nv_fmax
#define _fmaxf __nv_fmaxf
#endif
#endif
#if defined(__cplusplus)
@@ -167,7 +191,7 @@ __DEVICE__ double _Complex __divdc3(double __a, double __b, double __c,
// Can't use std::max, because that's defined in <algorithm>, and we don't
// want to pull that in for every compile. The CUDA headers define
// ::max(float, float) and ::max(double, double), which is sufficient for us.
double __logbw = _LOGBd(max(_ABSd(__c), _ABSd(__d)));
double __logbw = _LOGBd(_fmaxd(_ABSd(__c), _ABSd(__d)));
if (_ISFINITEd(__logbw)) {
__ilogbw = (int)__logbw;
__c = _SCALBNd(__c, -__ilogbw);
@@ -200,7 +224,7 @@ __DEVICE__ double _Complex __divdc3(double __a, double __b, double __c,
__DEVICE__ float _Complex __divsc3(float __a, float __b, float __c, float __d) {
int __ilogbw = 0;
float __logbw = _LOGBf(max(_ABSf(__c), _ABSf(__d)));
float __logbw = _LOGBf(_fmaxf(_ABSf(__c), _ABSf(__d)));
if (_ISFINITEf(__logbw)) {
__ilogbw = (int)__logbw;
__c = _SCALBNf(__c, -__ilogbw);
@@ -249,8 +273,10 @@ __DEVICE__ float _Complex __divsc3(float __a, float __b, float __c, float __d) {
#undef _ABSf
#undef _LOGBd
#undef _LOGBf
#undef _fmaxd
#undef _fmaxf
#ifdef _OPENMP
#ifdef __OPENMP_NVPTX__
#pragma omp end declare target
#endif

View File

@@ -195,8 +195,8 @@ __DEVICE__ int max(int __a, int __b) { return __nv_max(__a, __b); }
__DEVICE__ int min(int __a, int __b) { return __nv_min(__a, __b); }
__DEVICE__ double modf(double __a, double *__b) { return __nv_modf(__a, __b); }
__DEVICE__ float modff(float __a, float *__b) { return __nv_modff(__a, __b); }
__DEVICE__ double nearbyint(double __a) { return __nv_nearbyint(__a); }
__DEVICE__ float nearbyintf(float __a) { return __nv_nearbyintf(__a); }
__DEVICE__ double nearbyint(double __a) { return __builtin_nearbyint(__a); }
__DEVICE__ float nearbyintf(float __a) { return __builtin_nearbyintf(__a); }
__DEVICE__ double nextafter(double __a, double __b) {
return __nv_nextafter(__a, __b);
}
@@ -249,8 +249,9 @@ __DEVICE__ double rhypot(double __a, double __b) {
__DEVICE__ float rhypotf(float __a, float __b) {
return __nv_rhypotf(__a, __b);
}
__DEVICE__ double rint(double __a) { return __nv_rint(__a); }
__DEVICE__ float rintf(float __a) { return __nv_rintf(__a); }
// __nv_rint* in libdevice is buggy and produces incorrect results.
__DEVICE__ double rint(double __a) { return __builtin_rint(__a); }
__DEVICE__ float rintf(float __a) { return __builtin_rintf(__a); }
__DEVICE__ double rnorm(int __a, const double *__b) {
return __nv_rnorm(__a, __b);
}

View File

@@ -160,6 +160,9 @@ __DEVICE__ double scalbln(double, long);
__DEVICE__ float scalbln(float, long);
__DEVICE__ double scalbn(double, int);
__DEVICE__ float scalbn(float, int);
#ifdef _MSC_VER
__DEVICE__ bool signbit(long double);
#endif
__DEVICE__ bool signbit(double);
__DEVICE__ bool signbit(float);
__DEVICE__ double sin(double);

View File

@@ -377,30 +377,38 @@ __device__ static inline void *malloc(size_t __size) {
// Out-of-line implementations from __clang_cuda_builtin_vars.h. These need to
// come after we've pulled in the definition of uint3 and dim3.
__device__ inline __cuda_builtin_threadIdx_t::operator dim3() const {
return dim3(x, y, z);
}
__device__ inline __cuda_builtin_threadIdx_t::operator uint3() const {
uint3 ret;
ret.x = x;
ret.y = y;
ret.z = z;
return ret;
return {x, y, z};
}
__device__ inline __cuda_builtin_blockIdx_t::operator dim3() const {
return dim3(x, y, z);
}
__device__ inline __cuda_builtin_blockIdx_t::operator uint3() const {
uint3 ret;
ret.x = x;
ret.y = y;
ret.z = z;
return ret;
return {x, y, z};
}
__device__ inline __cuda_builtin_blockDim_t::operator dim3() const {
return dim3(x, y, z);
}
__device__ inline __cuda_builtin_blockDim_t::operator uint3() const {
return {x, y, z};
}
__device__ inline __cuda_builtin_gridDim_t::operator dim3() const {
return dim3(x, y, z);
}
__device__ inline __cuda_builtin_gridDim_t::operator uint3() const {
return {x, y, z};
}
#include <__clang_cuda_cmath.h>
#include <__clang_cuda_intrinsics.h>
#include <__clang_cuda_complex_builtins.h>

664
lib/include/__clang_hip_cmath.h vendored Normal file
View File

@@ -0,0 +1,664 @@
/*===---- __clang_hip_cmath.h - HIP cmath decls -----------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/
#ifndef __CLANG_HIP_CMATH_H__
#define __CLANG_HIP_CMATH_H__
#if !defined(__HIP__)
#error "This file is for HIP and OpenMP AMDGCN device compilation only."
#endif
#if defined(__cplusplus)
#include <limits>
#include <type_traits>
#include <utility>
#endif
#include <limits.h>
#include <stdint.h>
#pragma push_macro("__DEVICE__")
#define __DEVICE__ static __device__ inline __attribute__((always_inline))
// Start with functions that cannot be defined by DEF macros below.
#if defined(__cplusplus)
__DEVICE__ double abs(double __x) { return ::fabs(__x); }
__DEVICE__ float abs(float __x) { return ::fabsf(__x); }
__DEVICE__ long long abs(long long __n) { return ::llabs(__n); }
__DEVICE__ long abs(long __n) { return ::labs(__n); }
__DEVICE__ float fma(float __x, float __y, float __z) {
return ::fmaf(__x, __y, __z);
}
__DEVICE__ int fpclassify(float __x) {
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL,
FP_ZERO, __x);
}
__DEVICE__ int fpclassify(double __x) {
return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL,
FP_ZERO, __x);
}
__DEVICE__ float frexp(float __arg, int *__exp) {
return ::frexpf(__arg, __exp);
}
__DEVICE__ bool isfinite(float __x) { return ::__finitef(__x); }
__DEVICE__ bool isfinite(double __x) { return ::__finite(__x); }
__DEVICE__ bool isgreater(float __x, float __y) {
return __builtin_isgreater(__x, __y);
}
__DEVICE__ bool isgreater(double __x, double __y) {
return __builtin_isgreater(__x, __y);
}
__DEVICE__ bool isgreaterequal(float __x, float __y) {
return __builtin_isgreaterequal(__x, __y);
}
__DEVICE__ bool isgreaterequal(double __x, double __y) {
return __builtin_isgreaterequal(__x, __y);
}
__DEVICE__ bool isinf(float __x) { return ::__isinff(__x); }
__DEVICE__ bool isinf(double __x) { return ::__isinf(__x); }
__DEVICE__ bool isless(float __x, float __y) {
return __builtin_isless(__x, __y);
}
__DEVICE__ bool isless(double __x, double __y) {
return __builtin_isless(__x, __y);
}
__DEVICE__ bool islessequal(float __x, float __y) {
return __builtin_islessequal(__x, __y);
}
__DEVICE__ bool islessequal(double __x, double __y) {
return __builtin_islessequal(__x, __y);
}
__DEVICE__ bool islessgreater(float __x, float __y) {
return __builtin_islessgreater(__x, __y);
}
__DEVICE__ bool islessgreater(double __x, double __y) {
return __builtin_islessgreater(__x, __y);
}
__DEVICE__ bool isnan(float __x) { return ::__isnanf(__x); }
__DEVICE__ bool isnan(double __x) { return ::__isnan(__x); }
__DEVICE__ bool isnormal(float __x) { return __builtin_isnormal(__x); }
__DEVICE__ bool isnormal(double __x) { return __builtin_isnormal(__x); }
__DEVICE__ bool isunordered(float __x, float __y) {
return __builtin_isunordered(__x, __y);
}
__DEVICE__ bool isunordered(double __x, double __y) {
return __builtin_isunordered(__x, __y);
}
__DEVICE__ float modf(float __x, float *__iptr) { return ::modff(__x, __iptr); }
__DEVICE__ float pow(float __base, int __iexp) {
return ::powif(__base, __iexp);
}
__DEVICE__ double pow(double __base, int __iexp) {
return ::powi(__base, __iexp);
}
__DEVICE__ float remquo(float __x, float __y, int *__quo) {
return ::remquof(__x, __y, __quo);
}
__DEVICE__ float scalbln(float __x, long int __n) {
return ::scalblnf(__x, __n);
}
__DEVICE__ bool signbit(float __x) { return ::__signbitf(__x); }
__DEVICE__ bool signbit(double __x) { return ::__signbit(__x); }
// Notably missing above is nexttoward. We omit it because
// ocml doesn't provide an implementation, and we don't want to be in the
// business of implementing tricky libm functions in this header.
// Other functions.
__DEVICE__ _Float16 fma(_Float16 __x, _Float16 __y, _Float16 __z) {
return __ocml_fma_f16(__x, __y, __z);
}
__DEVICE__ _Float16 pow(_Float16 __base, int __iexp) {
return __ocml_pown_f16(__base, __iexp);
}
// BEGIN DEF_FUN and HIP_OVERLOAD
// BEGIN DEF_FUN
#pragma push_macro("__DEF_FUN1")
#pragma push_macro("__DEF_FUN2")
#pragma push_macro("__DEF_FUN2_FI")
// Define cmath functions with float argument and returns __retty.
#define __DEF_FUN1(__retty, __func) \
__DEVICE__ \
__retty __func(float __x) { return __func##f(__x); }
// Define cmath functions with two float arguments and returns __retty.
#define __DEF_FUN2(__retty, __func) \
__DEVICE__ \
__retty __func(float __x, float __y) { return __func##f(__x, __y); }
// Define cmath functions with a float and an int argument and returns __retty.
#define __DEF_FUN2_FI(__retty, __func) \
__DEVICE__ \
__retty __func(float __x, int __y) { return __func##f(__x, __y); }
__DEF_FUN1(float, acos)
__DEF_FUN1(float, acosh)
__DEF_FUN1(float, asin)
__DEF_FUN1(float, asinh)
__DEF_FUN1(float, atan)
__DEF_FUN2(float, atan2)
__DEF_FUN1(float, atanh)
__DEF_FUN1(float, cbrt)
__DEF_FUN1(float, ceil)
__DEF_FUN2(float, copysign)
__DEF_FUN1(float, cos)
__DEF_FUN1(float, cosh)
__DEF_FUN1(float, erf)
__DEF_FUN1(float, erfc)
__DEF_FUN1(float, exp)
__DEF_FUN1(float, exp2)
__DEF_FUN1(float, expm1)
__DEF_FUN1(float, fabs)
__DEF_FUN2(float, fdim)
__DEF_FUN1(float, floor)
__DEF_FUN2(float, fmax)
__DEF_FUN2(float, fmin)
__DEF_FUN2(float, fmod)
__DEF_FUN2(float, hypot)
__DEF_FUN1(int, ilogb)
__DEF_FUN2_FI(float, ldexp)
__DEF_FUN1(float, lgamma)
__DEF_FUN1(float, log)
__DEF_FUN1(float, log10)
__DEF_FUN1(float, log1p)
__DEF_FUN1(float, log2)
__DEF_FUN1(float, logb)
__DEF_FUN1(long long, llrint)
__DEF_FUN1(long long, llround)
__DEF_FUN1(long, lrint)
__DEF_FUN1(long, lround)
__DEF_FUN1(float, nearbyint)
__DEF_FUN2(float, nextafter)
__DEF_FUN2(float, pow)
__DEF_FUN2(float, remainder)
__DEF_FUN1(float, rint)
__DEF_FUN1(float, round)
__DEF_FUN2_FI(float, scalbn)
__DEF_FUN1(float, sin)
__DEF_FUN1(float, sinh)
__DEF_FUN1(float, sqrt)
__DEF_FUN1(float, tan)
__DEF_FUN1(float, tanh)
__DEF_FUN1(float, tgamma)
__DEF_FUN1(float, trunc)
#pragma pop_macro("__DEF_FUN1")
#pragma pop_macro("__DEF_FUN2")
#pragma pop_macro("__DEF_FUN2_FI")
// END DEF_FUN
// BEGIN HIP_OVERLOAD
#pragma push_macro("__HIP_OVERLOAD1")
#pragma push_macro("__HIP_OVERLOAD2")
// __hip_enable_if::type is a type function which returns __T if __B is true.
template <bool __B, class __T = void> struct __hip_enable_if {};
template <class __T> struct __hip_enable_if<true, __T> { typedef __T type; };
// decltype is only available in C++11 and above.
#if __cplusplus >= 201103L
// __hip_promote
namespace __hip {
template <class _Tp> struct __numeric_type {
static void __test(...);
static _Float16 __test(_Float16);
static float __test(float);
static double __test(char);
static double __test(int);
static double __test(unsigned);
static double __test(long);
static double __test(unsigned long);
static double __test(long long);
static double __test(unsigned long long);
static double __test(double);
// No support for long double, use double instead.
static double __test(long double);
typedef decltype(__test(std::declval<_Tp>())) type;
static const bool value = !std::is_same<type, void>::value;
};
template <> struct __numeric_type<void> { static const bool value = true; };
template <class _A1, class _A2 = void, class _A3 = void,
bool = __numeric_type<_A1>::value &&__numeric_type<_A2>::value
&&__numeric_type<_A3>::value>
class __promote_imp {
public:
static const bool value = false;
};
template <class _A1, class _A2, class _A3>
class __promote_imp<_A1, _A2, _A3, true> {
private:
typedef typename __promote_imp<_A1>::type __type1;
typedef typename __promote_imp<_A2>::type __type2;
typedef typename __promote_imp<_A3>::type __type3;
public:
typedef decltype(__type1() + __type2() + __type3()) type;
static const bool value = true;
};
template <class _A1, class _A2> class __promote_imp<_A1, _A2, void, true> {
private:
typedef typename __promote_imp<_A1>::type __type1;
typedef typename __promote_imp<_A2>::type __type2;
public:
typedef decltype(__type1() + __type2()) type;
static const bool value = true;
};
template <class _A1> class __promote_imp<_A1, void, void, true> {
public:
typedef typename __numeric_type<_A1>::type type;
static const bool value = true;
};
template <class _A1, class _A2 = void, class _A3 = void>
class __promote : public __promote_imp<_A1, _A2, _A3> {};
} // namespace __hip
#endif //__cplusplus >= 201103L
// __HIP_OVERLOAD1 is used to resolve function calls with integer argument to
// avoid compilation error due to ambibuity. e.g. floor(5) is resolved with
// floor(double).
#define __HIP_OVERLOAD1(__retty, __fn) \
template <typename __T> \
__DEVICE__ typename __hip_enable_if<std::numeric_limits<__T>::is_integer, \
__retty>::type \
__fn(__T __x) { \
return ::__fn((double)__x); \
}
// __HIP_OVERLOAD2 is used to resolve function calls with mixed float/double
// or integer argument to avoid compilation error due to ambibuity. e.g.
// max(5.0f, 6.0) is resolved with max(double, double).
#if __cplusplus >= 201103L
#define __HIP_OVERLOAD2(__retty, __fn) \
template <typename __T1, typename __T2> \
__DEVICE__ typename __hip_enable_if< \
std::numeric_limits<__T1>::is_specialized && \
std::numeric_limits<__T2>::is_specialized, \
typename __hip::__promote<__T1, __T2>::type>::type \
__fn(__T1 __x, __T2 __y) { \
typedef typename __hip::__promote<__T1, __T2>::type __result_type; \
return __fn((__result_type)__x, (__result_type)__y); \
}
#else
#define __HIP_OVERLOAD2(__retty, __fn) \
template <typename __T1, typename __T2> \
__DEVICE__ \
typename __hip_enable_if<std::numeric_limits<__T1>::is_specialized && \
std::numeric_limits<__T2>::is_specialized, \
__retty>::type \
__fn(__T1 __x, __T2 __y) { \
return __fn((double)__x, (double)__y); \
}
#endif
__HIP_OVERLOAD1(double, abs)
__HIP_OVERLOAD1(double, acos)
__HIP_OVERLOAD1(double, acosh)
__HIP_OVERLOAD1(double, asin)
__HIP_OVERLOAD1(double, asinh)
__HIP_OVERLOAD1(double, atan)
__HIP_OVERLOAD2(double, atan2)
__HIP_OVERLOAD1(double, atanh)
__HIP_OVERLOAD1(double, cbrt)
__HIP_OVERLOAD1(double, ceil)
__HIP_OVERLOAD2(double, copysign)
__HIP_OVERLOAD1(double, cos)
__HIP_OVERLOAD1(double, cosh)
__HIP_OVERLOAD1(double, erf)
__HIP_OVERLOAD1(double, erfc)
__HIP_OVERLOAD1(double, exp)
__HIP_OVERLOAD1(double, exp2)
__HIP_OVERLOAD1(double, expm1)
__HIP_OVERLOAD1(double, fabs)
__HIP_OVERLOAD2(double, fdim)
__HIP_OVERLOAD1(double, floor)
__HIP_OVERLOAD2(double, fmax)
__HIP_OVERLOAD2(double, fmin)
__HIP_OVERLOAD2(double, fmod)
__HIP_OVERLOAD1(int, fpclassify)
__HIP_OVERLOAD2(double, hypot)
__HIP_OVERLOAD1(int, ilogb)
__HIP_OVERLOAD1(bool, isfinite)
__HIP_OVERLOAD2(bool, isgreater)
__HIP_OVERLOAD2(bool, isgreaterequal)
__HIP_OVERLOAD1(bool, isinf)
__HIP_OVERLOAD2(bool, isless)
__HIP_OVERLOAD2(bool, islessequal)
__HIP_OVERLOAD2(bool, islessgreater)
__HIP_OVERLOAD1(bool, isnan)
__HIP_OVERLOAD1(bool, isnormal)
__HIP_OVERLOAD2(bool, isunordered)
__HIP_OVERLOAD1(double, lgamma)
__HIP_OVERLOAD1(double, log)
__HIP_OVERLOAD1(double, log10)
__HIP_OVERLOAD1(double, log1p)
__HIP_OVERLOAD1(double, log2)
__HIP_OVERLOAD1(double, logb)
__HIP_OVERLOAD1(long long, llrint)
__HIP_OVERLOAD1(long long, llround)
__HIP_OVERLOAD1(long, lrint)
__HIP_OVERLOAD1(long, lround)
__HIP_OVERLOAD1(double, nearbyint)
__HIP_OVERLOAD2(double, nextafter)
__HIP_OVERLOAD2(double, pow)
__HIP_OVERLOAD2(double, remainder)
__HIP_OVERLOAD1(double, rint)
__HIP_OVERLOAD1(double, round)
__HIP_OVERLOAD1(bool, signbit)
__HIP_OVERLOAD1(double, sin)
__HIP_OVERLOAD1(double, sinh)
__HIP_OVERLOAD1(double, sqrt)
__HIP_OVERLOAD1(double, tan)
__HIP_OVERLOAD1(double, tanh)
__HIP_OVERLOAD1(double, tgamma)
__HIP_OVERLOAD1(double, trunc)
// Overload these but don't add them to std, they are not part of cmath.
__HIP_OVERLOAD2(double, max)
__HIP_OVERLOAD2(double, min)
// Additional Overloads that don't quite match HIP_OVERLOAD.
#if __cplusplus >= 201103L
template <typename __T1, typename __T2, typename __T3>
__DEVICE__ typename __hip_enable_if<
std::numeric_limits<__T1>::is_specialized &&
std::numeric_limits<__T2>::is_specialized &&
std::numeric_limits<__T3>::is_specialized,
typename __hip::__promote<__T1, __T2, __T3>::type>::type
fma(__T1 __x, __T2 __y, __T3 __z) {
typedef typename __hip::__promote<__T1, __T2, __T3>::type __result_type;
return ::fma((__result_type)__x, (__result_type)__y, (__result_type)__z);
}
#else
template <typename __T1, typename __T2, typename __T3>
__DEVICE__
typename __hip_enable_if<std::numeric_limits<__T1>::is_specialized &&
std::numeric_limits<__T2>::is_specialized &&
std::numeric_limits<__T3>::is_specialized,
double>::type
fma(__T1 __x, __T2 __y, __T3 __z) {
return ::fma((double)__x, (double)__y, (double)__z);
}
#endif
template <typename __T>
__DEVICE__
typename __hip_enable_if<std::numeric_limits<__T>::is_integer, double>::type
frexp(__T __x, int *__exp) {
return ::frexp((double)__x, __exp);
}
template <typename __T>
__DEVICE__
typename __hip_enable_if<std::numeric_limits<__T>::is_integer, double>::type
ldexp(__T __x, int __exp) {
return ::ldexp((double)__x, __exp);
}
template <typename __T>
__DEVICE__
typename __hip_enable_if<std::numeric_limits<__T>::is_integer, double>::type
modf(__T __x, double *__exp) {
return ::modf((double)__x, __exp);
}
#if __cplusplus >= 201103L
template <typename __T1, typename __T2>
__DEVICE__
typename __hip_enable_if<std::numeric_limits<__T1>::is_specialized &&
std::numeric_limits<__T2>::is_specialized,
typename __hip::__promote<__T1, __T2>::type>::type
remquo(__T1 __x, __T2 __y, int *__quo) {
typedef typename __hip::__promote<__T1, __T2>::type __result_type;
return ::remquo((__result_type)__x, (__result_type)__y, __quo);
}
#else
template <typename __T1, typename __T2>
__DEVICE__
typename __hip_enable_if<std::numeric_limits<__T1>::is_specialized &&
std::numeric_limits<__T2>::is_specialized,
double>::type
remquo(__T1 __x, __T2 __y, int *__quo) {
return ::remquo((double)__x, (double)__y, __quo);
}
#endif
template <typename __T>
__DEVICE__
typename __hip_enable_if<std::numeric_limits<__T>::is_integer, double>::type
scalbln(__T __x, long int __exp) {
return ::scalbln((double)__x, __exp);
}
template <typename __T>
__DEVICE__
typename __hip_enable_if<std::numeric_limits<__T>::is_integer, double>::type
scalbn(__T __x, int __exp) {
return ::scalbn((double)__x, __exp);
}
#pragma pop_macro("__HIP_OVERLOAD1")
#pragma pop_macro("__HIP_OVERLOAD2")
// END HIP_OVERLOAD
// END DEF_FUN and HIP_OVERLOAD
#endif // defined(__cplusplus)
// Define these overloads inside the namespace our standard library uses.
#ifdef _LIBCPP_BEGIN_NAMESPACE_STD
_LIBCPP_BEGIN_NAMESPACE_STD
#else
namespace std {
#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
#endif
// Pull the new overloads we defined above into namespace std.
// using ::abs; - This may be considered for C++.
using ::acos;
using ::acosh;
using ::asin;
using ::asinh;
using ::atan;
using ::atan2;
using ::atanh;
using ::cbrt;
using ::ceil;
using ::copysign;
using ::cos;
using ::cosh;
using ::erf;
using ::erfc;
using ::exp;
using ::exp2;
using ::expm1;
using ::fabs;
using ::fdim;
using ::floor;
using ::fma;
using ::fmax;
using ::fmin;
using ::fmod;
using ::fpclassify;
using ::frexp;
using ::hypot;
using ::ilogb;
using ::isfinite;
using ::isgreater;
using ::isgreaterequal;
using ::isless;
using ::islessequal;
using ::islessgreater;
using ::isnormal;
using ::isunordered;
using ::ldexp;
using ::lgamma;
using ::llrint;
using ::llround;
using ::log;
using ::log10;
using ::log1p;
using ::log2;
using ::logb;
using ::lrint;
using ::lround;
using ::modf;
// using ::nan; - This may be considered for C++.
// using ::nanf; - This may be considered for C++.
// using ::nanl; - This is not yet defined.
using ::nearbyint;
using ::nextafter;
// using ::nexttoward; - Omit this since we do not have a definition.
using ::pow;
using ::remainder;
using ::remquo;
using ::rint;
using ::round;
using ::scalbln;
using ::scalbn;
using ::signbit;
using ::sin;
using ::sinh;
using ::sqrt;
using ::tan;
using ::tanh;
using ::tgamma;
using ::trunc;
// Well this is fun: We need to pull these symbols in for libc++, but we can't
// pull them in with libstdc++, because its ::isinf and ::isnan are different
// than its std::isinf and std::isnan.
#ifndef __GLIBCXX__
using ::isinf;
using ::isnan;
#endif
// Finally, pull the "foobarf" functions that HIP defines into std.
using ::acosf;
using ::acoshf;
using ::asinf;
using ::asinhf;
using ::atan2f;
using ::atanf;
using ::atanhf;
using ::cbrtf;
using ::ceilf;
using ::copysignf;
using ::cosf;
using ::coshf;
using ::erfcf;
using ::erff;
using ::exp2f;
using ::expf;
using ::expm1f;
using ::fabsf;
using ::fdimf;
using ::floorf;
using ::fmaf;
using ::fmaxf;
using ::fminf;
using ::fmodf;
using ::frexpf;
using ::hypotf;
using ::ilogbf;
using ::ldexpf;
using ::lgammaf;
using ::llrintf;
using ::llroundf;
using ::log10f;
using ::log1pf;
using ::log2f;
using ::logbf;
using ::logf;
using ::lrintf;
using ::lroundf;
using ::modff;
using ::nearbyintf;
using ::nextafterf;
// using ::nexttowardf; - Omit this since we do not have a definition.
using ::powf;
using ::remainderf;
using ::remquof;
using ::rintf;
using ::roundf;
using ::scalblnf;
using ::scalbnf;
using ::sinf;
using ::sinhf;
using ::sqrtf;
using ::tanf;
using ::tanhf;
using ::tgammaf;
using ::truncf;
#ifdef _LIBCPP_END_NAMESPACE_STD
_LIBCPP_END_NAMESPACE_STD
#else
#ifdef _GLIBCXX_BEGIN_NAMESPACE_VERSION
_GLIBCXX_END_NAMESPACE_VERSION
#endif
} // namespace std
#endif
// Define device-side math functions from <ymath.h> on MSVC.
#if defined(_MSC_VER)
// Before VS2019, `<ymath.h>` is also included in `<limits>` and other headers.
// But, from VS2019, it's only included in `<complex>`. Need to include
// `<ymath.h>` here to ensure C functions declared there won't be markded as
// `__host__` and `__device__` through `<complex>` wrapper.
#include <ymath.h>
#if defined(__cplusplus)
extern "C" {
#endif // defined(__cplusplus)
__DEVICE__ __attribute__((overloadable)) double _Cosh(double x, double y) {
return cosh(x) * y;
}
__DEVICE__ __attribute__((overloadable)) float _FCosh(float x, float y) {
return coshf(x) * y;
}
__DEVICE__ __attribute__((overloadable)) short _Dtest(double *p) {
return fpclassify(*p);
}
__DEVICE__ __attribute__((overloadable)) short _FDtest(float *p) {
return fpclassify(*p);
}
__DEVICE__ __attribute__((overloadable)) double _Sinh(double x, double y) {
return sinh(x) * y;
}
__DEVICE__ __attribute__((overloadable)) float _FSinh(float x, float y) {
return sinhf(x) * y;
}
#if defined(__cplusplus)
}
#endif // defined(__cplusplus)
#endif // defined(_MSC_VER)
#pragma pop_macro("__DEVICE__")
#endif // __CLANG_HIP_CMATH_H__

View File

@@ -10,7 +10,9 @@
#ifndef __CLANG_HIP_LIBDEVICE_DECLARES_H__
#define __CLANG_HIP_LIBDEVICE_DECLARES_H__
#ifdef __cplusplus
extern "C" {
#endif
// BEGIN FLOAT
__device__ __attribute__((const)) float __ocml_acos_f32(float);
@@ -78,6 +80,7 @@ __device__ __attribute__((const)) float __ocml_len4_f32(float, float, float,
__device__ __attribute__((pure)) float __ocml_ncdf_f32(float);
__device__ __attribute__((pure)) float __ocml_ncdfinv_f32(float);
__device__ __attribute__((pure)) float __ocml_pow_f32(float, float);
__device__ __attribute__((pure)) float __ocml_pown_f32(float, int);
__device__ __attribute__((pure)) float __ocml_rcbrt_f32(float);
__device__ __attribute__((const)) float __ocml_remainder_f32(float, float);
__device__ float __ocml_remquo_f32(float, float,
@@ -126,10 +129,10 @@ __device__ __attribute__((const)) float __ocml_div_rte_f32(float, float);
__device__ __attribute__((const)) float __ocml_div_rtn_f32(float, float);
__device__ __attribute__((const)) float __ocml_div_rtp_f32(float, float);
__device__ __attribute__((const)) float __ocml_div_rtz_f32(float, float);
__device__ __attribute__((const)) float __ocml_sqrt_rte_f32(float, float);
__device__ __attribute__((const)) float __ocml_sqrt_rtn_f32(float, float);
__device__ __attribute__((const)) float __ocml_sqrt_rtp_f32(float, float);
__device__ __attribute__((const)) float __ocml_sqrt_rtz_f32(float, float);
__device__ __attribute__((const)) float __ocml_sqrt_rte_f32(float);
__device__ __attribute__((const)) float __ocml_sqrt_rtn_f32(float);
__device__ __attribute__((const)) float __ocml_sqrt_rtp_f32(float);
__device__ __attribute__((const)) float __ocml_sqrt_rtz_f32(float);
__device__ __attribute__((const)) float __ocml_fma_rte_f32(float, float, float);
__device__ __attribute__((const)) float __ocml_fma_rtn_f32(float, float, float);
__device__ __attribute__((const)) float __ocml_fma_rtp_f32(float, float, float);
@@ -205,6 +208,7 @@ __device__ __attribute__((const)) double __ocml_len4_f64(double, double, double,
__device__ __attribute__((pure)) double __ocml_ncdf_f64(double);
__device__ __attribute__((pure)) double __ocml_ncdfinv_f64(double);
__device__ __attribute__((pure)) double __ocml_pow_f64(double, double);
__device__ __attribute__((pure)) double __ocml_pown_f64(double, int);
__device__ __attribute__((pure)) double __ocml_rcbrt_f64(double);
__device__ __attribute__((const)) double __ocml_remainder_f64(double, double);
__device__ double __ocml_remquo_f64(double, double,
@@ -252,10 +256,10 @@ __device__ __attribute__((const)) double __ocml_div_rte_f64(double, double);
__device__ __attribute__((const)) double __ocml_div_rtn_f64(double, double);
__device__ __attribute__((const)) double __ocml_div_rtp_f64(double, double);
__device__ __attribute__((const)) double __ocml_div_rtz_f64(double, double);
__device__ __attribute__((const)) double __ocml_sqrt_rte_f64(double, double);
__device__ __attribute__((const)) double __ocml_sqrt_rtn_f64(double, double);
__device__ __attribute__((const)) double __ocml_sqrt_rtp_f64(double, double);
__device__ __attribute__((const)) double __ocml_sqrt_rtz_f64(double, double);
__device__ __attribute__((const)) double __ocml_sqrt_rte_f64(double);
__device__ __attribute__((const)) double __ocml_sqrt_rtn_f64(double);
__device__ __attribute__((const)) double __ocml_sqrt_rtp_f64(double);
__device__ __attribute__((const)) double __ocml_sqrt_rtz_f64(double);
__device__ __attribute__((const)) double __ocml_fma_rte_f64(double, double,
double);
__device__ __attribute__((const)) double __ocml_fma_rtn_f64(double, double,
@@ -290,6 +294,7 @@ __device__ __attribute__((const)) _Float16 __ocml_rsqrt_f16(_Float16);
__device__ _Float16 __ocml_sin_f16(_Float16);
__device__ __attribute__((const)) _Float16 __ocml_sqrt_f16(_Float16);
__device__ __attribute__((const)) _Float16 __ocml_trunc_f16(_Float16);
__device__ __attribute__((pure)) _Float16 __ocml_pown_f16(_Float16, int);
typedef _Float16 __2f16 __attribute__((ext_vector_type(2)));
typedef short __2i16 __attribute__((ext_vector_type(2)));
@@ -313,14 +318,17 @@ __device__ __attribute__((pure)) __2f16 __ocml_log2_2f16(__2f16);
__device__ inline __2f16
__llvm_amdgcn_rcp_2f16(__2f16 __x) // Not currently exposed by ROCDL.
{
return __2f16{__llvm_amdgcn_rcp_f16(__x.x), __llvm_amdgcn_rcp_f16(__x.y)};
return (__2f16)(__llvm_amdgcn_rcp_f16(__x.x), __llvm_amdgcn_rcp_f16(__x.y));
}
__device__ __attribute__((const)) __2f16 __ocml_rint_2f16(__2f16);
__device__ __attribute__((const)) __2f16 __ocml_rsqrt_2f16(__2f16);
__device__ __2f16 __ocml_sin_2f16(__2f16);
__device__ __attribute__((const)) __2f16 __ocml_sqrt_2f16(__2f16);
__device__ __attribute__((const)) __2f16 __ocml_trunc_2f16(__2f16);
__device__ __attribute__((const)) __2f16 __ocml_pown_2f16(__2f16, __2i16);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // __CLANG_HIP_LIBDEVICE_DECLARES_H__

File diff suppressed because it is too large Load Diff

View File

@@ -28,6 +28,10 @@
#define __shared__ __attribute__((shared))
#define __constant__ __attribute__((constant))
#if !defined(__cplusplus) || __cplusplus < 201103L
#define nullptr NULL;
#endif
#if __HIP_ENABLE_DEVICE_MALLOC__
extern "C" __device__ void *__hip_malloc(size_t __size);
extern "C" __device__ void *__hip_free(void *__ptr);
@@ -51,6 +55,7 @@ static inline __device__ void *free(void *__ptr) {
#if !_OPENMP || __HIP_ENABLE_CUDA_WRAPPER_FOR_OPENMP__
#include <__clang_cuda_math_forward_declares.h>
#include <__clang_hip_cmath.h>
#include <__clang_cuda_complex_builtins.h>
#include <algorithm>

1209
lib/include/altivec.h vendored

File diff suppressed because it is too large Load Diff

View File

@@ -15,8 +15,8 @@
#define __AMXINTRIN_H
#ifdef __x86_64__
#define __DEFAULT_FN_ATTRS \
__attribute__((__always_inline__, __nodebug__, __target__("amx-tile")))
#define __DEFAULT_FN_ATTRS_TILE \
__attribute__((__always_inline__, __nodebug__, __target__("amx-tile")))
/// Load tile configuration from a 64-byte memory location specified by
/// "mem_addr". The tile configuration includes the tile type palette, the
@@ -31,9 +31,8 @@
///
/// \param __config
/// A pointer to 512-bits configuration
static __inline__ void __DEFAULT_FN_ATTRS
_tile_loadconfig(const void *__config)
{
static __inline__ void __DEFAULT_FN_ATTRS_TILE
_tile_loadconfig(const void *__config) {
__builtin_ia32_tile_loadconfig(__config);
}
@@ -48,9 +47,8 @@ _tile_loadconfig(const void *__config)
///
/// \param __config
/// A pointer to 512-bits configuration
static __inline__ void __DEFAULT_FN_ATTRS
_tile_storeconfig(void *__config)
{
static __inline__ void __DEFAULT_FN_ATTRS_TILE
_tile_storeconfig(void *__config) {
__builtin_ia32_tile_storeconfig(__config);
}
@@ -60,9 +58,7 @@ _tile_storeconfig(void *__config)
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> TILERELEASE </c> instruction.
static __inline__ void __DEFAULT_FN_ATTRS
_tile_release(void)
{
static __inline__ void __DEFAULT_FN_ATTRS_TILE _tile_release(void) {
__builtin_ia32_tilerelease();
}
@@ -80,8 +76,9 @@ _tile_release(void)
/// A pointer to base address.
/// \param stride
/// The stride between the rows' data to be loaded in memory.
#define _tile_loadd(dst, base, stride) \
__builtin_ia32_tileloadd64((dst), ((const void *)(base)), (__SIZE_TYPE__)(stride))
#define _tile_loadd(dst, base, stride) \
__builtin_ia32_tileloadd64((dst), ((const void *)(base)), \
(__SIZE_TYPE__)(stride))
/// Load tile rows from memory specifieid by "base" address and "stride" into
/// destination tile "dst" using the tile configuration previously configured
@@ -99,8 +96,9 @@ _tile_release(void)
/// A pointer to base address.
/// \param stride
/// The stride between the rows' data to be loaded in memory.
#define _tile_stream_loadd(dst, base, stride) \
__builtin_ia32_tileloaddt164((dst), ((const void *)(base)), (__SIZE_TYPE__)(stride))
#define _tile_stream_loadd(dst, base, stride) \
__builtin_ia32_tileloaddt164((dst), ((const void *)(base)), \
(__SIZE_TYPE__)(stride))
/// Store the tile specified by "src" to memory specifieid by "base" address and
/// "stride" using the tile configuration previously configured via
@@ -116,7 +114,7 @@ _tile_release(void)
/// A pointer to base address.
/// \param stride
/// The stride between the rows' data to be stored in memory.
#define _tile_stored(dst, base, stride) \
#define _tile_stored(dst, base, stride) \
__builtin_ia32_tilestored64((dst), ((void *)(base)), (__SIZE_TYPE__)(stride))
/// Zero the tile specified by "tdest".
@@ -145,7 +143,8 @@ _tile_release(void)
/// The 1st source tile. Max size is 1024 Bytes.
/// \param src1
/// The 2nd source tile. Max size is 1024 Bytes.
#define _tile_dpbssd(dst, src0, src1) __builtin_ia32_tdpbssd((dst), (src0), (src1))
#define _tile_dpbssd(dst, src0, src1) \
__builtin_ia32_tdpbssd((dst), (src0), (src1))
/// Compute dot-product of bytes in tiles with a source/destination accumulator.
/// Multiply groups of 4 adjacent pairs of signed 8-bit integers in src0 with
@@ -163,7 +162,8 @@ _tile_release(void)
/// The 1st source tile. Max size is 1024 Bytes.
/// \param src1
/// The 2nd source tile. Max size is 1024 Bytes.
#define _tile_dpbsud(dst, src0, src1) __builtin_ia32_tdpbsud((dst), (src0), (src1))
#define _tile_dpbsud(dst, src0, src1) \
__builtin_ia32_tdpbsud((dst), (src0), (src1))
/// Compute dot-product of bytes in tiles with a source/destination accumulator.
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in src0 with
@@ -181,7 +181,8 @@ _tile_release(void)
/// The 1st source tile. Max size is 1024 Bytes.
/// \param src1
/// The 2nd source tile. Max size is 1024 Bytes.
#define _tile_dpbusd(dst, src0, src1) __builtin_ia32_tdpbusd((dst), (src0), (src1))
#define _tile_dpbusd(dst, src0, src1) \
__builtin_ia32_tdpbusd((dst), (src0), (src1))
/// Compute dot-product of bytes in tiles with a source/destination accumulator.
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in src0 with
@@ -199,7 +200,8 @@ _tile_release(void)
/// The 1st source tile. Max size is 1024 Bytes.
/// \param src1
/// The 2nd source tile. Max size is 1024 Bytes.
#define _tile_dpbuud(dst, src0, src1) __builtin_ia32_tdpbuud((dst), (src0), (src1))
#define _tile_dpbuud(dst, src0, src1) \
__builtin_ia32_tdpbuud((dst), (src0), (src1))
/// Compute dot-product of BF16 (16-bit) floating-point pairs in tiles src0 and
/// src1, accumulating the intermediate single-precision (32-bit) floating-point
@@ -216,10 +218,61 @@ _tile_release(void)
/// The 1st source tile. Max size is 1024 Bytes.
/// \param src1
/// The 2nd source tile. Max size is 1024 Bytes.
#define _tile_dpbf16ps(dst, src0, src1) \
#define _tile_dpbf16ps(dst, src0, src1) \
__builtin_ia32_tdpbf16ps((dst), (src0), (src1))
#undef __DEFAULT_FN_ATTRS
#define __DEFAULT_FN_ATTRS_INT8 \
__attribute__((__always_inline__, __nodebug__, __target__("amx-int8")))
typedef int _tile1024i __attribute__((__vector_size__(1024), __aligned__(64)));
static __inline__ _tile1024i __DEFAULT_FN_ATTRS_INT8
_tile_loadd_internal(unsigned short m, unsigned short n, const void *base,
__SIZE_TYPE__ stride) {
return __builtin_ia32_tileloadd64_internal(m, n, base,
(__SIZE_TYPE__)(stride));
}
static __inline__ _tile1024i __DEFAULT_FN_ATTRS_INT8
_tile_dpbssd_internal(unsigned short m, unsigned short n, unsigned short k,
_tile1024i dst, _tile1024i src1, _tile1024i src2) {
return __builtin_ia32_tdpbssd_internal(m, n, k, dst, src1, src2);
}
static __inline__ void __DEFAULT_FN_ATTRS_INT8
_tile_stored_internal(unsigned short m, unsigned short n, void *base,
__SIZE_TYPE__ stride, _tile1024i tile) {
return __builtin_ia32_tilestored64_internal(m, n, base,
(__SIZE_TYPE__)(stride), tile);
}
typedef struct __tile1024i_str {
const unsigned short row;
const unsigned short col;
_tile1024i tile;
} __tile1024i;
__DEFAULT_FN_ATTRS_TILE
static void __tile_loadd(__tile1024i *dst, const void *base,
__SIZE_TYPE__ stride) {
dst->tile = _tile_loadd_internal(dst->row, dst->col, base, stride);
}
__DEFAULT_FN_ATTRS_INT8
static void __tile_dpbssd(__tile1024i *dst, __tile1024i src1,
__tile1024i src2) {
dst->tile = _tile_dpbssd_internal(src1.row, src2.col, src1.col, dst->tile,
src1.tile, src2.tile);
}
__DEFAULT_FN_ATTRS_TILE
static void __tile_stored(void *base, __SIZE_TYPE__ stride, __tile1024i src) {
_tile_stored_internal(src.row, src.col, base, stride, src.tile);
}
__DEFAULT_FN_ATTRS_TILE
static void __tile_zero(__tile1024i *dst) {
dst->tile = __builtin_ia32_tilezero_internal(dst->row, dst->col);
}
#endif /* __x86_64__ */
#endif /* __AMXINTRIN_H */

View File

@@ -639,6 +639,32 @@ __jcvt(double __a) {
}
#endif
/* Armv8.7-A load/store 64-byte intrinsics */
#if __ARM_64BIT_STATE && defined(__ARM_FEATURE_LS64)
typedef struct {
uint64_t val[8];
} data512_t;
static __inline__ data512_t __attribute__((__always_inline__, __nodebug__))
__arm_ld64b(const void *__addr) {
data512_t __value;
__builtin_arm_ld64b(__addr, __value.val);
return __value;
}
static __inline__ void __attribute__((__always_inline__, __nodebug__))
__arm_st64b(void *__addr, data512_t __value) {
__builtin_arm_st64b(__addr, __value.val);
}
static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
__arm_st64bv(void *__addr, data512_t __value) {
return __builtin_arm_st64bv(__addr, __value.val);
}
static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
__arm_st64bv0(void *__addr, data512_t __value) {
return __builtin_arm_st64bv0(__addr, __value.val);
}
#endif
/* 10.1 Special register intrinsics */
#define __arm_rsr(sysreg) __builtin_arm_rsr(sysreg)
#define __arm_rsr64(sysreg) __builtin_arm_rsr64(sysreg)

12574
lib/include/arm_neon.h vendored

File diff suppressed because it is too large Load Diff

160
lib/include/arm_sve.h vendored
View File

@@ -94,7 +94,7 @@ typedef __clang_svbfloat16x2_t svbfloat16x2_t;
typedef __clang_svbfloat16x3_t svbfloat16x3_t;
typedef __clang_svbfloat16x4_t svbfloat16x4_t;
#endif
typedef enum
enum svpattern
{
SV_POW2 = 0,
SV_VL1 = 1,
@@ -113,9 +113,9 @@ typedef enum
SV_MUL4 = 29,
SV_MUL3 = 30,
SV_ALL = 31
} sv_pattern;
};
typedef enum
enum svprfop
{
SV_PLDL1KEEP = 0,
SV_PLDL1STRM = 1,
@@ -129,7 +129,7 @@ typedef enum
SV_PSTL2STRM = 11,
SV_PSTL3KEEP = 12,
SV_PSTL3STRM = 13
} sv_prfop;
};
/* Function attributes */
#define __aio static inline __attribute__((__always_inline__, __nodebug__, __overloadable__))
@@ -10013,69 +10013,69 @@ int16_t svorv(svbool_t, svint16_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svpfirst_b)))
svbool_t svpfirst(svbool_t, svbool_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfb_gather_u32base)))
void svprfb_gather(svbool_t, svuint32_t, sv_prfop);
void svprfb_gather(svbool_t, svuint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfb_gather_u64base)))
void svprfb_gather(svbool_t, svuint64_t, sv_prfop);
void svprfb_gather(svbool_t, svuint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfb_gather_u32base_offset)))
void svprfb_gather_offset(svbool_t, svuint32_t, int64_t, sv_prfop);
void svprfb_gather_offset(svbool_t, svuint32_t, int64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfb_gather_u64base_offset)))
void svprfb_gather_offset(svbool_t, svuint64_t, int64_t, sv_prfop);
void svprfb_gather_offset(svbool_t, svuint64_t, int64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfb_gather_s32offset)))
void svprfb_gather_offset(svbool_t, void const *, svint32_t, sv_prfop);
void svprfb_gather_offset(svbool_t, void const *, svint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfb_gather_u32offset)))
void svprfb_gather_offset(svbool_t, void const *, svuint32_t, sv_prfop);
void svprfb_gather_offset(svbool_t, void const *, svuint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfb_gather_s64offset)))
void svprfb_gather_offset(svbool_t, void const *, svint64_t, sv_prfop);
void svprfb_gather_offset(svbool_t, void const *, svint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfb_gather_u64offset)))
void svprfb_gather_offset(svbool_t, void const *, svuint64_t, sv_prfop);
void svprfb_gather_offset(svbool_t, void const *, svuint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfd_gather_u32base)))
void svprfd_gather(svbool_t, svuint32_t, sv_prfop);
void svprfd_gather(svbool_t, svuint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfd_gather_u64base)))
void svprfd_gather(svbool_t, svuint64_t, sv_prfop);
void svprfd_gather(svbool_t, svuint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfd_gather_u32base_index)))
void svprfd_gather_index(svbool_t, svuint32_t, int64_t, sv_prfop);
void svprfd_gather_index(svbool_t, svuint32_t, int64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfd_gather_u64base_index)))
void svprfd_gather_index(svbool_t, svuint64_t, int64_t, sv_prfop);
void svprfd_gather_index(svbool_t, svuint64_t, int64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfd_gather_s32index)))
void svprfd_gather_index(svbool_t, void const *, svint32_t, sv_prfop);
void svprfd_gather_index(svbool_t, void const *, svint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfd_gather_u32index)))
void svprfd_gather_index(svbool_t, void const *, svuint32_t, sv_prfop);
void svprfd_gather_index(svbool_t, void const *, svuint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfd_gather_s64index)))
void svprfd_gather_index(svbool_t, void const *, svint64_t, sv_prfop);
void svprfd_gather_index(svbool_t, void const *, svint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfd_gather_u64index)))
void svprfd_gather_index(svbool_t, void const *, svuint64_t, sv_prfop);
void svprfd_gather_index(svbool_t, void const *, svuint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfh_gather_u32base)))
void svprfh_gather(svbool_t, svuint32_t, sv_prfop);
void svprfh_gather(svbool_t, svuint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfh_gather_u64base)))
void svprfh_gather(svbool_t, svuint64_t, sv_prfop);
void svprfh_gather(svbool_t, svuint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfh_gather_u32base_index)))
void svprfh_gather_index(svbool_t, svuint32_t, int64_t, sv_prfop);
void svprfh_gather_index(svbool_t, svuint32_t, int64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfh_gather_u64base_index)))
void svprfh_gather_index(svbool_t, svuint64_t, int64_t, sv_prfop);
void svprfh_gather_index(svbool_t, svuint64_t, int64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfh_gather_s32index)))
void svprfh_gather_index(svbool_t, void const *, svint32_t, sv_prfop);
void svprfh_gather_index(svbool_t, void const *, svint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfh_gather_u32index)))
void svprfh_gather_index(svbool_t, void const *, svuint32_t, sv_prfop);
void svprfh_gather_index(svbool_t, void const *, svuint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfh_gather_s64index)))
void svprfh_gather_index(svbool_t, void const *, svint64_t, sv_prfop);
void svprfh_gather_index(svbool_t, void const *, svint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfh_gather_u64index)))
void svprfh_gather_index(svbool_t, void const *, svuint64_t, sv_prfop);
void svprfh_gather_index(svbool_t, void const *, svuint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfw_gather_u32base)))
void svprfw_gather(svbool_t, svuint32_t, sv_prfop);
void svprfw_gather(svbool_t, svuint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfw_gather_u64base)))
void svprfw_gather(svbool_t, svuint64_t, sv_prfop);
void svprfw_gather(svbool_t, svuint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfw_gather_u32base_index)))
void svprfw_gather_index(svbool_t, svuint32_t, int64_t, sv_prfop);
void svprfw_gather_index(svbool_t, svuint32_t, int64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfw_gather_u64base_index)))
void svprfw_gather_index(svbool_t, svuint64_t, int64_t, sv_prfop);
void svprfw_gather_index(svbool_t, svuint64_t, int64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfw_gather_s32index)))
void svprfw_gather_index(svbool_t, void const *, svint32_t, sv_prfop);
void svprfw_gather_index(svbool_t, void const *, svint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfw_gather_u32index)))
void svprfw_gather_index(svbool_t, void const *, svuint32_t, sv_prfop);
void svprfw_gather_index(svbool_t, void const *, svuint32_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfw_gather_s64index)))
void svprfw_gather_index(svbool_t, void const *, svint64_t, sv_prfop);
void svprfw_gather_index(svbool_t, void const *, svint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svprfw_gather_u64index)))
void svprfw_gather_index(svbool_t, void const *, svuint64_t, sv_prfop);
void svprfw_gather_index(svbool_t, void const *, svuint64_t, enum svprfop);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqadd_n_s8)))
svint8_t svqadd(svint8_t, int8_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqadd_n_s32)))
@@ -10117,13 +10117,13 @@ uint32_t svqdecb(uint32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecb_n_u64)))
uint64_t svqdecb(uint64_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecb_pat_n_s32)))
int32_t svqdecb_pat(int32_t, sv_pattern, uint64_t);
int32_t svqdecb_pat(int32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecb_pat_n_s64)))
int64_t svqdecb_pat(int64_t, sv_pattern, uint64_t);
int64_t svqdecb_pat(int64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecb_pat_n_u32)))
uint32_t svqdecb_pat(uint32_t, sv_pattern, uint64_t);
uint32_t svqdecb_pat(uint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecb_pat_n_u64)))
uint64_t svqdecb_pat(uint64_t, sv_pattern, uint64_t);
uint64_t svqdecb_pat(uint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecd_n_s32)))
int32_t svqdecd(int32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecd_n_s64)))
@@ -10137,17 +10137,17 @@ svint64_t svqdecd(svint64_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecd_u64)))
svuint64_t svqdecd(svuint64_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecd_pat_n_s32)))
int32_t svqdecd_pat(int32_t, sv_pattern, uint64_t);
int32_t svqdecd_pat(int32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecd_pat_n_s64)))
int64_t svqdecd_pat(int64_t, sv_pattern, uint64_t);
int64_t svqdecd_pat(int64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecd_pat_n_u32)))
uint32_t svqdecd_pat(uint32_t, sv_pattern, uint64_t);
uint32_t svqdecd_pat(uint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecd_pat_n_u64)))
uint64_t svqdecd_pat(uint64_t, sv_pattern, uint64_t);
uint64_t svqdecd_pat(uint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecd_pat_s64)))
svint64_t svqdecd_pat(svint64_t, sv_pattern, uint64_t);
svint64_t svqdecd_pat(svint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecd_pat_u64)))
svuint64_t svqdecd_pat(svuint64_t, sv_pattern, uint64_t);
svuint64_t svqdecd_pat(svuint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdech_n_s32)))
int32_t svqdech(int32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdech_n_s64)))
@@ -10161,17 +10161,17 @@ svint16_t svqdech(svint16_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdech_u16)))
svuint16_t svqdech(svuint16_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdech_pat_n_s32)))
int32_t svqdech_pat(int32_t, sv_pattern, uint64_t);
int32_t svqdech_pat(int32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdech_pat_n_s64)))
int64_t svqdech_pat(int64_t, sv_pattern, uint64_t);
int64_t svqdech_pat(int64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdech_pat_n_u32)))
uint32_t svqdech_pat(uint32_t, sv_pattern, uint64_t);
uint32_t svqdech_pat(uint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdech_pat_n_u64)))
uint64_t svqdech_pat(uint64_t, sv_pattern, uint64_t);
uint64_t svqdech_pat(uint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdech_pat_s16)))
svint16_t svqdech_pat(svint16_t, sv_pattern, uint64_t);
svint16_t svqdech_pat(svint16_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdech_pat_u16)))
svuint16_t svqdech_pat(svuint16_t, sv_pattern, uint64_t);
svuint16_t svqdech_pat(svuint16_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecp_n_s32_b8)))
int32_t svqdecp_b8(int32_t, svbool_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecp_n_s32_b32)))
@@ -10229,17 +10229,17 @@ svint32_t svqdecw(svint32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecw_u32)))
svuint32_t svqdecw(svuint32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecw_pat_n_s32)))
int32_t svqdecw_pat(int32_t, sv_pattern, uint64_t);
int32_t svqdecw_pat(int32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecw_pat_n_s64)))
int64_t svqdecw_pat(int64_t, sv_pattern, uint64_t);
int64_t svqdecw_pat(int64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecw_pat_n_u32)))
uint32_t svqdecw_pat(uint32_t, sv_pattern, uint64_t);
uint32_t svqdecw_pat(uint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecw_pat_n_u64)))
uint64_t svqdecw_pat(uint64_t, sv_pattern, uint64_t);
uint64_t svqdecw_pat(uint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecw_pat_s32)))
svint32_t svqdecw_pat(svint32_t, sv_pattern, uint64_t);
svint32_t svqdecw_pat(svint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqdecw_pat_u32)))
svuint32_t svqdecw_pat(svuint32_t, sv_pattern, uint64_t);
svuint32_t svqdecw_pat(svuint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincb_n_s32)))
int32_t svqincb(int32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincb_n_s64)))
@@ -10249,13 +10249,13 @@ uint32_t svqincb(uint32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincb_n_u64)))
uint64_t svqincb(uint64_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincb_pat_n_s32)))
int32_t svqincb_pat(int32_t, sv_pattern, uint64_t);
int32_t svqincb_pat(int32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincb_pat_n_s64)))
int64_t svqincb_pat(int64_t, sv_pattern, uint64_t);
int64_t svqincb_pat(int64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincb_pat_n_u32)))
uint32_t svqincb_pat(uint32_t, sv_pattern, uint64_t);
uint32_t svqincb_pat(uint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincb_pat_n_u64)))
uint64_t svqincb_pat(uint64_t, sv_pattern, uint64_t);
uint64_t svqincb_pat(uint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincd_n_s32)))
int32_t svqincd(int32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincd_n_s64)))
@@ -10269,17 +10269,17 @@ svint64_t svqincd(svint64_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincd_u64)))
svuint64_t svqincd(svuint64_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincd_pat_n_s32)))
int32_t svqincd_pat(int32_t, sv_pattern, uint64_t);
int32_t svqincd_pat(int32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincd_pat_n_s64)))
int64_t svqincd_pat(int64_t, sv_pattern, uint64_t);
int64_t svqincd_pat(int64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincd_pat_n_u32)))
uint32_t svqincd_pat(uint32_t, sv_pattern, uint64_t);
uint32_t svqincd_pat(uint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincd_pat_n_u64)))
uint64_t svqincd_pat(uint64_t, sv_pattern, uint64_t);
uint64_t svqincd_pat(uint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincd_pat_s64)))
svint64_t svqincd_pat(svint64_t, sv_pattern, uint64_t);
svint64_t svqincd_pat(svint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincd_pat_u64)))
svuint64_t svqincd_pat(svuint64_t, sv_pattern, uint64_t);
svuint64_t svqincd_pat(svuint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqinch_n_s32)))
int32_t svqinch(int32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqinch_n_s64)))
@@ -10293,17 +10293,17 @@ svint16_t svqinch(svint16_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqinch_u16)))
svuint16_t svqinch(svuint16_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqinch_pat_n_s32)))
int32_t svqinch_pat(int32_t, sv_pattern, uint64_t);
int32_t svqinch_pat(int32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqinch_pat_n_s64)))
int64_t svqinch_pat(int64_t, sv_pattern, uint64_t);
int64_t svqinch_pat(int64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqinch_pat_n_u32)))
uint32_t svqinch_pat(uint32_t, sv_pattern, uint64_t);
uint32_t svqinch_pat(uint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqinch_pat_n_u64)))
uint64_t svqinch_pat(uint64_t, sv_pattern, uint64_t);
uint64_t svqinch_pat(uint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqinch_pat_s16)))
svint16_t svqinch_pat(svint16_t, sv_pattern, uint64_t);
svint16_t svqinch_pat(svint16_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqinch_pat_u16)))
svuint16_t svqinch_pat(svuint16_t, sv_pattern, uint64_t);
svuint16_t svqinch_pat(svuint16_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincp_n_s32_b8)))
int32_t svqincp_b8(int32_t, svbool_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincp_n_s32_b32)))
@@ -10361,17 +10361,17 @@ svint32_t svqincw(svint32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincw_u32)))
svuint32_t svqincw(svuint32_t, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincw_pat_n_s32)))
int32_t svqincw_pat(int32_t, sv_pattern, uint64_t);
int32_t svqincw_pat(int32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincw_pat_n_s64)))
int64_t svqincw_pat(int64_t, sv_pattern, uint64_t);
int64_t svqincw_pat(int64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincw_pat_n_u32)))
uint32_t svqincw_pat(uint32_t, sv_pattern, uint64_t);
uint32_t svqincw_pat(uint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincw_pat_n_u64)))
uint64_t svqincw_pat(uint64_t, sv_pattern, uint64_t);
uint64_t svqincw_pat(uint64_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincw_pat_s32)))
svint32_t svqincw_pat(svint32_t, sv_pattern, uint64_t);
svint32_t svqincw_pat(svint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqincw_pat_u32)))
svuint32_t svqincw_pat(svuint32_t, sv_pattern, uint64_t);
svuint32_t svqincw_pat(svuint32_t, enum svpattern, uint64_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqsub_n_s8)))
svint8_t svqsub(svint8_t, int8_t);
__aio __attribute__((__clang_arm_builtin_alias(__builtin_sve_svqsub_n_s32)))

View File

@@ -9297,303 +9297,232 @@ _mm512_mask_abs_pd(__m512d __W, __mmask8 __K, __m512d __A)
/* Vector-reduction arithmetic accepts vectors as inputs and produces scalars as
* outputs. This class of vector operation forms the basis of many scientific
* computations. In vector-reduction arithmetic, the evaluation off is
* computations. In vector-reduction arithmetic, the evaluation order is
* independent of the order of the input elements of V.
* For floating point types, we always assume the elements are reassociable even
* if -fast-math is off.
* Used bisection method. At each step, we partition the vector with previous
* step in half, and the operation is performed on its two halves.
* This takes log2(n) steps where n is the number of elements in the vector.
*/
#define _mm512_mask_reduce_operator(op) \
__v4du __t1 = (__v4du)_mm512_extracti64x4_epi64(__W, 0); \
__v4du __t2 = (__v4du)_mm512_extracti64x4_epi64(__W, 1); \
__m256i __t3 = (__m256i)(__t1 op __t2); \
__v2du __t4 = (__v2du)_mm256_extracti128_si256(__t3, 0); \
__v2du __t5 = (__v2du)_mm256_extracti128_si256(__t3, 1); \
__v2du __t6 = __t4 op __t5; \
__v2du __t7 = __builtin_shufflevector(__t6, __t6, 1, 0); \
__v2du __t8 = __t6 op __t7; \
return __t8[0]
static __inline__ long long __DEFAULT_FN_ATTRS512 _mm512_reduce_add_epi64(__m512i __W) {
_mm512_mask_reduce_operator(+);
return __builtin_ia32_reduce_add_q512(__W);
}
static __inline__ long long __DEFAULT_FN_ATTRS512 _mm512_reduce_mul_epi64(__m512i __W) {
_mm512_mask_reduce_operator(*);
return __builtin_ia32_reduce_mul_q512(__W);
}
static __inline__ long long __DEFAULT_FN_ATTRS512 _mm512_reduce_and_epi64(__m512i __W) {
_mm512_mask_reduce_operator(&);
return __builtin_ia32_reduce_and_q512(__W);
}
static __inline__ long long __DEFAULT_FN_ATTRS512 _mm512_reduce_or_epi64(__m512i __W) {
_mm512_mask_reduce_operator(|);
return __builtin_ia32_reduce_or_q512(__W);
}
static __inline__ long long __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_add_epi64(__mmask8 __M, __m512i __W) {
__W = _mm512_maskz_mov_epi64(__M, __W);
_mm512_mask_reduce_operator(+);
return __builtin_ia32_reduce_add_q512(__W);
}
static __inline__ long long __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_mul_epi64(__mmask8 __M, __m512i __W) {
__W = _mm512_mask_mov_epi64(_mm512_set1_epi64(1), __M, __W);
_mm512_mask_reduce_operator(*);
return __builtin_ia32_reduce_mul_q512(__W);
}
static __inline__ long long __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_and_epi64(__mmask8 __M, __m512i __W) {
__W = _mm512_mask_mov_epi64(_mm512_set1_epi64(~0ULL), __M, __W);
_mm512_mask_reduce_operator(&);
return __builtin_ia32_reduce_and_q512(__W);
}
static __inline__ long long __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_or_epi64(__mmask8 __M, __m512i __W) {
__W = _mm512_maskz_mov_epi64(__M, __W);
_mm512_mask_reduce_operator(|);
return __builtin_ia32_reduce_or_q512(__W);
}
#undef _mm512_mask_reduce_operator
#define _mm512_mask_reduce_operator(op) \
__m256d __t1 = _mm512_extractf64x4_pd(__W, 0); \
__m256d __t2 = _mm512_extractf64x4_pd(__W, 1); \
__m256d __t3 = __t1 op __t2; \
__m128d __t4 = _mm256_extractf128_pd(__t3, 0); \
__m128d __t5 = _mm256_extractf128_pd(__t3, 1); \
__m128d __t6 = __t4 op __t5; \
__m128d __t7 = __builtin_shufflevector(__t6, __t6, 1, 0); \
__m128d __t8 = __t6 op __t7; \
return __t8[0]
// -0.0 is used to ignore the start value since it is the neutral value of
// floating point addition. For more information, please refer to
// https://llvm.org/docs/LangRef.html#llvm-vector-reduce-fadd-intrinsic
static __inline__ double __DEFAULT_FN_ATTRS512 _mm512_reduce_add_pd(__m512d __W) {
_mm512_mask_reduce_operator(+);
return __builtin_ia32_reduce_fadd_pd512(-0.0, __W);
}
static __inline__ double __DEFAULT_FN_ATTRS512 _mm512_reduce_mul_pd(__m512d __W) {
_mm512_mask_reduce_operator(*);
return __builtin_ia32_reduce_fmul_pd512(1.0, __W);
}
static __inline__ double __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_add_pd(__mmask8 __M, __m512d __W) {
__W = _mm512_maskz_mov_pd(__M, __W);
_mm512_mask_reduce_operator(+);
return __builtin_ia32_reduce_fadd_pd512(-0.0, __W);
}
static __inline__ double __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_mul_pd(__mmask8 __M, __m512d __W) {
__W = _mm512_mask_mov_pd(_mm512_set1_pd(1.0), __M, __W);
_mm512_mask_reduce_operator(*);
return __builtin_ia32_reduce_fmul_pd512(1.0, __W);
}
#undef _mm512_mask_reduce_operator
#define _mm512_mask_reduce_operator(op) \
__v8su __t1 = (__v8su)_mm512_extracti64x4_epi64(__W, 0); \
__v8su __t2 = (__v8su)_mm512_extracti64x4_epi64(__W, 1); \
__m256i __t3 = (__m256i)(__t1 op __t2); \
__v4su __t4 = (__v4su)_mm256_extracti128_si256(__t3, 0); \
__v4su __t5 = (__v4su)_mm256_extracti128_si256(__t3, 1); \
__v4su __t6 = __t4 op __t5; \
__v4su __t7 = __builtin_shufflevector(__t6, __t6, 2, 3, 0, 1); \
__v4su __t8 = __t6 op __t7; \
__v4su __t9 = __builtin_shufflevector(__t8, __t8, 1, 0, 3, 2); \
__v4su __t10 = __t8 op __t9; \
return __t10[0]
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_reduce_add_epi32(__m512i __W) {
_mm512_mask_reduce_operator(+);
return __builtin_ia32_reduce_add_d512((__v16si)__W);
}
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_reduce_mul_epi32(__m512i __W) {
_mm512_mask_reduce_operator(*);
return __builtin_ia32_reduce_mul_d512((__v16si)__W);
}
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_reduce_and_epi32(__m512i __W) {
_mm512_mask_reduce_operator(&);
return __builtin_ia32_reduce_and_d512((__v16si)__W);
}
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_reduce_or_epi32(__m512i __W) {
_mm512_mask_reduce_operator(|);
return __builtin_ia32_reduce_or_d512((__v16si)__W);
}
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_add_epi32( __mmask16 __M, __m512i __W) {
__W = _mm512_maskz_mov_epi32(__M, __W);
_mm512_mask_reduce_operator(+);
return __builtin_ia32_reduce_add_d512((__v16si)__W);
}
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_mul_epi32( __mmask16 __M, __m512i __W) {
__W = _mm512_mask_mov_epi32(_mm512_set1_epi32(1), __M, __W);
_mm512_mask_reduce_operator(*);
return __builtin_ia32_reduce_mul_d512((__v16si)__W);
}
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_and_epi32( __mmask16 __M, __m512i __W) {
__W = _mm512_mask_mov_epi32(_mm512_set1_epi32(~0U), __M, __W);
_mm512_mask_reduce_operator(&);
return __builtin_ia32_reduce_and_d512((__v16si)__W);
}
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_or_epi32(__mmask16 __M, __m512i __W) {
__W = _mm512_maskz_mov_epi32(__M, __W);
_mm512_mask_reduce_operator(|);
return __builtin_ia32_reduce_or_d512((__v16si)__W);
}
#undef _mm512_mask_reduce_operator
#define _mm512_mask_reduce_operator(op) \
__m256 __t1 = (__m256)_mm512_extractf64x4_pd((__m512d)__W, 0); \
__m256 __t2 = (__m256)_mm512_extractf64x4_pd((__m512d)__W, 1); \
__m256 __t3 = __t1 op __t2; \
__m128 __t4 = _mm256_extractf128_ps(__t3, 0); \
__m128 __t5 = _mm256_extractf128_ps(__t3, 1); \
__m128 __t6 = __t4 op __t5; \
__m128 __t7 = __builtin_shufflevector(__t6, __t6, 2, 3, 0, 1); \
__m128 __t8 = __t6 op __t7; \
__m128 __t9 = __builtin_shufflevector(__t8, __t8, 1, 0, 3, 2); \
__m128 __t10 = __t8 op __t9; \
return __t10[0]
static __inline__ float __DEFAULT_FN_ATTRS512
_mm512_reduce_add_ps(__m512 __W) {
_mm512_mask_reduce_operator(+);
return __builtin_ia32_reduce_fadd_ps512(-0.0f, __W);
}
static __inline__ float __DEFAULT_FN_ATTRS512
_mm512_reduce_mul_ps(__m512 __W) {
_mm512_mask_reduce_operator(*);
return __builtin_ia32_reduce_fmul_ps512(1.0f, __W);
}
static __inline__ float __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_add_ps(__mmask16 __M, __m512 __W) {
__W = _mm512_maskz_mov_ps(__M, __W);
_mm512_mask_reduce_operator(+);
return __builtin_ia32_reduce_fadd_ps512(-0.0f, __W);
}
static __inline__ float __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_mul_ps(__mmask16 __M, __m512 __W) {
__W = _mm512_mask_mov_ps(_mm512_set1_ps(1.0f), __M, __W);
_mm512_mask_reduce_operator(*);
return __builtin_ia32_reduce_fmul_ps512(1.0f, __W);
}
#undef _mm512_mask_reduce_operator
#define _mm512_mask_reduce_operator(op) \
__m512i __t1 = (__m512i)__builtin_shufflevector((__v8di)__V, (__v8di)__V, 4, 5, 6, 7, 0, 1, 2, 3); \
__m512i __t2 = _mm512_##op(__V, __t1); \
__m512i __t3 = (__m512i)__builtin_shufflevector((__v8di)__t2, (__v8di)__t2, 2, 3, 0, 1, 6, 7, 4, 5); \
__m512i __t4 = _mm512_##op(__t2, __t3); \
__m512i __t5 = (__m512i)__builtin_shufflevector((__v8di)__t4, (__v8di)__t4, 1, 0, 3, 2, 5, 4, 7, 6); \
__v8di __t6 = (__v8di)_mm512_##op(__t4, __t5); \
return __t6[0]
static __inline__ long long __DEFAULT_FN_ATTRS512
_mm512_reduce_max_epi64(__m512i __V) {
_mm512_mask_reduce_operator(max_epi64);
return __builtin_ia32_reduce_smax_q512(__V);
}
static __inline__ unsigned long long __DEFAULT_FN_ATTRS512
_mm512_reduce_max_epu64(__m512i __V) {
_mm512_mask_reduce_operator(max_epu64);
return __builtin_ia32_reduce_umax_q512(__V);
}
static __inline__ long long __DEFAULT_FN_ATTRS512
_mm512_reduce_min_epi64(__m512i __V) {
_mm512_mask_reduce_operator(min_epi64);
return __builtin_ia32_reduce_smin_q512(__V);
}
static __inline__ unsigned long long __DEFAULT_FN_ATTRS512
_mm512_reduce_min_epu64(__m512i __V) {
_mm512_mask_reduce_operator(min_epu64);
return __builtin_ia32_reduce_umin_q512(__V);
}
static __inline__ long long __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_max_epi64(__mmask8 __M, __m512i __V) {
__V = _mm512_mask_mov_epi64(_mm512_set1_epi64(-__LONG_LONG_MAX__ - 1LL), __M, __V);
_mm512_mask_reduce_operator(max_epi64);
return __builtin_ia32_reduce_smax_q512(__V);
}
static __inline__ unsigned long long __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_max_epu64(__mmask8 __M, __m512i __V) {
__V = _mm512_maskz_mov_epi64(__M, __V);
_mm512_mask_reduce_operator(max_epu64);
return __builtin_ia32_reduce_umax_q512(__V);
}
static __inline__ long long __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_min_epi64(__mmask8 __M, __m512i __V) {
__V = _mm512_mask_mov_epi64(_mm512_set1_epi64(__LONG_LONG_MAX__), __M, __V);
_mm512_mask_reduce_operator(min_epi64);
return __builtin_ia32_reduce_smin_q512(__V);
}
static __inline__ unsigned long long __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_min_epu64(__mmask8 __M, __m512i __V) {
__V = _mm512_mask_mov_epi64(_mm512_set1_epi64(~0ULL), __M, __V);
_mm512_mask_reduce_operator(min_epu64);
return __builtin_ia32_reduce_umin_q512(__V);
}
#undef _mm512_mask_reduce_operator
#define _mm512_mask_reduce_operator(op) \
__m256i __t1 = _mm512_extracti64x4_epi64(__V, 0); \
__m256i __t2 = _mm512_extracti64x4_epi64(__V, 1); \
__m256i __t3 = _mm256_##op(__t1, __t2); \
__m128i __t4 = _mm256_extracti128_si256(__t3, 0); \
__m128i __t5 = _mm256_extracti128_si256(__t3, 1); \
__m128i __t6 = _mm_##op(__t4, __t5); \
__m128i __t7 = (__m128i)__builtin_shufflevector((__v4si)__t6, (__v4si)__t6, 2, 3, 0, 1); \
__m128i __t8 = _mm_##op(__t6, __t7); \
__m128i __t9 = (__m128i)__builtin_shufflevector((__v4si)__t8, (__v4si)__t8, 1, 0, 3, 2); \
__v4si __t10 = (__v4si)_mm_##op(__t8, __t9); \
return __t10[0]
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_reduce_max_epi32(__m512i __V) {
_mm512_mask_reduce_operator(max_epi32);
return __builtin_ia32_reduce_smax_d512((__v16si)__V);
}
static __inline__ unsigned int __DEFAULT_FN_ATTRS512
_mm512_reduce_max_epu32(__m512i __V) {
_mm512_mask_reduce_operator(max_epu32);
return __builtin_ia32_reduce_umax_d512((__v16si)__V);
}
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_reduce_min_epi32(__m512i __V) {
_mm512_mask_reduce_operator(min_epi32);
return __builtin_ia32_reduce_smin_d512((__v16si)__V);
}
static __inline__ unsigned int __DEFAULT_FN_ATTRS512
_mm512_reduce_min_epu32(__m512i __V) {
_mm512_mask_reduce_operator(min_epu32);
return __builtin_ia32_reduce_umin_d512((__v16si)__V);
}
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_max_epi32(__mmask16 __M, __m512i __V) {
__V = _mm512_mask_mov_epi32(_mm512_set1_epi32(-__INT_MAX__ - 1), __M, __V);
_mm512_mask_reduce_operator(max_epi32);
return __builtin_ia32_reduce_smax_d512((__v16si)__V);
}
static __inline__ unsigned int __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_max_epu32(__mmask16 __M, __m512i __V) {
__V = _mm512_maskz_mov_epi32(__M, __V);
_mm512_mask_reduce_operator(max_epu32);
return __builtin_ia32_reduce_umax_d512((__v16si)__V);
}
static __inline__ int __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_min_epi32(__mmask16 __M, __m512i __V) {
__V = _mm512_mask_mov_epi32(_mm512_set1_epi32(__INT_MAX__), __M, __V);
_mm512_mask_reduce_operator(min_epi32);
return __builtin_ia32_reduce_smin_d512((__v16si)__V);
}
static __inline__ unsigned int __DEFAULT_FN_ATTRS512
_mm512_mask_reduce_min_epu32(__mmask16 __M, __m512i __V) {
__V = _mm512_mask_mov_epi32(_mm512_set1_epi32(~0U), __M, __V);
_mm512_mask_reduce_operator(min_epu32);
return __builtin_ia32_reduce_umin_d512((__v16si)__V);
}
#undef _mm512_mask_reduce_operator
#define _mm512_mask_reduce_operator(op) \
__m256d __t1 = _mm512_extractf64x4_pd(__V, 0); \

View File

@@ -18,13 +18,157 @@
#define __DEFAULT_FN_ATTRS128 __attribute__((__always_inline__, __nodebug__, __target__("avx512vl,avx512vnni"), __min_vector_width__(128)))
#define __DEFAULT_FN_ATTRS256 __attribute__((__always_inline__, __nodebug__, __target__("avx512vl,avx512vnni"), __min_vector_width__(256)))
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a A with
/// corresponding signed 8-bit integers in \a B, producing 4 intermediate signed
/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
/// in \a S, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPBUSD </c> instructions.
///
/// \operation
/// FOR j := 0 to 7
/// tmp1.word := Signed(ZeroExtend16(A.byte[4*j]) * SignExtend16(B.byte[4*j]))
/// tmp2.word := Signed(ZeroExtend16(A.byte[4*j+1]) * SignExtend16(B.byte[4*j+1]))
/// tmp3.word := Signed(ZeroExtend16(A.byte[4*j+2]) * SignExtend16(B.byte[4*j+2]))
/// tmp4.word := Signed(ZeroExtend16(A.byte[4*j+3]) * SignExtend16(B.byte[4*j+3]))
/// DST.dword[j] := S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4
/// ENDFOR
/// DST[MAX:256] := 0
/// \endoperation
#define _mm256_dpbusd_epi32(S, A, B) \
(__m256i)__builtin_ia32_vpdpbusd256((__v8si)(S), (__v8si)(A), (__v8si)(B))
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_dpbusd_epi32(__m256i __S, __m256i __A, __m256i __B)
{
return (__m256i)__builtin_ia32_vpdpbusd256((__v8si)__S, (__v8si)__A,
(__v8si)__B);
}
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a A with
/// corresponding signed 8-bit integers in \a B, producing 4 intermediate signed
/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
/// in \a S using signed saturation, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPBUSDS </c> instructions.
///
/// \operation
/// FOR j := 0 to 7
/// tmp1.word := Signed(ZeroExtend16(A.byte[4*j]) * SignExtend16(B.byte[4*j]))
/// tmp2.word := Signed(ZeroExtend16(A.byte[4*j+1]) * SignExtend16(B.byte[4*j+1]))
/// tmp3.word := Signed(ZeroExtend16(A.byte[4*j+2]) * SignExtend16(B.byte[4*j+2]))
/// tmp4.word := Signed(ZeroExtend16(A.byte[4*j+3]) * SignExtend16(B.byte[4*j+3]))
/// DST.dword[j] := Saturate32(S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4)
/// ENDFOR
/// DST[MAX:256] := 0
/// \endoperation
#define _mm256_dpbusds_epi32(S, A, B) \
(__m256i)__builtin_ia32_vpdpbusds256((__v8si)(S), (__v8si)(A), (__v8si)(B))
/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a A with
/// corresponding 16-bit integers in \a B, producing 2 intermediate signed 32-bit
/// results. Sum these 2 results with the corresponding 32-bit integer in \a S,
/// and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPWSSD </c> instructions.
///
/// \operation
/// FOR j := 0 to 7
/// tmp1.dword := SignExtend32(A.word[2*j]) * SignExtend32(B.word[2*j])
/// tmp2.dword := SignExtend32(A.word[2*j+1]) * SignExtend32(B.word[2*j+1])
/// DST.dword[j] := S.dword[j] + tmp1 + tmp2
/// ENDFOR
/// DST[MAX:256] := 0
/// \endoperation
#define _mm256_dpwssd_epi32(S, A, B) \
(__m256i)__builtin_ia32_vpdpwssd256((__v8si)(S), (__v8si)(A), (__v8si)(B))
/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a A with
/// corresponding 16-bit integers in \a B, producing 2 intermediate signed 32-bit
/// results. Sum these 2 results with the corresponding 32-bit integer in \a S
/// using signed saturation, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPWSSDS </c> instructions.
///
/// \operation
/// FOR j := 0 to 7
/// tmp1.dword := SignExtend32(A.word[2*j]) * SignExtend32(B.word[2*j])
/// tmp2.dword := SignExtend32(A.word[2*j+1]) * SignExtend32(B.word[2*j+1])
/// DST.dword[j] := Saturate32(S.dword[j] + tmp1 + tmp2)
/// ENDFOR
/// DST[MAX:256] := 0
/// \endoperation
#define _mm256_dpwssds_epi32(S, A, B) \
(__m256i)__builtin_ia32_vpdpwssds256((__v8si)(S), (__v8si)(A), (__v8si)(B))
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a A with
/// corresponding signed 8-bit integers in \a B, producing 4 intermediate signed
/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
/// in \a S, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPBUSD </c> instructions.
///
/// \operation
/// FOR j := 0 to 3
/// tmp1.word := Signed(ZeroExtend16(A.byte[4*j]) * SignExtend16(B.byte[4*j]))
/// tmp2.word := Signed(ZeroExtend16(A.byte[4*j+1]) * SignExtend16(B.byte[4*j+1]))
/// tmp3.word := Signed(ZeroExtend16(A.byte[4*j+2]) * SignExtend16(B.byte[4*j+2]))
/// tmp4.word := Signed(ZeroExtend16(A.byte[4*j+3]) * SignExtend16(B.byte[4*j+3]))
/// DST.dword[j] := S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4
/// ENDFOR
/// DST[MAX:128] := 0
/// \endoperation
#define _mm_dpbusd_epi32(S, A, B) \
(__m128i)__builtin_ia32_vpdpbusd128((__v4si)(S), (__v4si)(A), (__v4si)(B))
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a A with
/// corresponding signed 8-bit integers in \a B, producing 4 intermediate signed
/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
/// in \a S using signed saturation, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPBUSDS </c> instructions.
///
/// \operation
/// FOR j := 0 to 3
/// tmp1.word := Signed(ZeroExtend16(A.byte[4*j]) * SignExtend16(B.byte[4*j]))
/// tmp2.word := Signed(ZeroExtend16(A.byte[4*j+1]) * SignExtend16(B.byte[4*j+1]))
/// tmp3.word := Signed(ZeroExtend16(A.byte[4*j+2]) * SignExtend16(B.byte[4*j+2]))
/// tmp4.word := Signed(ZeroExtend16(A.byte[4*j+3]) * SignExtend16(B.byte[4*j+3]))
/// DST.dword[j] := Saturate32(S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4)
/// ENDFOR
/// DST[MAX:128] := 0
/// \endoperation
#define _mm_dpbusds_epi32(S, A, B) \
(__m128i)__builtin_ia32_vpdpbusds128((__v4si)(S), (__v4si)(A), (__v4si)(B))
/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a A with
/// corresponding 16-bit integers in \a B, producing 2 intermediate signed 32-bit
/// results. Sum these 2 results with the corresponding 32-bit integer in \a S,
/// and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPWSSD </c> instructions.
///
/// \operation
/// FOR j := 0 to 3
/// tmp1.dword := SignExtend32(A.word[2*j]) * SignExtend32(B.word[2*j])
/// tmp2.dword := SignExtend32(A.word[2*j+1]) * SignExtend32(B.word[2*j+1])
/// DST.dword[j] := S.dword[j] + tmp1 + tmp2
/// ENDFOR
/// DST[MAX:128] := 0
/// \endoperation
#define _mm_dpwssd_epi32(S, A, B) \
(__m128i)__builtin_ia32_vpdpwssd128((__v4si)(S), (__v4si)(A), (__v4si)(B))
/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a A with
/// corresponding 16-bit integers in \a B, producing 2 intermediate signed 32-bit
/// results. Sum these 2 results with the corresponding 32-bit integer in \a S
/// using signed saturation, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPWSSDS </c> instructions.
///
/// \operation
/// FOR j := 0 to 3
/// tmp1.dword := SignExtend32(A.word[2*j]) * SignExtend32(B.word[2*j])
/// tmp2.dword := SignExtend32(A.word[2*j+1]) * SignExtend32(B.word[2*j+1])
/// DST.dword[j] := Saturate32(S.dword[j] + tmp1 + tmp2)
/// ENDFOR
/// DST[MAX:128] := 0
/// \endoperation
#define _mm_dpwssds_epi32(S, A, B) \
(__m128i)__builtin_ia32_vpdpwssds128((__v4si)(S), (__v4si)(A), (__v4si)(B))
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_mask_dpbusd_epi32(__m256i __S, __mmask8 __U, __m256i __A, __m256i __B)
@@ -42,13 +186,6 @@ _mm256_maskz_dpbusd_epi32(__mmask8 __U, __m256i __S, __m256i __A, __m256i __B)
(__v8si)_mm256_setzero_si256());
}
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_dpbusds_epi32(__m256i __S, __m256i __A, __m256i __B)
{
return (__m256i)__builtin_ia32_vpdpbusds256((__v8si)__S, (__v8si)__A,
(__v8si)__B);
}
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_mask_dpbusds_epi32(__m256i __S, __mmask8 __U, __m256i __A, __m256i __B)
{
@@ -65,13 +202,6 @@ _mm256_maskz_dpbusds_epi32(__mmask8 __U, __m256i __S, __m256i __A, __m256i __B)
(__v8si)_mm256_setzero_si256());
}
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_dpwssd_epi32(__m256i __S, __m256i __A, __m256i __B)
{
return (__m256i)__builtin_ia32_vpdpwssd256((__v8si)__S, (__v8si)__A,
(__v8si)__B);
}
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_mask_dpwssd_epi32(__m256i __S, __mmask8 __U, __m256i __A, __m256i __B)
{
@@ -88,13 +218,6 @@ _mm256_maskz_dpwssd_epi32(__mmask8 __U, __m256i __S, __m256i __A, __m256i __B)
(__v8si)_mm256_setzero_si256());
}
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_dpwssds_epi32(__m256i __S, __m256i __A, __m256i __B)
{
return (__m256i)__builtin_ia32_vpdpwssds256((__v8si)__S, (__v8si)__A,
(__v8si)__B);
}
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_mask_dpwssds_epi32(__m256i __S, __mmask8 __U, __m256i __A, __m256i __B)
{
@@ -111,13 +234,6 @@ _mm256_maskz_dpwssds_epi32(__mmask8 __U, __m256i __S, __m256i __A, __m256i __B)
(__v8si)_mm256_setzero_si256());
}
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_dpbusd_epi32(__m128i __S, __m128i __A, __m128i __B)
{
return (__m128i)__builtin_ia32_vpdpbusd128((__v4si)__S, (__v4si)__A,
(__v4si)__B);
}
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_mask_dpbusd_epi32(__m128i __S, __mmask8 __U, __m128i __A, __m128i __B)
{
@@ -134,13 +250,6 @@ _mm_maskz_dpbusd_epi32(__mmask8 __U, __m128i __S, __m128i __A, __m128i __B)
(__v4si)_mm_setzero_si128());
}
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_dpbusds_epi32(__m128i __S, __m128i __A, __m128i __B)
{
return (__m128i)__builtin_ia32_vpdpbusds128((__v4si)__S, (__v4si)__A,
(__v4si)__B);
}
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_mask_dpbusds_epi32(__m128i __S, __mmask8 __U, __m128i __A, __m128i __B)
{
@@ -157,13 +266,6 @@ _mm_maskz_dpbusds_epi32(__mmask8 __U, __m128i __S, __m128i __A, __m128i __B)
(__v4si)_mm_setzero_si128());
}
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_dpwssd_epi32(__m128i __S, __m128i __A, __m128i __B)
{
return (__m128i)__builtin_ia32_vpdpwssd128((__v4si)__S, (__v4si)__A,
(__v4si)__B);
}
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_mask_dpwssd_epi32(__m128i __S, __mmask8 __U, __m128i __A, __m128i __B)
{
@@ -180,13 +282,6 @@ _mm_maskz_dpwssd_epi32(__mmask8 __U, __m128i __S, __m128i __A, __m128i __B)
(__v4si)_mm_setzero_si128());
}
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_dpwssds_epi32(__m128i __S, __m128i __A, __m128i __B)
{
return (__m128i)__builtin_ia32_vpdpwssds128((__v4si)__S, (__v4si)__A,
(__v4si)__B);
}
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_mask_dpwssds_epi32(__m128i __S, __mmask8 __U, __m128i __A, __m128i __B)
{

View File

@@ -2245,7 +2245,7 @@ _mm256_cvttps_epi32(__m256 __a)
/// Returns the first element of the input vector of [4 x double].
///
/// \headerfile <avxintrin.h>
/// \headerfile <x86intrin.h>
///
/// This intrinsic is a utility function and does not correspond to a specific
/// instruction.
@@ -2261,7 +2261,7 @@ _mm256_cvtsd_f64(__m256d __a)
/// Returns the first element of the input vector of [8 x i32].
///
/// \headerfile <avxintrin.h>
/// \headerfile <x86intrin.h>
///
/// This intrinsic is a utility function and does not correspond to a specific
/// instruction.
@@ -2278,7 +2278,7 @@ _mm256_cvtsi256_si32(__m256i __a)
/// Returns the first element of the input vector of [8 x float].
///
/// \headerfile <avxintrin.h>
/// \headerfile <x86intrin.h>
///
/// This intrinsic is a utility function and does not correspond to a specific
/// instruction.

225
lib/include/avxvnniintrin.h vendored Normal file
View File

@@ -0,0 +1,225 @@
/*===--------------- avxvnniintrin.h - VNNI intrinsics --------------------===
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*===-----------------------------------------------------------------------===
*/
#ifndef __IMMINTRIN_H
#error "Never use <avxvnniintrin.h> directly; include <immintrin.h> instead."
#endif
#ifndef __AVXVNNIINTRIN_H
#define __AVXVNNIINTRIN_H
/* Below intrinsics defined in avx512vlvnniintrin.h can be used for AVXVNNI */
/// \fn __m256i _mm256_dpbusd_epi32(__m256i __S, __m256i __A, __m256i __B)
/// \fn __m256i _mm256_dpbusds_epi32(__m256i __S, __m256i __A, __m256i __B)
/// \fn __m256i _mm256_dpwssd_epi32(__m256i __S, __m256i __A, __m256i __B)
/// \fn __m256i _mm256_dpwssds_epi32(__m256i __S, __m256i __A, __m256i __B)
/// \fn __m128i _mm_dpbusd_epi32(__m128i __S, __m128i __A, __m128i __B)
/// \fn __m128i _mm_dpbusds_epi32(__m128i __S, __m128i __A, __m128i __B)
/// \fn __m128i _mm_dpwssd_epi32(__m128i __S, __m128i __A, __m128i __B)
/// \fn __m128i _mm_dpwssds_epi32(__m128i __S, __m128i __A, __m128i __B)
/* Intrinsics with _avx_ prefix are for compatibility with msvc. */
/* Define the default attributes for the functions in this file. */
#define __DEFAULT_FN_ATTRS256 __attribute__((__always_inline__, __nodebug__, __target__("avxvnni"), __min_vector_width__(256)))
#define __DEFAULT_FN_ATTRS128 __attribute__((__always_inline__, __nodebug__, __target__("avxvnni"), __min_vector_width__(128)))
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a __A with
/// corresponding signed 8-bit integers in \a __B, producing 4 intermediate signed
/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
/// in \a __S, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPBUSD </c> instructions.
///
/// \operation
/// FOR j := 0 to 7
/// tmp1.word := Signed(ZeroExtend16(__A.byte[4*j]) * SignExtend16(__B.byte[4*j]))
/// tmp2.word := Signed(ZeroExtend16(__A.byte[4*j+1]) * SignExtend16(__B.byte[4*j+1]))
/// tmp3.word := Signed(ZeroExtend16(__A.byte[4*j+2]) * SignExtend16(__B.byte[4*j+2]))
/// tmp4.word := Signed(ZeroExtend16(__A.byte[4*j+3]) * SignExtend16(__B.byte[4*j+3]))
/// DST.dword[j] := __S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4
/// ENDFOR
/// DST[MAX:256] := 0
/// \endoperation
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_dpbusd_avx_epi32(__m256i __S, __m256i __A, __m256i __B)
{
return (__m256i)__builtin_ia32_vpdpbusd256((__v8si)__S, (__v8si)__A, (__v8si)__B);
}
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a __A with
/// corresponding signed 8-bit integers in \a __B, producing 4 intermediate signed
/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
/// in \a __S using signed saturation, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPBUSDS </c> instructions.
///
/// \operation
/// FOR j := 0 to 7
/// tmp1.word := Signed(ZeroExtend16(__A.byte[4*j]) * SignExtend16(__B.byte[4*j]))
/// tmp2.word := Signed(ZeroExtend16(__A.byte[4*j+1]) * SignExtend16(__B.byte[4*j+1]))
/// tmp3.word := Signed(ZeroExtend16(__A.byte[4*j+2]) * SignExtend16(__B.byte[4*j+2]))
/// tmp4.word := Signed(ZeroExtend16(__A.byte[4*j+3]) * SignExtend16(__B.byte[4*j+3]))
/// DST.dword[j] := Saturate32(__S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4)
/// ENDFOR
/// DST[MAX:256] := 0
/// \endoperation
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_dpbusds_avx_epi32(__m256i __S, __m256i __A, __m256i __B)
{
return (__m256i)__builtin_ia32_vpdpbusds256((__v8si)__S, (__v8si)__A, (__v8si)__B);
}
/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a __A with
/// corresponding 16-bit integers in \a __B, producing 2 intermediate signed 32-bit
/// results. Sum these 2 results with the corresponding 32-bit integer in \a __S,
/// and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPWSSD </c> instructions.
///
/// \operation
/// FOR j := 0 to 7
/// tmp1.dword := SignExtend32(__A.word[2*j]) * SignExtend32(__B.word[2*j])
/// tmp2.dword := SignExtend32(__A.word[2*j+1]) * SignExtend32(__B.word[2*j+1])
/// DST.dword[j] := __S.dword[j] + tmp1 + tmp2
/// ENDFOR
/// DST[MAX:256] := 0
/// \endoperation
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_dpwssd_avx_epi32(__m256i __S, __m256i __A, __m256i __B)
{
return (__m256i)__builtin_ia32_vpdpwssd256((__v8si)__S, (__v8si)__A, (__v8si)__B);
}
/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a __A with
/// corresponding 16-bit integers in \a __B, producing 2 intermediate signed 32-bit
/// results. Sum these 2 results with the corresponding 32-bit integer in \a __S
/// using signed saturation, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPWSSDS </c> instructions.
///
/// \operation
/// FOR j := 0 to 7
/// tmp1.dword := SignExtend32(__A.word[2*j]) * SignExtend32(__B.word[2*j])
/// tmp2.dword := SignExtend32(__A.word[2*j+1]) * SignExtend32(__B.word[2*j+1])
/// DST.dword[j] := Saturate32(__S.dword[j] + tmp1 + tmp2)
/// ENDFOR
/// DST[MAX:256] := 0
/// \endoperation
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_dpwssds_avx_epi32(__m256i __S, __m256i __A, __m256i __B)
{
return (__m256i)__builtin_ia32_vpdpwssds256((__v8si)__S, (__v8si)__A, (__v8si)__B);
}
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a __A with
/// corresponding signed 8-bit integers in \a __B, producing 4 intermediate signed
/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
/// in \a __S, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPBUSD </c> instructions.
///
/// \operation
/// FOR j := 0 to 3
/// tmp1.word := Signed(ZeroExtend16(__A.byte[4*j]) * SignExtend16(__B.byte[4*j]))
/// tmp2.word := Signed(ZeroExtend16(__A.byte[4*j+1]) * SignExtend16(__B.byte[4*j+1]))
/// tmp3.word := Signed(ZeroExtend16(__A.byte[4*j+2]) * SignExtend16(__B.byte[4*j+2]))
/// tmp4.word := Signed(ZeroExtend16(__A.byte[4*j+3]) * SignExtend16(__B.byte[4*j+3]))
/// DST.dword[j] := __S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4
/// ENDFOR
/// DST[MAX:128] := 0
/// \endoperation
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_dpbusd_avx_epi32(__m128i __S, __m128i __A, __m128i __B)
{
return (__m128i)__builtin_ia32_vpdpbusd128((__v4si)__S, (__v4si)__A, (__v4si)__B);
}
/// Multiply groups of 4 adjacent pairs of unsigned 8-bit integers in \a __A with
/// corresponding signed 8-bit integers in \a __B, producing 4 intermediate signed
/// 16-bit results. Sum these 4 results with the corresponding 32-bit integer
/// in \a __S using signed saturation, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPBUSDS </c> instructions.
///
/// \operation
/// FOR j := 0 to 3
/// tmp1.word := Signed(ZeroExtend16(__A.byte[4*j]) * SignExtend16(__B.byte[4*j]))
/// tmp2.word := Signed(ZeroExtend16(__A.byte[4*j+1]) * SignExtend16(__B.byte[4*j+1]))
/// tmp3.word := Signed(ZeroExtend16(__A.byte[4*j+2]) * SignExtend16(__B.byte[4*j+2]))
/// tmp4.word := Signed(ZeroExtend16(__A.byte[4*j+3]) * SignExtend16(__B.byte[4*j+3]))
/// DST.dword[j] := Saturate32(__S.dword[j] + tmp1 + tmp2 + tmp3 + tmp4)
/// ENDFOR
/// DST[MAX:128] := 0
/// \endoperation
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_dpbusds_avx_epi32(__m128i __S, __m128i __A, __m128i __B)
{
return (__m128i)__builtin_ia32_vpdpbusds128((__v4si)__S, (__v4si)__A, (__v4si)__B);
}
/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a __A with
/// corresponding 16-bit integers in \a __B, producing 2 intermediate signed 32-bit
/// results. Sum these 2 results with the corresponding 32-bit integer in \a __S,
/// and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPWSSD </c> instructions.
///
/// \operation
/// FOR j := 0 to 3
/// tmp1.dword := SignExtend32(__A.word[2*j]) * SignExtend32(__B.word[2*j])
/// tmp2.dword := SignExtend32(__A.word[2*j+1]) * SignExtend32(__B.word[2*j+1])
/// DST.dword[j] := __S.dword[j] + tmp1 + tmp2
/// ENDFOR
/// DST[MAX:128] := 0
/// \endoperation
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_dpwssd_avx_epi32(__m128i __S, __m128i __A, __m128i __B)
{
return (__m128i)__builtin_ia32_vpdpwssd128((__v4si)__S, (__v4si)__A, (__v4si)__B);
}
/// Multiply groups of 2 adjacent pairs of signed 16-bit integers in \a __A with
/// corresponding 16-bit integers in \a __B, producing 2 intermediate signed 32-bit
/// results. Sum these 2 results with the corresponding 32-bit integer in \a __S
/// using signed saturation, and store the packed 32-bit results in DST.
///
/// This intrinsic corresponds to the <c> VPDPWSSDS </c> instructions.
///
/// \operation
/// FOR j := 0 to 3
/// tmp1.dword := SignExtend32(__A.word[2*j]) * SignExtend32(__B.word[2*j])
/// tmp2.dword := SignExtend32(__A.word[2*j+1]) * SignExtend32(__B.word[2*j+1])
/// DST.dword[j] := Saturate32(__S.dword[j] + tmp1 + tmp2)
/// ENDFOR
/// DST[MAX:128] := 0
/// \endoperation
static __inline__ __m128i __DEFAULT_FN_ATTRS128
_mm_dpwssds_avx_epi32(__m128i __S, __m128i __A, __m128i __B)
{
return (__m128i)__builtin_ia32_vpdpwssds128((__v4si)__S, (__v4si)__A, (__v4si)__B);
}
#undef __DEFAULT_FN_ATTRS128
#undef __DEFAULT_FN_ATTRS256
#endif // __AVXVNNIINTRIN_H

8
lib/include/cpuid.h vendored
View File

@@ -7,6 +7,9 @@
*===-----------------------------------------------------------------------===
*/
#ifndef __CPUID_H
#define __CPUID_H
#if !(__x86_64__ || __i386__)
#error this header is for x86 only
#endif
@@ -186,6 +189,7 @@
/* Features in %edx for leaf 7 sub-leaf 0 */
#define bit_AVX5124VNNIW 0x00000004
#define bit_AVX5124FMAPS 0x00000008
#define bit_UINTR 0x00000020
#define bit_SERIALIZE 0x00004000
#define bit_TSXLDTRK 0x00010000
#define bit_PCONFIG 0x00040000
@@ -195,7 +199,9 @@
#define bit_AMXINT8 0x02000000
/* Features in %eax for leaf 7 sub-leaf 1 */
#define bit_AVXVNNI 0x00000008
#define bit_AVX512BF16 0x00000020
#define bit_HRESET 0x00400000
/* Features in %eax for leaf 13 sub-leaf 1 */
#define bit_XSAVEOPT 0x00000001
@@ -309,3 +315,5 @@ static __inline int __get_cpuid_count (unsigned int __leaf,
__cpuid_count(__leaf, __subleaf, *__eax, *__ebx, *__ecx, *__edx);
return 1;
}
#endif /* __CPUID_H */

View File

@@ -1,4 +1,4 @@
/*===---- complex - CUDA wrapper for <algorithm> ----------------------------===
/*===---- algorithm - CUDA wrapper for <algorithm> -------------------------===
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,4 +1,4 @@
/*===---- complex - CUDA wrapper for <new> ------------------------------===
/*===---- new - CUDA wrapper for <new> -------------------------------------===
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,13 @@
#include_next <new>
#if !defined(__device__)
// The header has been included too early from the standard C++ library
// and CUDA-specific macros are not available yet.
// Undo the include guard and try again later.
#undef __CLANG_CUDA_WRAPPERS_NEW
#else
#pragma push_macro("CUDA_NOEXCEPT")
#if __cplusplus >= 201103L
#define CUDA_NOEXCEPT noexcept
@@ -95,4 +102,5 @@ __device__ inline void operator delete[](void *, void *) CUDA_NOEXCEPT {}
#pragma pop_macro("CUDA_NOEXCEPT")
#endif // __device__
#endif // include guard

View File

@@ -4025,7 +4025,7 @@ _mm_storeu_si128(__m128i_u *__p, __m128i __b)
///
/// \param __p
/// A pointer to a 64-bit memory location. The address of the memory
/// location does not have to be algned.
/// location does not have to be aligned.
/// \param __b
/// A 128-bit integer vector containing the value to be stored.
static __inline__ void __DEFAULT_FN_ATTRS

View File

@@ -14,38 +14,56 @@
#ifndef __GFNIINTRIN_H
#define __GFNIINTRIN_H
/* Default attributes for simple form (no masking). */
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("gfni"), __min_vector_width__(128)))
/* Default attributes for YMM unmasked form. */
#define __DEFAULT_FN_ATTRS_Y __attribute__((__always_inline__, __nodebug__, __target__("avx,gfni"), __min_vector_width__(256)))
/* Default attributes for ZMM forms. */
#define __DEFAULT_FN_ATTRS_Z __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,gfni"), __min_vector_width__(512)))
/* Default attributes for VLX forms. */
#define __DEFAULT_FN_ATTRS_VL128 __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,avx512vl,gfni"), __min_vector_width__(128)))
#define __DEFAULT_FN_ATTRS_VL256 __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,avx512vl,gfni"), __min_vector_width__(256)))
#define _mm_gf2p8affineinv_epi64_epi8(A, B, I) \
(__m128i)__builtin_ia32_vgf2p8affineinvqb_v16qi((__v16qi)(__m128i)(A), \
(__v16qi)(__m128i)(B), \
(char)(I))
#define _mm_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \
(__m128i)__builtin_ia32_selectb_128((__mmask16)(U), \
(__v16qi)_mm_gf2p8affineinv_epi64_epi8(A, B, I), \
(__v16qi)(__m128i)(S))
#define _mm_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \
(__m128i)_mm_mask_gf2p8affineinv_epi64_epi8((__m128i)_mm_setzero_si128(), \
U, A, B, I)
#define _mm_gf2p8affine_epi64_epi8(A, B, I) \
(__m128i)__builtin_ia32_vgf2p8affineqb_v16qi((__v16qi)(__m128i)(A), \
(__v16qi)(__m128i)(B), \
(char)(I))
static __inline__ __m128i __DEFAULT_FN_ATTRS
_mm_gf2p8mul_epi8(__m128i __A, __m128i __B)
{
return (__m128i) __builtin_ia32_vgf2p8mulb_v16qi((__v16qi) __A,
(__v16qi) __B);
}
#ifdef __AVXINTRIN_H
#define _mm256_gf2p8affineinv_epi64_epi8(A, B, I) \
(__m256i)__builtin_ia32_vgf2p8affineinvqb_v32qi((__v32qi)(__m256i)(A), \
(__v32qi)(__m256i)(B), \
(char)(I))
#define _mm256_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \
(__m256i)__builtin_ia32_selectb_256((__mmask32)(U), \
(__v32qi)_mm256_gf2p8affineinv_epi64_epi8(A, B, I), \
(__v32qi)(__m256i)(S))
#define _mm256_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \
(__m256i)_mm256_mask_gf2p8affineinv_epi64_epi8((__m256i)_mm256_setzero_si256(), \
U, A, B, I)
#define _mm256_gf2p8affine_epi64_epi8(A, B, I) \
(__m256i)__builtin_ia32_vgf2p8affineqb_v32qi((__v32qi)(__m256i)(A), \
(__v32qi)(__m256i)(B), \
(char)(I))
static __inline__ __m256i __DEFAULT_FN_ATTRS_Y
_mm256_gf2p8mul_epi8(__m256i __A, __m256i __B)
{
return (__m256i) __builtin_ia32_vgf2p8mulb_v32qi((__v32qi) __A,
(__v32qi) __B);
}
#endif /* __AVXINTRIN_H */
#ifdef __AVX512BWINTRIN_H
#define _mm512_gf2p8affineinv_epi64_epi8(A, B, I) \
(__m512i)__builtin_ia32_vgf2p8affineinvqb_v64qi((__v64qi)(__m512i)(A), \
(__v64qi)(__m512i)(B), \
@@ -60,37 +78,6 @@
(__m512i)_mm512_mask_gf2p8affineinv_epi64_epi8((__m512i)_mm512_setzero_si512(), \
U, A, B, I)
#define _mm_gf2p8affine_epi64_epi8(A, B, I) \
(__m128i)__builtin_ia32_vgf2p8affineqb_v16qi((__v16qi)(__m128i)(A), \
(__v16qi)(__m128i)(B), \
(char)(I))
#define _mm_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) \
(__m128i)__builtin_ia32_selectb_128((__mmask16)(U), \
(__v16qi)_mm_gf2p8affine_epi64_epi8(A, B, I), \
(__v16qi)(__m128i)(S))
#define _mm_maskz_gf2p8affine_epi64_epi8(U, A, B, I) \
(__m128i)_mm_mask_gf2p8affine_epi64_epi8((__m128i)_mm_setzero_si128(), \
U, A, B, I)
#define _mm256_gf2p8affine_epi64_epi8(A, B, I) \
(__m256i)__builtin_ia32_vgf2p8affineqb_v32qi((__v32qi)(__m256i)(A), \
(__v32qi)(__m256i)(B), \
(char)(I))
#define _mm256_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) \
(__m256i)__builtin_ia32_selectb_256((__mmask32)(U), \
(__v32qi)_mm256_gf2p8affine_epi64_epi8(A, B, I), \
(__v32qi)(__m256i)(S))
#define _mm256_maskz_gf2p8affine_epi64_epi8(U, A, B, I) \
(__m256i)_mm256_mask_gf2p8affine_epi64_epi8((__m256i)_mm256_setzero_si256(), \
U, A, B, I)
#define _mm512_gf2p8affine_epi64_epi8(A, B, I) \
(__m512i)__builtin_ia32_vgf2p8affineqb_v64qi((__v64qi)(__m512i)(A), \
(__v64qi)(__m512i)(B), \
@@ -105,63 +92,6 @@
(__m512i)_mm512_mask_gf2p8affine_epi64_epi8((__m512i)_mm512_setzero_si512(), \
U, A, B, I)
/* Default attributes for simple form (no masking). */
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("gfni"), __min_vector_width__(128)))
/* Default attributes for YMM unmasked form. */
#define __DEFAULT_FN_ATTRS_Y __attribute__((__always_inline__, __nodebug__, __target__("avx,gfni"), __min_vector_width__(256)))
/* Default attributes for ZMM forms. */
#define __DEFAULT_FN_ATTRS_Z __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,gfni"), __min_vector_width__(512)))
/* Default attributes for VLX forms. */
#define __DEFAULT_FN_ATTRS_VL128 __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,avx512vl,gfni"), __min_vector_width__(128)))
#define __DEFAULT_FN_ATTRS_VL256 __attribute__((__always_inline__, __nodebug__, __target__("avx512bw,avx512vl,gfni"), __min_vector_width__(256)))
static __inline__ __m128i __DEFAULT_FN_ATTRS
_mm_gf2p8mul_epi8(__m128i __A, __m128i __B)
{
return (__m128i) __builtin_ia32_vgf2p8mulb_v16qi((__v16qi) __A,
(__v16qi) __B);
}
static __inline__ __m128i __DEFAULT_FN_ATTRS_VL128
_mm_mask_gf2p8mul_epi8(__m128i __S, __mmask16 __U, __m128i __A, __m128i __B)
{
return (__m128i) __builtin_ia32_selectb_128(__U,
(__v16qi) _mm_gf2p8mul_epi8(__A, __B),
(__v16qi) __S);
}
static __inline__ __m128i __DEFAULT_FN_ATTRS_VL128
_mm_maskz_gf2p8mul_epi8(__mmask16 __U, __m128i __A, __m128i __B)
{
return _mm_mask_gf2p8mul_epi8((__m128i)_mm_setzero_si128(),
__U, __A, __B);
}
static __inline__ __m256i __DEFAULT_FN_ATTRS_Y
_mm256_gf2p8mul_epi8(__m256i __A, __m256i __B)
{
return (__m256i) __builtin_ia32_vgf2p8mulb_v32qi((__v32qi) __A,
(__v32qi) __B);
}
static __inline__ __m256i __DEFAULT_FN_ATTRS_VL256
_mm256_mask_gf2p8mul_epi8(__m256i __S, __mmask32 __U, __m256i __A, __m256i __B)
{
return (__m256i) __builtin_ia32_selectb_256(__U,
(__v32qi) _mm256_gf2p8mul_epi8(__A, __B),
(__v32qi) __S);
}
static __inline__ __m256i __DEFAULT_FN_ATTRS_VL256
_mm256_maskz_gf2p8mul_epi8(__mmask32 __U, __m256i __A, __m256i __B)
{
return _mm256_mask_gf2p8mul_epi8((__m256i)_mm256_setzero_si256(),
__U, __A, __B);
}
static __inline__ __m512i __DEFAULT_FN_ATTRS_Z
_mm512_gf2p8mul_epi8(__m512i __A, __m512i __B)
{
@@ -183,6 +113,75 @@ _mm512_maskz_gf2p8mul_epi8(__mmask64 __U, __m512i __A, __m512i __B)
return _mm512_mask_gf2p8mul_epi8((__m512i)_mm512_setzero_si512(),
__U, __A, __B);
}
#endif /* __AVX512BWINTRIN_H */
#ifdef __AVX512VLBWINTRIN_H
#define _mm_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \
(__m128i)__builtin_ia32_selectb_128((__mmask16)(U), \
(__v16qi)_mm_gf2p8affineinv_epi64_epi8(A, B, I), \
(__v16qi)(__m128i)(S))
#define _mm_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \
(__m128i)_mm_mask_gf2p8affineinv_epi64_epi8((__m128i)_mm_setzero_si128(), \
U, A, B, I)
#define _mm256_mask_gf2p8affineinv_epi64_epi8(S, U, A, B, I) \
(__m256i)__builtin_ia32_selectb_256((__mmask32)(U), \
(__v32qi)_mm256_gf2p8affineinv_epi64_epi8(A, B, I), \
(__v32qi)(__m256i)(S))
#define _mm256_maskz_gf2p8affineinv_epi64_epi8(U, A, B, I) \
(__m256i)_mm256_mask_gf2p8affineinv_epi64_epi8((__m256i)_mm256_setzero_si256(), \
U, A, B, I)
#define _mm_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) \
(__m128i)__builtin_ia32_selectb_128((__mmask16)(U), \
(__v16qi)_mm_gf2p8affine_epi64_epi8(A, B, I), \
(__v16qi)(__m128i)(S))
#define _mm_maskz_gf2p8affine_epi64_epi8(U, A, B, I) \
(__m128i)_mm_mask_gf2p8affine_epi64_epi8((__m128i)_mm_setzero_si128(), \
U, A, B, I)
#define _mm256_mask_gf2p8affine_epi64_epi8(S, U, A, B, I) \
(__m256i)__builtin_ia32_selectb_256((__mmask32)(U), \
(__v32qi)_mm256_gf2p8affine_epi64_epi8(A, B, I), \
(__v32qi)(__m256i)(S))
#define _mm256_maskz_gf2p8affine_epi64_epi8(U, A, B, I) \
(__m256i)_mm256_mask_gf2p8affine_epi64_epi8((__m256i)_mm256_setzero_si256(), \
U, A, B, I)
static __inline__ __m128i __DEFAULT_FN_ATTRS_VL128
_mm_mask_gf2p8mul_epi8(__m128i __S, __mmask16 __U, __m128i __A, __m128i __B)
{
return (__m128i) __builtin_ia32_selectb_128(__U,
(__v16qi) _mm_gf2p8mul_epi8(__A, __B),
(__v16qi) __S);
}
static __inline__ __m128i __DEFAULT_FN_ATTRS_VL128
_mm_maskz_gf2p8mul_epi8(__mmask16 __U, __m128i __A, __m128i __B)
{
return _mm_mask_gf2p8mul_epi8((__m128i)_mm_setzero_si128(),
__U, __A, __B);
}
static __inline__ __m256i __DEFAULT_FN_ATTRS_VL256
_mm256_mask_gf2p8mul_epi8(__m256i __S, __mmask32 __U, __m256i __A, __m256i __B)
{
return (__m256i) __builtin_ia32_selectb_256(__U,
(__v32qi) _mm256_gf2p8mul_epi8(__A, __B),
(__v32qi) __S);
}
static __inline__ __m256i __DEFAULT_FN_ATTRS_VL256
_mm256_maskz_gf2p8mul_epi8(__mmask32 __U, __m256i __A, __m256i __B)
{
return _mm256_mask_gf2p8mul_epi8((__m256i)_mm256_setzero_si256(),
__U, __A, __B);
}
#endif /* __AVX512VLBWINTRIN_H */
#undef __DEFAULT_FN_ATTRS
#undef __DEFAULT_FN_ATTRS_Y

49
lib/include/hresetintrin.h vendored Normal file
View File

@@ -0,0 +1,49 @@
/*===---------------- hresetintrin.h - HRESET intrinsics -------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/
#ifndef __X86GPRINTRIN_H
#error "Never use <hresetintrin.h> directly; include <x86gprintrin.h> instead."
#endif
#ifndef __HRESETINTRIN_H
#define __HRESETINTRIN_H
#if __has_extension(gnu_asm)
/* Define the default attributes for the functions in this file. */
#define __DEFAULT_FN_ATTRS \
__attribute__((__always_inline__, __nodebug__, __target__("hreset")))
/// Provides a hint to the processor to selectively reset the prediction
/// history of the current logical processor specified by a 32-bit integer
/// value \a __eax.
///
/// This intrinsic corresponds to the <c> HRESET </c> instruction.
///
/// \operation
/// IF __eax == 0
/// // nop
/// ELSE
/// FOR i := 0 to 31
/// IF __eax[i]
/// ResetPredictionFeature(i)
/// FI
/// ENDFOR
/// FI
/// \endoperation
static __inline void __DEFAULT_FN_ATTRS
_hreset(int __eax)
{
__asm__ ("hreset $0" :: "a"(__eax));
}
#undef __DEFAULT_FN_ATTRS
#endif /* __has_extension(gnu_asm) */
#endif /* __HRESETINTRIN_H */

View File

@@ -14,6 +14,18 @@
#ifndef __IA32INTRIN_H
#define __IA32INTRIN_H
/* Define the default attributes for the functions in this file. */
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
#define __DEFAULT_FN_ATTRS_SSE42 __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
#if defined(__cplusplus) && (__cplusplus >= 201103L)
#define __DEFAULT_FN_ATTRS_CAST __attribute__((__always_inline__)) constexpr
#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
#else
#define __DEFAULT_FN_ATTRS_CAST __attribute__((__always_inline__))
#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
#endif
/** Find the first set bit starting from the lsb. Result is undefined if
* input is 0.
*
@@ -26,7 +38,7 @@
* A 32-bit integer operand.
* \returns A 32-bit integer containing the bit number.
*/
static __inline__ int __attribute__((__always_inline__, __nodebug__))
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
__bsfd(int __A) {
return __builtin_ctz(__A);
}
@@ -43,7 +55,7 @@ __bsfd(int __A) {
* A 32-bit integer operand.
* \returns A 32-bit integer containing the bit number.
*/
static __inline__ int __attribute__((__always_inline__, __nodebug__))
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
__bsrd(int __A) {
return 31 - __builtin_clz(__A);
}
@@ -59,12 +71,12 @@ __bsrd(int __A) {
* A 32-bit integer operand.
* \returns A 32-bit integer containing the swapped bytes.
*/
static __inline__ int __attribute__((__always_inline__, __nodebug__))
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
__bswapd(int __A) {
return __builtin_bswap32(__A);
}
static __inline__ int __attribute__((__always_inline__, __nodebug__))
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
_bswap(int __A) {
return __builtin_bswap32(__A);
}
@@ -85,7 +97,7 @@ _bswap(int __A) {
* A 64-bit integer operand.
* \returns A 32-bit integer containing the bit number.
*/
static __inline__ int __attribute__((__always_inline__, __nodebug__))
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
__bsfq(long long __A) {
return __builtin_ctzll(__A);
}
@@ -102,7 +114,7 @@ __bsfq(long long __A) {
* A 64-bit integer operand.
* \returns A 32-bit integer containing the bit number.
*/
static __inline__ int __attribute__((__always_inline__, __nodebug__))
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
__bsrq(long long __A) {
return 63 - __builtin_clzll(__A);
}
@@ -118,7 +130,7 @@ __bsrq(long long __A) {
* A 64-bit integer operand.
* \returns A 64-bit integer containing the swapped bytes.
*/
static __inline__ long long __attribute__((__always_inline__, __nodebug__))
static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
__bswapq(long long __A) {
return __builtin_bswap64(__A);
}
@@ -138,7 +150,7 @@ __bswapq(long long __A) {
* \returns A 32-bit integer containing the number of bits with value 1 in the
* source operand.
*/
static __inline__ int __attribute__((__always_inline__, __nodebug__))
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
__popcntd(unsigned int __A)
{
return __builtin_popcount(__A);
@@ -159,7 +171,7 @@ __popcntd(unsigned int __A)
* \returns A 64-bit integer containing the number of bits with value 1 in the
* source operand.
*/
static __inline__ long long __attribute__((__always_inline__, __nodebug__))
static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
__popcntq(unsigned long long __A)
{
return __builtin_popcountll(__A);
@@ -169,26 +181,26 @@ __popcntq(unsigned long long __A)
#endif /* __x86_64__ */
#ifdef __x86_64__
static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__readeflags(void)
{
return __builtin_ia32_readeflags_u64();
}
static __inline__ void __attribute__((__always_inline__, __nodebug__))
static __inline__ void __DEFAULT_FN_ATTRS
__writeeflags(unsigned long long __f)
{
__builtin_ia32_writeeflags_u64(__f);
}
#else /* !__x86_64__ */
static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned int __DEFAULT_FN_ATTRS
__readeflags(void)
{
return __builtin_ia32_readeflags_u32();
}
static __inline__ void __attribute__((__always_inline__, __nodebug__))
static __inline__ void __DEFAULT_FN_ATTRS
__writeeflags(unsigned int __f)
{
__builtin_ia32_writeeflags_u32(__f);
@@ -205,11 +217,9 @@ __writeeflags(unsigned int __f)
* A 32-bit float value.
* \returns a 32-bit unsigned integer containing the converted value.
*/
static __inline__ unsigned int __attribute__((__always_inline__))
static __inline__ unsigned int __DEFAULT_FN_ATTRS_CAST
_castf32_u32(float __A) {
unsigned int D;
__builtin_memcpy(&D, &__A, sizeof(__A));
return D;
return __builtin_bit_cast(unsigned int, __A);
}
/** Cast a 64-bit float value to a 64-bit unsigned integer value
@@ -222,11 +232,9 @@ _castf32_u32(float __A) {
* A 64-bit float value.
* \returns a 64-bit unsigned integer containing the converted value.
*/
static __inline__ unsigned long long __attribute__((__always_inline__))
static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CAST
_castf64_u64(double __A) {
unsigned long long D;
__builtin_memcpy(&D, &__A, sizeof(__A));
return D;
return __builtin_bit_cast(unsigned long long, __A);
}
/** Cast a 32-bit unsigned integer value to a 32-bit float value
@@ -239,11 +247,9 @@ _castf64_u64(double __A) {
* A 32-bit unsigned integer value.
* \returns a 32-bit float value containing the converted value.
*/
static __inline__ float __attribute__((__always_inline__))
static __inline__ float __DEFAULT_FN_ATTRS_CAST
_castu32_f32(unsigned int __A) {
float D;
__builtin_memcpy(&D, &__A, sizeof(__A));
return D;
return __builtin_bit_cast(float, __A);
}
/** Cast a 64-bit unsigned integer value to a 64-bit float value
@@ -256,11 +262,9 @@ _castu32_f32(unsigned int __A) {
* A 64-bit unsigned integer value.
* \returns a 64-bit float value containing the converted value.
*/
static __inline__ double __attribute__((__always_inline__))
static __inline__ double __DEFAULT_FN_ATTRS_CAST
_castu64_f64(unsigned long long __A) {
double D;
__builtin_memcpy(&D, &__A, sizeof(__A));
return D;
return __builtin_bit_cast(double, __A);
}
/** Adds the unsigned integer operand to the CRC-32C checksum of the
@@ -278,7 +282,7 @@ _castu64_f64(unsigned long long __A) {
* \returns The result of adding operand \a __C to the CRC-32C checksum of
* operand \a __D.
*/
static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
static __inline__ unsigned int __DEFAULT_FN_ATTRS_SSE42
__crc32b(unsigned int __C, unsigned char __D)
{
return __builtin_ia32_crc32qi(__C, __D);
@@ -299,7 +303,7 @@ __crc32b(unsigned int __C, unsigned char __D)
* \returns The result of adding operand \a __C to the CRC-32C checksum of
* operand \a __D.
*/
static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
static __inline__ unsigned int __DEFAULT_FN_ATTRS_SSE42
__crc32w(unsigned int __C, unsigned short __D)
{
return __builtin_ia32_crc32hi(__C, __D);
@@ -320,7 +324,7 @@ __crc32w(unsigned int __C, unsigned short __D)
* \returns The result of adding operand \a __C to the CRC-32C checksum of
* operand \a __D.
*/
static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
static __inline__ unsigned int __DEFAULT_FN_ATTRS_SSE42
__crc32d(unsigned int __C, unsigned int __D)
{
return __builtin_ia32_crc32si(__C, __D);
@@ -342,20 +346,20 @@ __crc32d(unsigned int __C, unsigned int __D)
* \returns The result of adding operand \a __C to the CRC-32C checksum of
* operand \a __D.
*/
static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__, __target__("sse4.2")))
static __inline__ unsigned long long __DEFAULT_FN_ATTRS_SSE42
__crc32q(unsigned long long __C, unsigned long long __D)
{
return __builtin_ia32_crc32di(__C, __D);
}
#endif /* __x86_64__ */
static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__rdpmc(int __A) {
return __builtin_ia32_rdpmc(__A);
}
/* __rdtscp */
static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned long long __DEFAULT_FN_ATTRS
__rdtscp(unsigned int *__A) {
return __builtin_ia32_rdtscp(__A);
}
@@ -364,48 +368,48 @@ __rdtscp(unsigned int *__A) {
#define _rdpmc(A) __rdpmc(A)
static __inline__ void __attribute__((__always_inline__, __nodebug__))
static __inline__ void __DEFAULT_FN_ATTRS
_wbinvd(void) {
__builtin_ia32_wbinvd();
}
static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
__rolb(unsigned char __X, int __C) {
return __builtin_rotateleft8(__X, __C);
}
static __inline__ unsigned char __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned char __DEFAULT_FN_ATTRS_CONSTEXPR
__rorb(unsigned char __X, int __C) {
return __builtin_rotateright8(__X, __C);
}
static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned short __DEFAULT_FN_ATTRS_CONSTEXPR
__rolw(unsigned short __X, int __C) {
return __builtin_rotateleft16(__X, __C);
}
static __inline__ unsigned short __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned short __DEFAULT_FN_ATTRS_CONSTEXPR
__rorw(unsigned short __X, int __C) {
return __builtin_rotateright16(__X, __C);
}
static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
__rold(unsigned int __X, int __C) {
return __builtin_rotateleft32(__X, __C);
}
static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned int __DEFAULT_FN_ATTRS_CONSTEXPR
__rord(unsigned int __X, int __C) {
return __builtin_rotateright32(__X, __C);
}
#ifdef __x86_64__
static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CONSTEXPR
__rolq(unsigned long long __X, int __C) {
return __builtin_rotateleft64(__X, __C);
}
static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
static __inline__ unsigned long long __DEFAULT_FN_ATTRS_CONSTEXPR
__rorq(unsigned long long __X, int __C) {
return __builtin_rotateright64(__X, __C);
}
@@ -429,4 +433,9 @@ __rorq(unsigned long long __X, int __C) {
#define _rotwl(a,b) __rolw((a), (b))
#define _rotwr(a,b) __rorw((a), (b))
#undef __DEFAULT_FN_ATTRS
#undef __DEFAULT_FN_ATTRS_CAST
#undef __DEFAULT_FN_ATTRS_SSE42
#undef __DEFAULT_FN_ATTRS_CONSTEXPR
#endif /* __IA32INTRIN_H */

View File

@@ -10,6 +10,8 @@
#ifndef __IMMINTRIN_H
#define __IMMINTRIN_H
#include <x86gprintrin.h>
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
defined(__MMX__)
#include <mmintrin.h>
@@ -143,6 +145,11 @@
#include <avx512vlvnniintrin.h>
#endif
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
defined(__AVXVNNI__)
#include <avxvnniintrin.h>
#endif
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
defined(__AVX512DQ__)
#include <avx512dqintrin.h>
@@ -471,6 +478,11 @@ _storebe_i64(void * __P, long long __D) {
#include <invpcidintrin.h>
#endif
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
defined(__KL__) || defined(__WIDEKL__)
#include <keylockerintrin.h>
#endif
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
defined(__AMXTILE__) || defined(__AMXINT8__) || defined(__AMXBF16__)
#include <amxintrin.h>

173
lib/include/intrin.h vendored
View File

@@ -57,16 +57,11 @@ void __addfsbyte(unsigned long, unsigned char);
void __addfsdword(unsigned long, unsigned long);
void __addfsword(unsigned long, unsigned short);
void __code_seg(const char *);
static __inline__
void __cpuid(int[4], int);
static __inline__
void __cpuidex(int[4], int, int);
static __inline__
__int64 __emul(int, int);
static __inline__
unsigned __int64 __emulu(unsigned int, unsigned int);
unsigned int __getcallerseflags(void);
static __inline__
void __halt(void);
unsigned char __inbyte(unsigned short);
void __inbytestring(unsigned short, unsigned char *, unsigned long);
@@ -82,13 +77,9 @@ void __inwordstring(unsigned short, unsigned short *, unsigned long);
void __lidt(void *);
unsigned __int64 __ll_lshift(unsigned __int64, int);
__int64 __ll_rshift(__int64, int);
static __inline__
void __movsb(unsigned char *, unsigned char const *, size_t);
static __inline__
void __movsd(unsigned long *, unsigned long const *, size_t);
static __inline__
void __movsw(unsigned short *, unsigned short const *, size_t);
static __inline__
void __nop(void);
void __nvreg_restore_fence(void);
void __nvreg_save_fence(void);
@@ -105,23 +96,16 @@ unsigned long __readcr4(void);
unsigned long __readcr8(void);
unsigned int __readdr(unsigned int);
#ifdef __i386__
static __inline__
unsigned char __readfsbyte(unsigned long);
static __inline__
unsigned __int64 __readfsqword(unsigned long);
static __inline__
unsigned short __readfsword(unsigned long);
#endif
static __inline__
unsigned __int64 __readmsr(unsigned long);
unsigned __int64 __readpmc(unsigned long);
unsigned long __segmentlimit(unsigned long);
void __sidt(void *);
static __inline__
void __stosb(unsigned char *, unsigned char, size_t);
static __inline__
void __stosd(unsigned long *, unsigned long, size_t);
static __inline__
void __stosw(unsigned short *, unsigned short, size_t);
void __svm_clgi(void);
void __svm_invlpga(void *, int);
@@ -136,7 +120,6 @@ void __vmx_off(void);
void __vmx_vmptrst(unsigned __int64 *);
void __wbinvd(void);
void __writecr0(unsigned int);
static __inline__
void __writecr3(unsigned __INTPTR_TYPE__);
void __writecr4(unsigned int);
void __writecr8(unsigned int);
@@ -146,11 +129,8 @@ void __writefsdword(unsigned long, unsigned long);
void __writefsqword(unsigned long, unsigned __int64);
void __writefsword(unsigned long, unsigned short);
void __writemsr(unsigned long, unsigned __int64);
static __inline__
void *_AddressOfReturnAddress(void);
static __inline__
unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask);
static __inline__
unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask);
unsigned char _bittest(long const *, long);
unsigned char _bittestandcomplement(long *, long);
@@ -169,12 +149,10 @@ long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long);
long _InterlockedExchangeAdd_HLERelease(long volatile *, long);
__int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64);
__int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64);
static __inline__ void
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
_ReadBarrier(void);
static __inline__ void
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
_ReadWriteBarrier(void);
void __attribute__((__deprecated__(
"use other intrinsics or C++11 atomics instead"))) _ReadBarrier(void);
void __attribute__((__deprecated__(
"use other intrinsics or C++11 atomics instead"))) _ReadWriteBarrier(void);
unsigned int _rorx_u32(unsigned int, const unsigned int);
int _sarx_i32(int, unsigned int);
#if __STDC_HOSTED__
@@ -185,9 +163,8 @@ unsigned int _shrx_u32(unsigned int, unsigned int);
void _Store_HLERelease(long volatile *, long);
void _Store64_HLERelease(__int64 volatile *, __int64);
void _StorePointer_HLERelease(void *volatile *, void *);
static __inline__ void
__attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
_WriteBarrier(void);
void __attribute__((__deprecated__(
"use other intrinsics or C++11 atomics instead"))) _WriteBarrier(void);
unsigned __int32 xbegin(void);
void _xend(void);
@@ -197,19 +174,14 @@ void __addgsbyte(unsigned long, unsigned char);
void __addgsdword(unsigned long, unsigned long);
void __addgsqword(unsigned long, unsigned __int64);
void __addgsword(unsigned long, unsigned short);
static __inline__
void __faststorefence(void);
void __incgsbyte(unsigned long);
void __incgsdword(unsigned long);
void __incgsqword(unsigned long);
void __incgsword(unsigned long);
static __inline__
void __movsq(unsigned long long *, unsigned long long const *, size_t);
static __inline__
unsigned char __readgsbyte(unsigned long);
static __inline__
unsigned long __readgsdword(unsigned long);
static __inline__
unsigned __int64 __readgsqword(unsigned long);
unsigned short __readgsword(unsigned long);
unsigned __int64 __shiftleft128(unsigned __int64 _LowPart,
@@ -218,7 +190,6 @@ unsigned __int64 __shiftleft128(unsigned __int64 _LowPart,
unsigned __int64 __shiftright128(unsigned __int64 _LowPart,
unsigned __int64 _HighPart,
unsigned char _Shift);
static __inline__
void __stosq(unsigned __int64 *, unsigned __int64, size_t);
unsigned char __vmx_on(unsigned __int64 *);
unsigned char __vmx_vmclear(unsigned __int64 *);
@@ -243,10 +214,6 @@ unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange,
long _Comparand);
unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination,
__int64 _ExchangeHigh,
__int64 _ExchangeLow,
__int64 *_CompareandResult);
unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
__int64 _ExchangeHigh,
__int64 _ExchangeLow,
@@ -269,13 +236,9 @@ unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
__int64 _sarx_i64(__int64, unsigned int);
unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
static __inline__
__int64 __mulh(__int64, __int64);
static __inline__
unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
static __inline__
__int64 _mul128(__int64, __int64, __int64*);
static __inline__
unsigned __int64 _umul128(unsigned __int64,
unsigned __int64,
unsigned __int64*);
@@ -284,29 +247,19 @@ unsigned __int64 _umul128(unsigned __int64,
#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
static __inline__
unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask);
static __inline__
unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
#endif
#if defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
static __inline__
__int64 _InterlockedDecrement64(__int64 volatile *_Addend);
static __inline__
__int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value);
static __inline__
__int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value);
static __inline__
__int64 _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value);
static __inline__
__int64 _InterlockedIncrement64(__int64 volatile *_Addend);
static __inline__
__int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask);
static __inline__
__int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask);
static __inline__
__int64 _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask);
#endif
@@ -470,45 +423,81 @@ __int64 _InterlockedCompareExchange64_nf(__int64 volatile *_Destination,
__int64 _InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
__int64 _Exchange, __int64 _Comparand);
#endif
#if defined(__x86_64__) || defined(__aarch64__)
unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination,
__int64 _ExchangeHigh,
__int64 _ExchangeLow,
__int64 *_ComparandResult);
#endif
#if defined(__aarch64__)
unsigned char _InterlockedCompareExchange128_acq(__int64 volatile *_Destination,
__int64 _ExchangeHigh,
__int64 _ExchangeLow,
__int64 *_ComparandResult);
unsigned char _InterlockedCompareExchange128_nf(__int64 volatile *_Destination,
__int64 _ExchangeHigh,
__int64 _ExchangeLow,
__int64 *_ComparandResult);
unsigned char _InterlockedCompareExchange128_rel(__int64 volatile *_Destination,
__int64 _ExchangeHigh,
__int64 _ExchangeLow,
__int64 *_ComparandResult);
#endif
/*----------------------------------------------------------------------------*\
|* movs, stos
\*----------------------------------------------------------------------------*/
#if defined(__i386__) || defined(__x86_64__)
static __inline__ void __DEFAULT_FN_ATTRS
__movsb(unsigned char *__dst, unsigned char const *__src, size_t __n) {
static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
unsigned char const *__src,
size_t __n) {
__asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
: : "memory");
}
static __inline__ void __DEFAULT_FN_ATTRS
__movsd(unsigned long *__dst, unsigned long const *__src, size_t __n) {
__asm__ __volatile__("rep movsl" : "+D"(__dst), "+S"(__src), "+c"(__n)
: : "memory");
}
static __inline__ void __DEFAULT_FN_ATTRS
__movsw(unsigned short *__dst, unsigned short const *__src, size_t __n) {
__asm__ __volatile__("rep movsw" : "+D"(__dst), "+S"(__src), "+c"(__n)
: : "memory");
}
static __inline__ void __DEFAULT_FN_ATTRS
__stosd(unsigned long *__dst, unsigned long __x, size_t __n) {
__asm__ __volatile__("rep stosl" : "+D"(__dst), "+c"(__n) : "a"(__x)
static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
unsigned long const *__src,
size_t __n) {
__asm__ __volatile__("rep movsl"
: "+D"(__dst), "+S"(__src), "+c"(__n)
:
: "memory");
}
static __inline__ void __DEFAULT_FN_ATTRS
__stosw(unsigned short *__dst, unsigned short __x, size_t __n) {
__asm__ __volatile__("rep stosw" : "+D"(__dst), "+c"(__n) : "a"(__x)
static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
unsigned short const *__src,
size_t __n) {
__asm__ __volatile__("rep movsw"
: "+D"(__dst), "+S"(__src), "+c"(__n)
:
: "memory");
}
static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
unsigned long __x,
size_t __n) {
__asm__ __volatile__("rep stosl"
: "+D"(__dst), "+c"(__n)
: "a"(__x)
: "memory");
}
static __inline__ void __DEFAULT_FN_ATTRS __stosw(unsigned short *__dst,
unsigned short __x,
size_t __n) {
__asm__ __volatile__("rep stosw"
: "+D"(__dst), "+c"(__n)
: "a"(__x)
: "memory");
}
#endif
#ifdef __x86_64__
static __inline__ void __DEFAULT_FN_ATTRS
__movsq(unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
__asm__ __volatile__("rep movsq" : "+D"(__dst), "+S"(__src), "+c"(__n)
: : "memory");
static __inline__ void __DEFAULT_FN_ATTRS __movsq(
unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
__asm__ __volatile__("rep movsq"
: "+D"(__dst), "+S"(__src), "+c"(__n)
:
: "memory");
}
static __inline__ void __DEFAULT_FN_ATTRS
__stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) {
static __inline__ void __DEFAULT_FN_ATTRS __stosq(unsigned __int64 *__dst,
unsigned __int64 __x,
size_t __n) {
__asm__ __volatile__("rep stosq" : "+D"(__dst), "+c"(__n) : "a"(__x)
: "memory");
}
@@ -518,26 +507,25 @@ __stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) {
|* Misc
\*----------------------------------------------------------------------------*/
#if defined(__i386__) || defined(__x86_64__)
static __inline__ void __DEFAULT_FN_ATTRS
__cpuid(int __info[4], int __level) {
__asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
: "a"(__level), "c"(0));
static __inline__ void __DEFAULT_FN_ATTRS __cpuid(int __info[4], int __level) {
__asm__("cpuid"
: "=a"(__info[0]), "=b"(__info[1]), "=c"(__info[2]), "=d"(__info[3])
: "a"(__level), "c"(0));
}
static __inline__ void __DEFAULT_FN_ATTRS
__cpuidex(int __info[4], int __level, int __ecx) {
__asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
: "a"(__level), "c"(__ecx));
static __inline__ void __DEFAULT_FN_ATTRS __cpuidex(int __info[4], int __level,
int __ecx) {
__asm__("cpuid"
: "=a"(__info[0]), "=b"(__info[1]), "=c"(__info[2]), "=d"(__info[3])
: "a"(__level), "c"(__ecx));
}
static __inline__ void __DEFAULT_FN_ATTRS
__halt(void) {
__asm__ volatile ("hlt");
static __inline__ void __DEFAULT_FN_ATTRS __halt(void) {
__asm__ volatile("hlt");
}
#endif
#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
static __inline__ void __DEFAULT_FN_ATTRS
__nop(void) {
__asm__ volatile ("nop");
static __inline__ void __DEFAULT_FN_ATTRS __nop(void) {
__asm__ volatile("nop");
}
#endif
@@ -574,8 +562,7 @@ __readmsr(unsigned long __register) {
}
#endif
static __inline__ unsigned __LPTRINT_TYPE__ __DEFAULT_FN_ATTRS
__readcr3(void) {
static __inline__ unsigned __LPTRINT_TYPE__ __DEFAULT_FN_ATTRS __readcr3(void) {
unsigned __LPTRINT_TYPE__ __cr3_val;
__asm__ __volatile__ ("mov %%cr3, %0" : "=r"(__cr3_val) : : "memory");
return __cr3_val;

506
lib/include/keylockerintrin.h vendored Normal file
View File

@@ -0,0 +1,506 @@
/*===----------------- keylockerintrin.h - KL Intrinsics -------------------===
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*===-----------------------------------------------------------------------===
*/
#ifndef __IMMINTRIN_H
#error "Never use <keylockerintrin.h> directly; include <immintrin.h> instead."
#endif
#ifndef _KEYLOCKERINTRIN_H
#define _KEYLOCKERINTRIN_H
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
defined(__KL__)
/* Define the default attributes for the functions in this file. */
#define __DEFAULT_FN_ATTRS \
__attribute__((__always_inline__, __nodebug__, __target__("kl"),\
__min_vector_width__(128)))
/// Load internal wrapping key from __intkey, __enkey_lo and __enkey_hi. __ctl
/// will assigned to EAX, whch specifies the KeySource and whether backing up
/// the key is permitted. The 256-bit encryption key is loaded from the two
/// explicit operands (__enkey_lo and __enkey_hi). The 128-bit integrity key is
/// loaded from the implicit operand XMM0 which assigned by __intkey.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> LOADIWKEY </c> instructions.
///
/// \operation
/// IF CPL > 0 // LOADKWKEY only allowed at ring 0 (supervisor mode)
/// GP (0)
/// FI
/// IF “LOADIWKEY exiting” VM execution control set
/// VMexit
/// FI
/// IF __ctl[4:1] > 1 // Reserved KeySource encoding used
/// GP (0)
/// FI
/// IF __ctl[31:5] != 0 // Reserved bit in __ctl is set
/// GP (0)
/// FI
/// IF __ctl[0] AND (CPUID.19H.ECX[0] == 0) // NoBackup is not supported on this part
/// GP (0)
/// FI
/// IF (__ctl[4:1] == 1) AND (CPUID.19H.ECX[1] == 0) // KeySource of 1 is not supported on this part
/// GP (0)
/// FI
/// IF (__ctl[4:1] == 0) // KeySource of 0.
/// IWKey.Encryption Key[127:0] := __enkey_hi[127:0]:
/// IWKey.Encryption Key[255:128] := __enkey_lo[127:0]
/// IWKey.IntegrityKey[127:0] := __intkey[127:0]
/// IWKey.NoBackup := __ctl[0]
/// IWKey.KeySource := __ctl[4:1]
/// ZF := 0
/// ELSE // KeySource of 1. See RDSEED definition for details of randomness
/// IF HW_NRND_GEN.ready == 1 // Full-entropy random data from RDSEED was received
/// IWKey.Encryption Key[127:0] := __enkey_hi[127:0] XOR HW_NRND_GEN.data[127:0]
/// IWKey.Encryption Key[255:128] := __enkey_lo[127:0] XOR HW_NRND_GEN.data[255:128]
/// IWKey.Encryption Key[255:0] := __enkey_hi[127:0]:__enkey_lo[127:0] XOR HW_NRND_GEN.data[255:0]
/// IWKey.IntegrityKey[127:0] := __intkey[127:0] XOR HW_NRND_GEN.data[383:256]
/// IWKey.NoBackup := __ctl[0]
/// IWKey.KeySource := __ctl[4:1]
/// ZF := 0
/// ELSE // Random data was not returned from RDSEED. IWKey was not loaded
/// ZF := 1
/// FI
/// FI
/// dst := ZF
/// OF := 0
/// SF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ void __DEFAULT_FN_ATTRS
_mm_loadiwkey (unsigned int __ctl, __m128i __intkey,
__m128i __enkey_lo, __m128i __enkey_hi) {
__builtin_ia32_loadiwkey (__intkey, __enkey_lo, __enkey_hi, __ctl);
}
/// Wrap a 128-bit AES key from __key into a key handle and output in
/// ((__m128i*)__h) to ((__m128i*)__h) + 5 and a 32-bit value as return.
/// The explicit source operand __htype specifies handle restrictions.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> ENCODEKEY128 </c> instructions.
///
/// \operation
/// InputKey[127:0] := __key[127:0]
/// KeyMetadata[2:0] := __htype[2:0]
/// KeyMetadata[23:3] := 0 // Reserved for future usage
/// KeyMetadata[27:24] := 0 // KeyType is AES-128 (value of 0)
/// KeyMetadata[127:28] := 0 // Reserved for future usage
/// Handle[383:0] := WrapKey128(InputKey[127:0], KeyMetadata[127:0],
/// IWKey.Integrity Key[127:0], IWKey.Encryption Key[255:0])
/// dst[0] := IWKey.NoBackup
/// dst[4:1] := IWKey.KeySource[3:0]
/// dst[31:5] := 0
/// MEM[__h+127:__h] := Handle[127:0] // AAD
/// MEM[__h+255:__h+128] := Handle[255:128] // Integrity Tag
/// MEM[__h+383:__h+256] := Handle[383:256] // CipherText
/// MEM[__h+511:__h+384] := 0 // Reserved for future usage
/// MEM[__h+639:__h+512] := 0 // Reserved for future usage
/// MEM[__h+767:__h+640] := 0 // Reserved for future usage
/// OF := 0
/// SF := 0
/// ZF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ unsigned int __DEFAULT_FN_ATTRS
_mm_encodekey128_u32(unsigned int __htype, __m128i __key, void *__h) {
return __builtin_ia32_encodekey128_u32(__htype, (__v2di)__key, __h);
}
/// Wrap a 256-bit AES key from __key_hi:__key_lo into a key handle, then
/// output handle in ((__m128i*)__h) to ((__m128i*)__h) + 6 and
/// a 32-bit value as return.
/// The explicit source operand __htype specifies handle restrictions.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> ENCODEKEY256 </c> instructions.
///
/// \operation
/// InputKey[127:0] := __key_lo[127:0]
/// InputKey[255:128] := __key_hi[255:128]
/// KeyMetadata[2:0] := __htype[2:0]
/// KeyMetadata[23:3] := 0 // Reserved for future usage
/// KeyMetadata[27:24] := 1 // KeyType is AES-256 (value of 1)
/// KeyMetadata[127:28] := 0 // Reserved for future usage
/// Handle[511:0] := WrapKey256(InputKey[255:0], KeyMetadata[127:0],
/// IWKey.Integrity Key[127:0], IWKey.Encryption Key[255:0])
/// dst[0] := IWKey.NoBackup
/// dst[4:1] := IWKey.KeySource[3:0]
/// dst[31:5] := 0
/// MEM[__h+127:__h] := Handle[127:0] // AAD
/// MEM[__h+255:__h+128] := Handle[255:128] // Tag
/// MEM[__h+383:__h+256] := Handle[383:256] // CipherText[127:0]
/// MEM[__h+511:__h+384] := Handle[511:384] // CipherText[255:128]
/// MEM[__h+639:__h+512] := 0 // Reserved for future usage
/// MEM[__h+767:__h+640] := 0 // Reserved for future usage
/// MEM[__h+895:__h+768] := 0 Integrity// Reserved for future usage
/// OF := 0
/// SF := 0
/// ZF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ unsigned int __DEFAULT_FN_ATTRS
_mm_encodekey256_u32(unsigned int __htype, __m128i __key_lo, __m128i __key_hi,
void *__h) {
return __builtin_ia32_encodekey256_u32(__htype, (__v2di)__key_lo,
(__v2di)__key_hi, __h);
}
/// The AESENC128KL performs 10 rounds of AES to encrypt the __idata using
/// the 128-bit key in the handle from the __h. It stores the result in the
/// __odata. And return the affected ZF flag status.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> AESENC128KL </c> instructions.
///
/// \operation
/// Handle[383:0] := MEM[__h+383:__h] // Load is not guaranteed to be atomic.
/// IllegalHandle := ( HandleReservedBitSet (Handle[383:0]) ||
/// (Handle[127:0] AND (CPL > 0)) ||
/// Handle[383:256] ||
/// HandleKeyType (Handle[383:0]) != HANDLE_KEY_TYPE_AES128 )
/// IF (IllegalHandle)
/// ZF := 1
/// ELSE
/// (UnwrappedKey, Authentic) := UnwrapKeyAndAuthenticate384 (Handle[383:0], IWKey)
/// IF (Authentic == 0)
/// ZF := 1
/// ELSE
/// MEM[__odata+127:__odata] := AES128Encrypt (__idata[127:0], UnwrappedKey)
/// ZF := 0
/// FI
/// FI
/// dst := ZF
/// OF := 0
/// SF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ unsigned char __DEFAULT_FN_ATTRS
_mm_aesenc128kl_u8(__m128i* __odata, __m128i __idata, const void *__h) {
return __builtin_ia32_aesenc128kl_u8((__v2di *)__odata, (__v2di)__idata, __h);
}
/// The AESENC256KL performs 14 rounds of AES to encrypt the __idata using
/// the 256-bit key in the handle from the __h. It stores the result in the
/// __odata. And return the affected ZF flag status.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> AESENC256KL </c> instructions.
///
/// \operation
/// Handle[511:0] := MEM[__h+511:__h] // Load is not guaranteed to be atomic.
/// IllegalHandle := ( HandleReservedBitSet (Handle[511:0]) ||
/// (Handle[127:0] AND (CPL > 0)) ||
/// Handle[255:128] ||
/// HandleKeyType (Handle[511:0]) != HANDLE_KEY_TYPE_AES256 )
/// IF (IllegalHandle)
/// ZF := 1
/// ELSE
/// (UnwrappedKey, Authentic) := UnwrapKeyAndAuthenticate512 (Handle[511:0], IWKey)
/// IF (Authentic == 0)
/// ZF := 1
/// ELSE
/// MEM[__odata+127:__odata] := AES256Encrypt (__idata[127:0], UnwrappedKey)
/// ZF := 0
/// FI
/// FI
/// dst := ZF
/// OF := 0
/// SF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ unsigned char __DEFAULT_FN_ATTRS
_mm_aesenc256kl_u8(__m128i* __odata, __m128i __idata, const void *__h) {
return __builtin_ia32_aesenc256kl_u8((__v2di *)__odata, (__v2di)__idata, __h);
}
/// The AESDEC128KL performs 10 rounds of AES to decrypt the __idata using
/// the 128-bit key in the handle from the __h. It stores the result in the
/// __odata. And return the affected ZF flag status.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> AESDEC128KL </c> instructions.
///
/// \operation
/// Handle[383:0] := MEM[__h+383:__h] // Load is not guaranteed to be atomic.
/// IllegalHandle := (HandleReservedBitSet (Handle[383:0]) ||
/// (Handle[127:0] AND (CPL > 0)) ||
/// Handle[383:256] ||
/// HandleKeyType (Handle[383:0]) != HANDLE_KEY_TYPE_AES128)
/// IF (IllegalHandle)
/// ZF := 1
/// ELSE
/// (UnwrappedKey, Authentic) := UnwrapKeyAndAuthenticate384 (Handle[383:0], IWKey)
/// IF (Authentic == 0)
/// ZF := 1
/// ELSE
/// MEM[__odata+127:__odata] := AES128Decrypt (__idata[127:0], UnwrappedKey)
/// ZF := 0
/// FI
/// FI
/// dst := ZF
/// OF := 0
/// SF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ unsigned char __DEFAULT_FN_ATTRS
_mm_aesdec128kl_u8(__m128i* __odata, __m128i __idata, const void *__h) {
return __builtin_ia32_aesdec128kl_u8((__v2di *)__odata, (__v2di)__idata, __h);
}
/// The AESDEC256KL performs 10 rounds of AES to decrypt the __idata using
/// the 256-bit key in the handle from the __h. It stores the result in the
/// __odata. And return the affected ZF flag status.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> AESDEC256KL </c> instructions.
///
/// \operation
/// Handle[511:0] := MEM[__h+511:__h]
/// IllegalHandle := (HandleReservedBitSet (Handle[511:0]) ||
/// (Handle[127:0] AND (CPL > 0)) ||
/// Handle[383:256] ||
/// HandleKeyType (Handle[511:0]) != HANDLE_KEY_TYPE_AES256)
/// IF (IllegalHandle)
/// ZF := 1
/// ELSE
/// (UnwrappedKey, Authentic) := UnwrapKeyAndAuthenticate512 (Handle[511:0], IWKey)
/// IF (Authentic == 0)
/// ZF := 1
/// ELSE
/// MEM[__odata+127:__odata] := AES256Decrypt (__idata[127:0], UnwrappedKey)
/// ZF := 0
/// FI
/// FI
/// dst := ZF
/// OF := 0
/// SF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ unsigned char __DEFAULT_FN_ATTRS
_mm_aesdec256kl_u8(__m128i* __odata, __m128i __idata, const void *__h) {
return __builtin_ia32_aesdec256kl_u8((__v2di *)__odata, (__v2di)__idata, __h);
}
#undef __DEFAULT_FN_ATTRS
#endif /* !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) \
|| defined(__KL__) */
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
defined(__WIDEKL__)
/* Define the default attributes for the functions in this file. */
#define __DEFAULT_FN_ATTRS \
__attribute__((__always_inline__, __nodebug__, __target__("kl,widekl"),\
__min_vector_width__(128)))
/// Encrypt __idata[0] to __idata[7] using 128-bit AES key indicated by handle
/// at __h and store each resultant block back from __odata to __odata+7. And
/// return the affected ZF flag status.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> AESENCWIDE128KL </c> instructions.
///
/// \operation
/// Handle := MEM[__h+383:__h]
/// IllegalHandle := ( HandleReservedBitSet (Handle[383:0]) ||
/// (Handle[127:0] AND (CPL > 0)) ||
/// Handle[255:128] ||
/// HandleKeyType (Handle[383:0]) != HANDLE_KEY_TYPE_AES128 )
/// IF (IllegalHandle)
/// ZF := 1
/// ELSE
/// (UnwrappedKey, Authentic) := UnwrapKeyAndAuthenticate384 (Handle[383:0], IWKey)
/// IF Authentic == 0
/// ZF := 1
/// ELSE
/// FOR i := 0 to 7
/// __odata[i] := AES128Encrypt (__idata[i], UnwrappedKey)
/// ENDFOR
/// ZF := 0
/// FI
/// FI
/// dst := ZF
/// OF := 0
/// SF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ unsigned char __DEFAULT_FN_ATTRS
_mm_aesencwide128kl_u8(__m128i __odata[8], const __m128i __idata[8], const void* __h) {
return __builtin_ia32_aesencwide128kl_u8((__v2di *)__odata,
(const __v2di *)__idata, __h);
}
/// Encrypt __idata[0] to __idata[7] using 256-bit AES key indicated by handle
/// at __h and store each resultant block back from __odata to __odata+7. And
/// return the affected ZF flag status.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> AESENCWIDE256KL </c> instructions.
///
/// \operation
/// Handle[511:0] := MEM[__h+511:__h]
/// IllegalHandle := ( HandleReservedBitSet (Handle[511:0]) ||
/// (Handle[127:0] AND (CPL > 0)) ||
/// Handle[255:128] ||
/// HandleKeyType (Handle[511:0]) != HANDLE_KEY_TYPE_AES512 )
/// IF (IllegalHandle)
/// ZF := 1
/// ELSE
/// (UnwrappedKey, Authentic) := UnwrapKeyAndAuthenticate512 (Handle[511:0], IWKey)
/// IF Authentic == 0
/// ZF := 1
/// ELSE
/// FOR i := 0 to 7
/// __odata[i] := AES256Encrypt (__idata[i], UnwrappedKey)
/// ENDFOR
/// ZF := 0
/// FI
/// FI
/// dst := ZF
/// OF := 0
/// SF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ unsigned char __DEFAULT_FN_ATTRS
_mm_aesencwide256kl_u8(__m128i __odata[8], const __m128i __idata[8], const void* __h) {
return __builtin_ia32_aesencwide256kl_u8((__v2di *)__odata,
(const __v2di *)__idata, __h);
}
/// Decrypt __idata[0] to __idata[7] using 128-bit AES key indicated by handle
/// at __h and store each resultant block back from __odata to __odata+7. And
/// return the affected ZF flag status.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> AESDECWIDE128KL </c> instructions.
///
/// \operation
/// Handle[383:0] := MEM[__h+383:__h]
/// IllegalHandle := ( HandleReservedBitSet (Handle[383:0]) ||
/// (Handle[127:0] AND (CPL > 0)) ||
/// Handle[255:128] ||
/// HandleKeyType (Handle) != HANDLE_KEY_TYPE_AES128 )
/// IF (IllegalHandle)
/// ZF := 1
/// ELSE
/// (UnwrappedKey, Authentic) := UnwrapKeyAndAuthenticate384 (Handle[383:0], IWKey)
/// IF Authentic == 0
/// ZF := 1
/// ELSE
/// FOR i := 0 to 7
/// __odata[i] := AES128Decrypt (__idata[i], UnwrappedKey)
/// ENDFOR
/// ZF := 0
/// FI
/// FI
/// dst := ZF
/// OF := 0
/// SF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ unsigned char __DEFAULT_FN_ATTRS
_mm_aesdecwide128kl_u8(__m128i __odata[8], const __m128i __idata[8], const void* __h) {
return __builtin_ia32_aesdecwide128kl_u8((__v2di *)__odata,
(const __v2di *)__idata, __h);
}
/// Decrypt __idata[0] to __idata[7] using 256-bit AES key indicated by handle
/// at __h and store each resultant block back from __odata to __odata+7. And
/// return the affected ZF flag status.
///
/// \headerfile <x86intrin.h>
///
/// This intrinsic corresponds to the <c> AESDECWIDE256KL </c> instructions.
///
/// \operation
/// Handle[511:0] := MEM[__h+511:__h]
/// IllegalHandle = ( HandleReservedBitSet (Handle[511:0]) ||
/// (Handle[127:0] AND (CPL > 0)) ||
/// Handle[255:128] ||
/// HandleKeyType (Handle) != HANDLE_KEY_TYPE_AES512 )
/// If (IllegalHandle)
/// ZF := 1
/// ELSE
/// (UnwrappedKey, Authentic) := UnwrapKeyAndAuthenticate512 (Handle[511:0], IWKey)
/// IF Authentic == 0
/// ZF := 1
/// ELSE
/// FOR i := 0 to 7
/// __odata[i] := AES256Decrypt (__idata[i], UnwrappedKey)
/// ENDFOR
/// ZF := 0
/// FI
/// FI
/// dst := ZF
/// OF := 0
/// SF := 0
/// AF := 0
/// PF := 0
/// CF := 0
/// \endoperation
static __inline__ unsigned char __DEFAULT_FN_ATTRS
_mm_aesdecwide256kl_u8(__m128i __odata[8], const __m128i __idata[8], const void* __h) {
return __builtin_ia32_aesdecwide256kl_u8((__v2di *)__odata,
(const __v2di *)__idata, __h);
}
#undef __DEFAULT_FN_ATTRS
#endif /* !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) \
|| defined(__WIDEKL__) */
#endif /* _KEYLOCKERINTRIN_H */

View File

@@ -54,7 +54,13 @@ _mm_malloc(size_t __size, size_t __align)
static __inline__ void __attribute__((__always_inline__, __nodebug__))
_mm_free(void *__p)
{
#if defined(__MINGW32__)
__mingw_aligned_free(__p);
#elif defined(_WIN32)
_aligned_free(__p);
#else
free(__p);
#endif
}
#endif

View File

@@ -9,6 +9,21 @@
#ifndef _OPENCL_BASE_H_
#define _OPENCL_BASE_H_
// Define extension macros
#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
// For SPIR all extensions are supported.
#if defined(__SPIR__)
#define cl_khr_subgroup_extended_types 1
#define cl_khr_subgroup_non_uniform_vote 1
#define cl_khr_subgroup_ballot 1
#define cl_khr_subgroup_non_uniform_arithmetic 1
#define cl_khr_subgroup_shuffle 1
#define cl_khr_subgroup_shuffle_relative 1
#define cl_khr_subgroup_clustered_reduce 1
#endif // defined(__SPIR__)
#endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
// built-in scalar data types:
/**
@@ -568,4 +583,7 @@ typedef struct {
#pragma OPENCL EXTENSION cl_intel_device_side_avc_motion_estimation : end
#endif // cl_intel_device_side_avc_motion_estimation
// Disable any extensions we may have enabled previously.
#pragma OPENCL EXTENSION all : disable
#endif //_OPENCL_BASE_H_

View File

@@ -4633,6 +4633,7 @@ float16 __ovld __cnfn convert_float16(float16);
// Conversions with double data type parameters or return value.
#ifdef cl_khr_fp64
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
char __ovld __cnfn convert_char(double);
char __ovld __cnfn convert_char_rte(double);
char __ovld __cnfn convert_char_rtn(double);
@@ -5455,6 +5456,7 @@ double16 __ovld __cnfn convert_double16_rtz(ushort16);
#endif //cl_khr_fp64
#ifdef cl_khr_fp16
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
// Convert half types to non-double types.
uchar __ovld __cnfn convert_uchar(half);
uchar __ovld __cnfn convert_uchar_rte(half);

View File

@@ -24,8 +24,11 @@
// which might live in cstdlib.
#include <cstdlib>
// We need limits because __clang_cuda_cmath.h below uses `std::numeric_limit`.
#include <limits>
#pragma omp begin declare variant match( \
device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any)})
device = {arch(nvptx, nvptx64)}, implementation = {extension(match_any, allow_templates)})
#define __CUDA__
#define __OPENMP_NVPTX__

View File

@@ -18,8 +18,35 @@
#include <cmath>
#define __CUDA__
#define __OPENMP_NVPTX__
#include <__clang_cuda_complex_builtins.h>
#undef __OPENMP_NVPTX__
#endif
// Grab the host header too.
#include_next <complex>
#ifdef __cplusplus
// If we are compiling against libc++, the macro _LIBCPP_STD_VER should be set
// after including <cmath> above. Since the complex header we use is a
// simplified version of the libc++, we don't need it in this case. If we
// compile against libstdc++, or any other standard library, we will overload
// the (hopefully template) functions in the <complex> header with the ones we
// got from libc++ which decomposes math functions, like `std::sin`, into
// arithmetic and calls to non-complex functions, all of which we can then
// handle.
#ifndef _LIBCPP_STD_VER
#pragma omp begin declare variant match( \
device = {arch(nvptx, nvptx64)}, \
implementation = {extension(match_any, allow_templates)})
#include <complex_cmath.h>
#pragma omp end declare variant
#endif
#endif

View File

@@ -18,7 +18,9 @@
#include <math.h>
#define __CUDA__
#define __OPENMP_NVPTX__
#include <__clang_cuda_complex_builtins.h>
#undef __OPENMP_NVPTX__
#endif
// Grab the host header too.

View File

@@ -0,0 +1,388 @@
//===------------------------- __complex_cmath.h --------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// std::complex header copied from the libcxx source and simplified for use in
// OpenMP target offload regions.
//
//===----------------------------------------------------------------------===//
#ifndef _OPENMP
#error "This file is for OpenMP compilation only."
#endif
#ifndef __cplusplus
#error "This file is for C++ compilation only."
#endif
#ifndef _LIBCPP_COMPLEX
#define _LIBCPP_COMPLEX
#include <cmath>
#include <type_traits>
#define __DEVICE__ static constexpr __attribute__((nothrow))
namespace std {
// abs
template <class _Tp> __DEVICE__ _Tp abs(const std::complex<_Tp> &__c) {
return hypot(__c.real(), __c.imag());
}
// arg
template <class _Tp> __DEVICE__ _Tp arg(const std::complex<_Tp> &__c) {
return atan2(__c.imag(), __c.real());
}
template <class _Tp>
typename enable_if<is_integral<_Tp>::value || is_same<_Tp, double>::value,
double>::type
arg(_Tp __re) {
return atan2(0., __re);
}
template <class _Tp>
typename enable_if<is_same<_Tp, float>::value, float>::type arg(_Tp __re) {
return atan2f(0.F, __re);
}
// norm
template <class _Tp> __DEVICE__ _Tp norm(const std::complex<_Tp> &__c) {
if (std::isinf(__c.real()))
return abs(__c.real());
if (std::isinf(__c.imag()))
return abs(__c.imag());
return __c.real() * __c.real() + __c.imag() * __c.imag();
}
// conj
template <class _Tp> std::complex<_Tp> conj(const std::complex<_Tp> &__c) {
return std::complex<_Tp>(__c.real(), -__c.imag());
}
// proj
template <class _Tp> std::complex<_Tp> proj(const std::complex<_Tp> &__c) {
std::complex<_Tp> __r = __c;
if (std::isinf(__c.real()) || std::isinf(__c.imag()))
__r = std::complex<_Tp>(INFINITY, copysign(_Tp(0), __c.imag()));
return __r;
}
// polar
template <class _Tp>
complex<_Tp> polar(const _Tp &__rho, const _Tp &__theta = _Tp()) {
if (std::isnan(__rho) || signbit(__rho))
return std::complex<_Tp>(_Tp(NAN), _Tp(NAN));
if (std::isnan(__theta)) {
if (std::isinf(__rho))
return std::complex<_Tp>(__rho, __theta);
return std::complex<_Tp>(__theta, __theta);
}
if (std::isinf(__theta)) {
if (std::isinf(__rho))
return std::complex<_Tp>(__rho, _Tp(NAN));
return std::complex<_Tp>(_Tp(NAN), _Tp(NAN));
}
_Tp __x = __rho * cos(__theta);
if (std::isnan(__x))
__x = 0;
_Tp __y = __rho * sin(__theta);
if (std::isnan(__y))
__y = 0;
return std::complex<_Tp>(__x, __y);
}
// log
template <class _Tp> std::complex<_Tp> log(const std::complex<_Tp> &__x) {
return std::complex<_Tp>(log(abs(__x)), arg(__x));
}
// log10
template <class _Tp> std::complex<_Tp> log10(const std::complex<_Tp> &__x) {
return log(__x) / log(_Tp(10));
}
// sqrt
template <class _Tp>
__DEVICE__ std::complex<_Tp> sqrt(const std::complex<_Tp> &__x) {
if (std::isinf(__x.imag()))
return std::complex<_Tp>(_Tp(INFINITY), __x.imag());
if (std::isinf(__x.real())) {
if (__x.real() > _Tp(0))
return std::complex<_Tp>(__x.real(), std::isnan(__x.imag())
? __x.imag()
: copysign(_Tp(0), __x.imag()));
return std::complex<_Tp>(std::isnan(__x.imag()) ? __x.imag() : _Tp(0),
copysign(__x.real(), __x.imag()));
}
return polar(sqrt(abs(__x)), arg(__x) / _Tp(2));
}
// exp
template <class _Tp>
__DEVICE__ std::complex<_Tp> exp(const std::complex<_Tp> &__x) {
_Tp __i = __x.imag();
if (std::isinf(__x.real())) {
if (__x.real() < _Tp(0)) {
if (!std::isfinite(__i))
__i = _Tp(1);
} else if (__i == 0 || !std::isfinite(__i)) {
if (std::isinf(__i))
__i = _Tp(NAN);
return std::complex<_Tp>(__x.real(), __i);
}
} else if (std::isnan(__x.real()) && __x.imag() == 0)
return __x;
_Tp __e = exp(__x.real());
return std::complex<_Tp>(__e * cos(__i), __e * sin(__i));
}
// pow
template <class _Tp>
std::complex<_Tp> pow(const std::complex<_Tp> &__x,
const std::complex<_Tp> &__y) {
return exp(__y * log(__x));
}
// __sqr, computes pow(x, 2)
template <class _Tp> std::complex<_Tp> __sqr(const std::complex<_Tp> &__x) {
return std::complex<_Tp>((__x.real() - __x.imag()) *
(__x.real() + __x.imag()),
_Tp(2) * __x.real() * __x.imag());
}
// asinh
template <class _Tp>
__DEVICE__ std::complex<_Tp> asinh(const std::complex<_Tp> &__x) {
const _Tp __pi(atan2(+0., -0.));
if (std::isinf(__x.real())) {
if (std::isnan(__x.imag()))
return __x;
if (std::isinf(__x.imag()))
return std::complex<_Tp>(__x.real(),
copysign(__pi * _Tp(0.25), __x.imag()));
return std::complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag()));
}
if (std::isnan(__x.real())) {
if (std::isinf(__x.imag()))
return std::complex<_Tp>(__x.imag(), __x.real());
if (__x.imag() == 0)
return __x;
return std::complex<_Tp>(__x.real(), __x.real());
}
if (std::isinf(__x.imag()))
return std::complex<_Tp>(copysign(__x.imag(), __x.real()),
copysign(__pi / _Tp(2), __x.imag()));
std::complex<_Tp> __z = log(__x + sqrt(__sqr(__x) + _Tp(1)));
return std::complex<_Tp>(copysign(__z.real(), __x.real()),
copysign(__z.imag(), __x.imag()));
}
// acosh
template <class _Tp>
__DEVICE__ std::complex<_Tp> acosh(const std::complex<_Tp> &__x) {
const _Tp __pi(atan2(+0., -0.));
if (std::isinf(__x.real())) {
if (std::isnan(__x.imag()))
return std::complex<_Tp>(abs(__x.real()), __x.imag());
if (std::isinf(__x.imag())) {
if (__x.real() > 0)
return std::complex<_Tp>(__x.real(),
copysign(__pi * _Tp(0.25), __x.imag()));
else
return std::complex<_Tp>(-__x.real(),
copysign(__pi * _Tp(0.75), __x.imag()));
}
if (__x.real() < 0)
return std::complex<_Tp>(-__x.real(), copysign(__pi, __x.imag()));
return std::complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag()));
}
if (std::isnan(__x.real())) {
if (std::isinf(__x.imag()))
return std::complex<_Tp>(abs(__x.imag()), __x.real());
return std::complex<_Tp>(__x.real(), __x.real());
}
if (std::isinf(__x.imag()))
return std::complex<_Tp>(abs(__x.imag()),
copysign(__pi / _Tp(2), __x.imag()));
std::complex<_Tp> __z = log(__x + sqrt(__sqr(__x) - _Tp(1)));
return std::complex<_Tp>(copysign(__z.real(), _Tp(0)),
copysign(__z.imag(), __x.imag()));
}
// atanh
template <class _Tp>
__DEVICE__ std::complex<_Tp> atanh(const std::complex<_Tp> &__x) {
const _Tp __pi(atan2(+0., -0.));
if (std::isinf(__x.imag())) {
return std::complex<_Tp>(copysign(_Tp(0), __x.real()),
copysign(__pi / _Tp(2), __x.imag()));
}
if (std::isnan(__x.imag())) {
if (std::isinf(__x.real()) || __x.real() == 0)
return std::complex<_Tp>(copysign(_Tp(0), __x.real()), __x.imag());
return std::complex<_Tp>(__x.imag(), __x.imag());
}
if (std::isnan(__x.real())) {
return std::complex<_Tp>(__x.real(), __x.real());
}
if (std::isinf(__x.real())) {
return std::complex<_Tp>(copysign(_Tp(0), __x.real()),
copysign(__pi / _Tp(2), __x.imag()));
}
if (abs(__x.real()) == _Tp(1) && __x.imag() == _Tp(0)) {
return std::complex<_Tp>(copysign(_Tp(INFINITY), __x.real()),
copysign(_Tp(0), __x.imag()));
}
std::complex<_Tp> __z = log((_Tp(1) + __x) / (_Tp(1) - __x)) / _Tp(2);
return std::complex<_Tp>(copysign(__z.real(), __x.real()),
copysign(__z.imag(), __x.imag()));
}
// sinh
template <class _Tp>
__DEVICE__ std::complex<_Tp> sinh(const std::complex<_Tp> &__x) {
if (std::isinf(__x.real()) && !std::isfinite(__x.imag()))
return std::complex<_Tp>(__x.real(), _Tp(NAN));
if (__x.real() == 0 && !std::isfinite(__x.imag()))
return std::complex<_Tp>(__x.real(), _Tp(NAN));
if (__x.imag() == 0 && !std::isfinite(__x.real()))
return __x;
return std::complex<_Tp>(sinh(__x.real()) * cos(__x.imag()),
cosh(__x.real()) * sin(__x.imag()));
}
// cosh
template <class _Tp>
__DEVICE__ std::complex<_Tp> cosh(const std::complex<_Tp> &__x) {
if (std::isinf(__x.real()) && !std::isfinite(__x.imag()))
return std::complex<_Tp>(abs(__x.real()), _Tp(NAN));
if (__x.real() == 0 && !std::isfinite(__x.imag()))
return std::complex<_Tp>(_Tp(NAN), __x.real());
if (__x.real() == 0 && __x.imag() == 0)
return std::complex<_Tp>(_Tp(1), __x.imag());
if (__x.imag() == 0 && !std::isfinite(__x.real()))
return std::complex<_Tp>(abs(__x.real()), __x.imag());
return std::complex<_Tp>(cosh(__x.real()) * cos(__x.imag()),
sinh(__x.real()) * sin(__x.imag()));
}
// tanh
template <class _Tp>
__DEVICE__ std::complex<_Tp> tanh(const std::complex<_Tp> &__x) {
if (std::isinf(__x.real())) {
if (!std::isfinite(__x.imag()))
return std::complex<_Tp>(_Tp(1), _Tp(0));
return std::complex<_Tp>(_Tp(1),
copysign(_Tp(0), sin(_Tp(2) * __x.imag())));
}
if (std::isnan(__x.real()) && __x.imag() == 0)
return __x;
_Tp __2r(_Tp(2) * __x.real());
_Tp __2i(_Tp(2) * __x.imag());
_Tp __d(cosh(__2r) + cos(__2i));
_Tp __2rsh(sinh(__2r));
if (std::isinf(__2rsh) && std::isinf(__d))
return std::complex<_Tp>(__2rsh > _Tp(0) ? _Tp(1) : _Tp(-1),
__2i > _Tp(0) ? _Tp(0) : _Tp(-0.));
return std::complex<_Tp>(__2rsh / __d, sin(__2i) / __d);
}
// asin
template <class _Tp>
__DEVICE__ std::complex<_Tp> asin(const std::complex<_Tp> &__x) {
std::complex<_Tp> __z = asinh(complex<_Tp>(-__x.imag(), __x.real()));
return std::complex<_Tp>(__z.imag(), -__z.real());
}
// acos
template <class _Tp>
__DEVICE__ std::complex<_Tp> acos(const std::complex<_Tp> &__x) {
const _Tp __pi(atan2(+0., -0.));
if (std::isinf(__x.real())) {
if (std::isnan(__x.imag()))
return std::complex<_Tp>(__x.imag(), __x.real());
if (std::isinf(__x.imag())) {
if (__x.real() < _Tp(0))
return std::complex<_Tp>(_Tp(0.75) * __pi, -__x.imag());
return std::complex<_Tp>(_Tp(0.25) * __pi, -__x.imag());
}
if (__x.real() < _Tp(0))
return std::complex<_Tp>(__pi,
signbit(__x.imag()) ? -__x.real() : __x.real());
return std::complex<_Tp>(_Tp(0),
signbit(__x.imag()) ? __x.real() : -__x.real());
}
if (std::isnan(__x.real())) {
if (std::isinf(__x.imag()))
return std::complex<_Tp>(__x.real(), -__x.imag());
return std::complex<_Tp>(__x.real(), __x.real());
}
if (std::isinf(__x.imag()))
return std::complex<_Tp>(__pi / _Tp(2), -__x.imag());
if (__x.real() == 0 && (__x.imag() == 0 || isnan(__x.imag())))
return std::complex<_Tp>(__pi / _Tp(2), -__x.imag());
std::complex<_Tp> __z = log(__x + sqrt(__sqr(__x) - _Tp(1)));
if (signbit(__x.imag()))
return std::complex<_Tp>(abs(__z.imag()), abs(__z.real()));
return std::complex<_Tp>(abs(__z.imag()), -abs(__z.real()));
}
// atan
template <class _Tp>
__DEVICE__ std::complex<_Tp> atan(const std::complex<_Tp> &__x) {
std::complex<_Tp> __z = atanh(complex<_Tp>(-__x.imag(), __x.real()));
return std::complex<_Tp>(__z.imag(), -__z.real());
}
// sin
template <class _Tp>
__DEVICE__ std::complex<_Tp> sin(const std::complex<_Tp> &__x) {
std::complex<_Tp> __z = sinh(complex<_Tp>(-__x.imag(), __x.real()));
return std::complex<_Tp>(__z.imag(), -__z.real());
}
// cos
template <class _Tp> std::complex<_Tp> cos(const std::complex<_Tp> &__x) {
return cosh(complex<_Tp>(-__x.imag(), __x.real()));
}
// tan
template <class _Tp>
__DEVICE__ std::complex<_Tp> tan(const std::complex<_Tp> &__x) {
std::complex<_Tp> __z = tanh(complex<_Tp>(-__x.imag(), __x.real()));
return std::complex<_Tp>(__z.imag(), -__z.real());
}
} // namespace std
#endif

View File

@@ -13,6 +13,12 @@
/* Define the default attributes for the functions in this file. */
#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("popcnt")))
#if defined(__cplusplus) && (__cplusplus >= 201103L)
#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS constexpr
#else
#define __DEFAULT_FN_ATTRS_CONSTEXPR __DEFAULT_FN_ATTRS
#endif
/// Counts the number of bits in the source operand having a value of 1.
///
/// \headerfile <x86intrin.h>
@@ -23,7 +29,7 @@
/// An unsigned 32-bit integer operand.
/// \returns A 32-bit integer containing the number of bits with value 1 in the
/// source operand.
static __inline__ int __DEFAULT_FN_ATTRS
static __inline__ int __DEFAULT_FN_ATTRS_CONSTEXPR
_mm_popcnt_u32(unsigned int __A)
{
return __builtin_popcount(__A);
@@ -40,7 +46,7 @@ _mm_popcnt_u32(unsigned int __A)
/// An unsigned 64-bit integer operand.
/// \returns A 64-bit integer containing the number of bits with value 1 in the
/// source operand.
static __inline__ long long __DEFAULT_FN_ATTRS
static __inline__ long long __DEFAULT_FN_ATTRS_CONSTEXPR
_mm_popcnt_u64(unsigned long long __A)
{
return __builtin_popcountll(__A);
@@ -48,5 +54,6 @@ _mm_popcnt_u64(unsigned long long __A)
#endif /* __x86_64__ */
#undef __DEFAULT_FN_ATTRS
#undef __DEFAULT_FN_ATTRS_CONSTEXPR
#endif /* __POPCNTINTRIN_H */

View File

@@ -78,6 +78,30 @@ extern __inline __m128i
return (__m128i)vec_sel((__v16qu)__A, (__v16qu)__B, __lmask);
}
extern __inline __m128i
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_insert_epi8(__m128i const __A, int const __D, int const __N) {
__v16qi result = (__v16qi)__A;
result[__N & 0xf] = __D;
return (__m128i)result;
}
extern __inline __m128i
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_insert_epi32(__m128i const __A, int const __D, int const __N) {
__v4si result = (__v4si)__A;
result[__N & 3] = __D;
return (__m128i)result;
}
extern __inline __m128i
__attribute__((__gnu_inline__, __always_inline__, __artificial__))
_mm_insert_epi64(__m128i const __A, long long const __D, int const __N) {
__v2di result = (__v2di)__A;
result[__N & 1] = __D;
return (__m128i)result;
}
#else
#include_next <smmintrin.h>
#endif /* defined(__linux__) && defined(__ppc64__) */

150
lib/include/uintrintrin.h vendored Normal file
View File

@@ -0,0 +1,150 @@
/*===------------------ uintrintrin.h - UINTR intrinsics -------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/
#ifndef __X86GPRINTRIN_H
#error "Never use <uintrintrin.h> directly; include <x86gprintrin.h> instead."
#endif
#ifndef __UINTRINTRIN_H
#define __UINTRINTRIN_H
/* Define the default attributes for the functions in this file */
#define __DEFAULT_FN_ATTRS \
__attribute__((__always_inline__, __nodebug__, __target__("uintr")))
#ifdef __x86_64__
/// Clears the user interrupt flag (UIF). Its effect takes place immediately: a
/// user interrupt cannot be delivered on the instruction boundary following
/// CLUI. Can be executed only if CR4.UINT = 1, the logical processor is in
/// 64-bit mode, and software is not executing inside an enclave; otherwise,
/// each causes an invalid-opcode exception. Causes a transactional abort if
/// executed inside a transactional region; the abort loads EAX as it would
/// had it been due to an execution of CLI.
///
/// \headerfile <x86gprintrin.h>
///
/// This intrinsic corresponds to the <c> CLUI </c> instruction.
///
/// \operation
/// UIF := 0
/// \endoperation
static __inline__ void __DEFAULT_FN_ATTRS
_clui (void)
{
__builtin_ia32_clui();
}
/// Sets the user interrupt flag (UIF). Its effect takes place immediately; a
/// user interrupt may be delivered on the instruction boundary following
/// STUI. Can be executed only if CR4.UINT = 1, the logical processor is in
/// 64-bit mode, and software is not executing inside an enclave; otherwise,
/// each causes an invalid-opcode exception. Causes a transactional abort if
/// executed inside a transactional region; the abort loads EAX as it would
/// had it been due to an execution of STI.
///
/// \headerfile <x86gprintrin.h>
///
/// This intrinsic corresponds to the <c> STUI </c> instruction.
///
/// \operation
/// UIF := 1
/// \endoperation
static __inline__ void __DEFAULT_FN_ATTRS
_stui (void)
{
__builtin_ia32_stui();
}
/// Get the current value of the user interrupt flag (UIF). Can be executed
/// regardless of CPL and inside a transactional region. Can be executed only
/// if CR4.UINT = 1, the logical processor is in 64-bit mode, and software is
/// not executing inside an enclave; otherwise, it causes an invalid-opcode
/// exception.
///
/// \headerfile <x86gprintrin.h>
///
/// This intrinsic corresponds to the <c> TESTUI </c> instruction.
///
/// \returns The current value of the user interrupt flag (UIF).
///
/// \operation
/// CF := UIF
/// ZF := 0
/// AF := 0
/// OF := 0
/// PF := 0
/// SF := 0
/// dst := CF
/// \endoperation
static __inline__ unsigned char __DEFAULT_FN_ATTRS
_testui (void)
{
return __builtin_ia32_testui();
}
/// Send interprocessor user interrupt. Can be executed only if
/// CR4.UINT = IA32_UINT_TT[0] = 1, the logical processor is in 64-bit mode,
/// and software is not executing inside an enclave; otherwise, it causes an
/// invalid-opcode exception. May be executed at any privilege level, all of
/// its memory accesses are performed with supervisor privilege.
///
/// \headerfile <x86gprintrin.h>
///
/// This intrinsic corresponds to the <c> SENDUIPI </c> instruction
///
/// \param __a
/// Index of user-interrupt target table entry in user-interrupt target
/// table.
///
/// \operation
/// IF __a > UITTSZ
/// GP (0)
/// FI
/// tempUITTE := MEM[UITTADDR + (a<<4)]
/// // tempUITTE must be valid, and can't have any reserved bit set
/// IF (tempUITTE.V == 0 OR tempUITTE[7:1] != 0)
/// GP (0)
/// FI
/// tempUPID := MEM[tempUITTE.UPIDADDR] // under lock
/// // tempUPID can't have any reserved bit set
/// IF (tempUPID[15:2] != 0 OR tempUPID[31:24] != 0)
/// GP (0) // release lock
/// FI
/// tempUPID.PIR[tempUITTE.UV] := 1;
/// IF (tempUPID.SN == 0 AND tempUPID.ON == 0)
/// tempUPID.ON := 1
/// sendNotify := 1
/// ELSE
/// sendNotify := 0
/// FI
/// MEM[tempUITTE.UPIDADDR] := tempUPID // release lock
/// IF sendNotify == 1
/// IF IA32_APIC_BASE[10] == 1 // local APIC is in x2APIC mode
/// // send ordinary IPI with vector tempUPID.NV to 32-bit physical APIC
/// // ID tempUPID.NDST
/// SendOrdinaryIPI(tempUPID.NV, tempUPID.NDST)
/// ELSE
/// // send ordinary IPI with vector tempUPID.NV to 8-bit physical APIC
/// // ID tempUPID.NDST[15:8]
/// SendOrdinaryIPI(tempUPID.NV, tempUPID.NDST[15:8])
/// FI
/// FI
/// \endoperation
static __inline__ void __DEFAULT_FN_ATTRS
_senduipi (unsigned long long __a)
{
__builtin_ia32_senduipi(__a);
}
#endif /* __x86_64__ */
#undef __DEFAULT_FN_ATTRS
#endif /* __UINTRINTRIN_H */

View File

@@ -18,8 +18,7 @@ typedef int32_t v128_t __attribute__((__vector_size__(16), __aligned__(16)));
// Internal types determined by clang builtin definitions
typedef int32_t __v128_u __attribute__((__vector_size__(16), __aligned__(1)));
typedef char __i8x16 __attribute__((__vector_size__(16), __aligned__(16)));
typedef signed char __s8x16
typedef signed char __i8x16
__attribute__((__vector_size__(16), __aligned__(16)));
typedef unsigned char __u8x16
__attribute__((__vector_size__(16), __aligned__(16)));
@@ -35,6 +34,13 @@ typedef unsigned long long __u64x2
typedef float __f32x4 __attribute__((__vector_size__(16), __aligned__(16)));
typedef double __f64x2 __attribute__((__vector_size__(16), __aligned__(16)));
typedef signed char __i8x8 __attribute__((__vector_size__(8), __aligned__(8)));
typedef unsigned char __u8x8
__attribute__((__vector_size__(8), __aligned__(8)));
typedef short __i16x4 __attribute__((__vector_size__(8), __aligned__(8)));
typedef unsigned short __u16x4
__attribute__((__vector_size__(8), __aligned__(8)));
#define __DEFAULT_FN_ATTRS \
__attribute__((__always_inline__, __nodebug__, __target__("simd128"), \
__min_vector_width__(128)))
@@ -273,7 +279,7 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_splat(int8_t __a) {
(__builtin_wasm_extract_lane_s_i8x16((__i8x16)(__a), __i))
#define wasm_u8x16_extract_lane(__a, __i) \
(__builtin_wasm_extract_lane_u_i8x16((__i8x16)(__a), __i))
(__builtin_wasm_extract_lane_u_i8x16((__u8x16)(__a), __i))
#define wasm_i8x16_replace_lane(__a, __i, __b) \
((v128_t)__builtin_wasm_replace_lane_i8x16((__i8x16)(__a), __i, __b))
@@ -286,7 +292,7 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_splat(int16_t __a) {
(__builtin_wasm_extract_lane_s_i16x8((__i16x8)(__a), __i))
#define wasm_u16x8_extract_lane(__a, __i) \
(__builtin_wasm_extract_lane_u_i16x8((__i16x8)(__a), __i))
(__builtin_wasm_extract_lane_u_i16x8((__u16x8)(__a), __i))
#define wasm_i16x8_replace_lane(__a, __i, __b) \
((v128_t)__builtin_wasm_replace_lane_i16x8((__i16x8)(__a), __i, __b))
@@ -333,17 +339,17 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_f64x2_splat(double __a) {
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_eq(v128_t __a,
v128_t __b) {
return (v128_t)((__s8x16)__a == (__s8x16)__b);
return (v128_t)((__i8x16)__a == (__i8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_ne(v128_t __a,
v128_t __b) {
return (v128_t)((__s8x16)__a != (__s8x16)__b);
return (v128_t)((__i8x16)__a != (__i8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_lt(v128_t __a,
v128_t __b) {
return (v128_t)((__s8x16)__a < (__s8x16)__b);
return (v128_t)((__i8x16)__a < (__i8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_lt(v128_t __a,
@@ -353,7 +359,7 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_lt(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_gt(v128_t __a,
v128_t __b) {
return (v128_t)((__s8x16)__a > (__s8x16)__b);
return (v128_t)((__i8x16)__a > (__i8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_gt(v128_t __a,
@@ -363,7 +369,7 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_gt(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_le(v128_t __a,
v128_t __b) {
return (v128_t)((__s8x16)__a <= (__s8x16)__b);
return (v128_t)((__i8x16)__a <= (__i8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_le(v128_t __a,
@@ -373,7 +379,7 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_le(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_ge(v128_t __a,
v128_t __b) {
return (v128_t)((__s8x16)__a >= (__s8x16)__b);
return (v128_t)((__i8x16)__a >= (__i8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_ge(v128_t __a,
@@ -595,7 +601,7 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_shl(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_shr(v128_t __a,
int32_t __b) {
return (v128_t)((__s8x16)__a >> __b);
return (v128_t)((__i8x16)__a >> __b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_shr(v128_t __a,
@@ -616,8 +622,8 @@ wasm_i8x16_add_saturate(v128_t __a, v128_t __b) {
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_u8x16_add_saturate(v128_t __a, v128_t __b) {
return (v128_t)__builtin_wasm_add_saturate_u_i8x16((__i8x16)__a,
(__i8x16)__b);
return (v128_t)__builtin_wasm_add_saturate_u_i8x16((__u8x16)__a,
(__u8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_sub(v128_t __a,
@@ -633,8 +639,8 @@ wasm_i8x16_sub_saturate(v128_t __a, v128_t __b) {
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_u8x16_sub_saturate(v128_t __a, v128_t __b) {
return (v128_t)__builtin_wasm_sub_saturate_u_i8x16((__i8x16)__a,
(__i8x16)__b);
return (v128_t)__builtin_wasm_sub_saturate_u_i8x16((__u8x16)__a,
(__u8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_min(v128_t __a,
@@ -644,7 +650,7 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_min(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_min(v128_t __a,
v128_t __b) {
return (v128_t)__builtin_wasm_min_u_i8x16((__i8x16)__a, (__i8x16)__b);
return (v128_t)__builtin_wasm_min_u_i8x16((__u8x16)__a, (__u8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_max(v128_t __a,
@@ -654,12 +660,12 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i8x16_max(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_max(v128_t __a,
v128_t __b) {
return (v128_t)__builtin_wasm_max_u_i8x16((__i8x16)__a, (__i8x16)__b);
return (v128_t)__builtin_wasm_max_u_i8x16((__u8x16)__a, (__u8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u8x16_avgr(v128_t __a,
v128_t __b) {
return (v128_t)__builtin_wasm_avgr_u_i8x16((__i8x16)__a, (__i8x16)__b);
return (v128_t)__builtin_wasm_avgr_u_i8x16((__u8x16)__a, (__u8x16)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_abs(v128_t __a) {
@@ -706,8 +712,8 @@ wasm_i16x8_add_saturate(v128_t __a, v128_t __b) {
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_u16x8_add_saturate(v128_t __a, v128_t __b) {
return (v128_t)__builtin_wasm_add_saturate_u_i16x8((__i16x8)__a,
(__i16x8)__b);
return (v128_t)__builtin_wasm_add_saturate_u_i16x8((__u16x8)__a,
(__u16x8)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_sub(v128_t __a,
@@ -723,8 +729,8 @@ wasm_i16x8_sub_saturate(v128_t __a, v128_t __b) {
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_u16x8_sub_saturate(v128_t __a, v128_t __b) {
return (v128_t)__builtin_wasm_sub_saturate_u_i16x8((__i16x8)__a,
(__i16x8)__b);
return (v128_t)__builtin_wasm_sub_saturate_u_i16x8((__u16x8)__a,
(__u16x8)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_mul(v128_t __a,
@@ -739,7 +745,7 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_min(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u16x8_min(v128_t __a,
v128_t __b) {
return (v128_t)__builtin_wasm_min_u_i16x8((__i16x8)__a, (__i16x8)__b);
return (v128_t)__builtin_wasm_min_u_i16x8((__u16x8)__a, (__u16x8)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_max(v128_t __a,
@@ -749,12 +755,12 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i16x8_max(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u16x8_max(v128_t __a,
v128_t __b) {
return (v128_t)__builtin_wasm_max_u_i16x8((__i16x8)__a, (__i16x8)__b);
return (v128_t)__builtin_wasm_max_u_i16x8((__u16x8)__a, (__u16x8)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u16x8_avgr(v128_t __a,
v128_t __b) {
return (v128_t)__builtin_wasm_avgr_u_i16x8((__i16x8)__a, (__i16x8)__b);
return (v128_t)__builtin_wasm_avgr_u_i16x8((__u16x8)__a, (__u16x8)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i32x4_abs(v128_t __a) {
@@ -810,7 +816,7 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i32x4_min(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u32x4_min(v128_t __a,
v128_t __b) {
return (v128_t)__builtin_wasm_min_u_i32x4((__i32x4)__a, (__i32x4)__b);
return (v128_t)__builtin_wasm_min_u_i32x4((__u32x4)__a, (__u32x4)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i32x4_max(v128_t __a,
@@ -820,7 +826,7 @@ static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i32x4_max(v128_t __a,
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_u32x4_max(v128_t __a,
v128_t __b) {
return (v128_t)__builtin_wasm_max_u_i32x4((__i32x4)__a, (__i32x4)__b);
return (v128_t)__builtin_wasm_max_u_i32x4((__u32x4)__a, (__u32x4)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS wasm_i64x2_neg(v128_t __a) {
@@ -1071,8 +1077,8 @@ wasm_i8x16_narrow_i16x8(v128_t __a, v128_t __b) {
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_u8x16_narrow_i16x8(v128_t __a, v128_t __b) {
return (v128_t)__builtin_wasm_narrow_u_i8x16_i16x8((__i16x8)__a,
(__i16x8)__b);
return (v128_t)__builtin_wasm_narrow_u_i8x16_i16x8((__u16x8)__a,
(__u16x8)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS
@@ -1083,48 +1089,76 @@ wasm_i16x8_narrow_i32x4(v128_t __a, v128_t __b) {
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_u16x8_narrow_i32x4(v128_t __a, v128_t __b) {
return (v128_t)__builtin_wasm_narrow_u_i16x8_i32x4((__i32x4)__a,
(__i32x4)__b);
return (v128_t)__builtin_wasm_narrow_u_i16x8_i32x4((__u32x4)__a,
(__u32x4)__b);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_i16x8_widen_low_i8x16(v128_t __a) {
return (v128_t)__builtin_wasm_widen_low_s_i16x8_i8x16((__i8x16)__a);
return (v128_t) __builtin_convertvector(
(__i8x8){((__i8x16)__a)[0], ((__i8x16)__a)[1], ((__i8x16)__a)[2],
((__i8x16)__a)[3], ((__i8x16)__a)[4], ((__i8x16)__a)[5],
((__i8x16)__a)[6], ((__i8x16)__a)[7]},
__i16x8);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_i16x8_widen_high_i8x16(v128_t __a) {
return (v128_t)__builtin_wasm_widen_high_s_i16x8_i8x16((__i8x16)__a);
return (v128_t) __builtin_convertvector(
(__i8x8){((__i8x16)__a)[8], ((__i8x16)__a)[9], ((__i8x16)__a)[10],
((__i8x16)__a)[11], ((__i8x16)__a)[12], ((__i8x16)__a)[13],
((__i8x16)__a)[14], ((__i8x16)__a)[15]},
__i16x8);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_i16x8_widen_low_u8x16(v128_t __a) {
return (v128_t)__builtin_wasm_widen_low_u_i16x8_i8x16((__i8x16)__a);
return (v128_t) __builtin_convertvector(
(__u8x8){((__u8x16)__a)[0], ((__u8x16)__a)[1], ((__u8x16)__a)[2],
((__u8x16)__a)[3], ((__u8x16)__a)[4], ((__u8x16)__a)[5],
((__u8x16)__a)[6], ((__u8x16)__a)[7]},
__u16x8);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_i16x8_widen_high_u8x16(v128_t __a) {
return (v128_t)__builtin_wasm_widen_high_u_i16x8_i8x16((__i8x16)__a);
return (v128_t) __builtin_convertvector(
(__u8x8){((__u8x16)__a)[8], ((__u8x16)__a)[9], ((__u8x16)__a)[10],
((__u8x16)__a)[11], ((__u8x16)__a)[12], ((__u8x16)__a)[13],
((__u8x16)__a)[14], ((__u8x16)__a)[15]},
__u16x8);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_i32x4_widen_low_i16x8(v128_t __a) {
return (v128_t)__builtin_wasm_widen_low_s_i32x4_i16x8((__i16x8)__a);
return (v128_t) __builtin_convertvector(
(__i16x4){((__i16x8)__a)[0], ((__i16x8)__a)[1], ((__i16x8)__a)[2],
((__i16x8)__a)[3]},
__i32x4);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_i32x4_widen_high_i16x8(v128_t __a) {
return (v128_t)__builtin_wasm_widen_high_s_i32x4_i16x8((__i16x8)__a);
return (v128_t) __builtin_convertvector(
(__i16x4){((__i16x8)__a)[4], ((__i16x8)__a)[5], ((__i16x8)__a)[6],
((__i16x8)__a)[7]},
__i32x4);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_i32x4_widen_low_u16x8(v128_t __a) {
return (v128_t)__builtin_wasm_widen_low_u_i32x4_i16x8((__i16x8)__a);
return (v128_t) __builtin_convertvector(
(__u16x4){((__u16x8)__a)[0], ((__u16x8)__a)[1], ((__u16x8)__a)[2],
((__u16x8)__a)[3]},
__u32x4);
}
static __inline__ v128_t __DEFAULT_FN_ATTRS
wasm_i32x4_widen_high_u16x8(v128_t __a) {
return (v128_t)__builtin_wasm_widen_high_u_i32x4_i16x8((__i16x8)__a);
return (v128_t) __builtin_convertvector(
(__u16x4){((__u16x8)__a)[4], ((__u16x8)__a)[5], ((__u16x8)__a)[6],
((__u16x8)__a)[7]},
__u32x4);
}
// Undefine helper macros

23
lib/include/x86gprintrin.h vendored Normal file
View File

@@ -0,0 +1,23 @@
/*===--------------- x86gprintrin.h - X86 GPR intrinsics ------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/
#ifndef __X86GPRINTRIN_H
#define __X86GPRINTRIN_H
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
defined(__HRESET__)
#include <hresetintrin.h>
#endif
#if !(defined(_MSC_VER) || defined(__SCE__)) || __has_feature(modules) || \
defined(__UINTR__)
#include <uintrintrin.h>
#endif
#endif /* __X86GPRINTRIN_H */

180
lib/libc/glibc/abi.txt vendored
View File

@@ -1195,6 +1195,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
29
29
29
29
29
@@ -2097,6 +2098,10 @@ aarch64-linux-gnu aarch64_be-linux-gnu
29
29
29
43
43
43
43
29
29
29
@@ -2656,10 +2661,13 @@ aarch64-linux-gnu aarch64_be-linux-gnu
29
29
29
43
43
29
29
29
29
43
29
29
29
@@ -2702,6 +2710,8 @@ aarch64-linux-gnu aarch64_be-linux-gnu
29
29
29
43
43
29
29
29
@@ -3440,6 +3450,8 @@ aarch64-linux-gnu aarch64_be-linux-gnu
29
29
29
43
43
29
29
29
@@ -5154,6 +5166,7 @@ s390x-linux-gnu
5
5
5
16
5
@@ -6056,6 +6069,10 @@ s390x-linux-gnu
5
5
12
43
43
43
43
5
5
5
@@ -6615,10 +6632,13 @@ s390x-linux-gnu
5
5
12
43
43
12
5
5
5
43
5
5
22
@@ -6661,6 +6681,8 @@ s390x-linux-gnu
5
5
16
43
43
19
19
23
@@ -7399,6 +7421,8 @@ s390x-linux-gnu
5 16
5
5
43
43
5
5
5
@@ -9113,6 +9137,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
16
16
16
16
16
@@ -10015,6 +10040,10 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
16
16
16
43
43
43
43
16
16
16
@@ -10574,10 +10603,13 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
16
16
16
43
43
16
16
16
16
43
16
16
22
@@ -10620,6 +10652,8 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
16
16
16
43
43
19
19
23
@@ -11358,6 +11392,8 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
16
16
16
43
43
16
16
16
@@ -13072,6 +13108,7 @@ sparc-linux-gnu sparcel-linux-gnu
5
5
0
16
0
@@ -13974,6 +14011,10 @@ sparc-linux-gnu sparcel-linux-gnu
0 5
1 5
12
43
43
43
43
0
1
1
@@ -14533,10 +14574,13 @@ sparc-linux-gnu sparcel-linux-gnu
0
1 5
12
43
43
12
0
1
0
43
0
0
22
@@ -14579,6 +14623,8 @@ sparc-linux-gnu sparcel-linux-gnu
5
0
16
43
43
19
19
23
@@ -15317,6 +15363,8 @@ sparc-linux-gnu sparcel-linux-gnu
0 16
0
0
43
43
0
1
1
@@ -17031,6 +17079,7 @@ sparcv9-linux-gnu
5
5
5
16
5
@@ -17933,6 +17982,10 @@ sparcv9-linux-gnu
5
5
12
43
43
43
43
5
5
5
@@ -18492,10 +18545,13 @@ sparcv9-linux-gnu
5
5
12
43
43
12
5
5
5
43
5
5
22
@@ -18538,6 +18594,8 @@ sparcv9-linux-gnu
5
5
16
43
43
19
19
23
@@ -19276,6 +19334,8 @@ sparcv9-linux-gnu
5
5
5
43
43
5
5
5
@@ -20990,6 +21050,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
5
5
0
16
0
@@ -21892,6 +21953,10 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
0 5
5
12
43
43
43
43
0
5
5
@@ -22451,10 +22516,13 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
0
5
12
43
43
12
0
5
0
43
0
0
22
@@ -22497,6 +22565,8 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
5
0
16
43
43
19
19
23
@@ -23235,6 +23305,8 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
0
0
0
43
43
0
5
5
@@ -24949,6 +25021,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
5
5
0
16
0
@@ -25851,6 +25924,10 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
0 5
5
12
43
43
43
43
0
5
5
@@ -26410,10 +26487,13 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
0
5
12
43
43
12
0
5
0
43
0
0
22
@@ -26456,6 +26536,8 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
5
0
16
43
43
19
19
23
@@ -27194,6 +27276,8 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
0
0
0
43
43
0
5
5
@@ -28908,6 +28992,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
5
5
0
16
0
@@ -29810,6 +29895,10 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
0 5
5
12
43
43
43
43
0
5
5
@@ -30369,10 +30458,13 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
0
5
12
43
43
12
0
5
0
43
0
0
22
@@ -30415,6 +30507,8 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
5
0
16
43
43
19
19
23
@@ -31153,6 +31247,8 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
0
0
0
43
43
0
5
5
@@ -32867,6 +32963,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
5
5
0
16
0
@@ -33769,6 +33866,10 @@ mipsel-linux-gnueabi mips-linux-gnueabi
0 5
5
12
43
43
43
43
0
5
5
@@ -34328,10 +34429,13 @@ mipsel-linux-gnueabi mips-linux-gnueabi
0
5
12
43
43
12
0
5
0
43
0
0
22
@@ -34374,6 +34478,8 @@ mipsel-linux-gnueabi mips-linux-gnueabi
5
0
16
43
43
19
19
23
@@ -35112,6 +35218,8 @@ mipsel-linux-gnueabi mips-linux-gnueabi
0
0
0
43
43
0
5
5
@@ -36826,6 +36934,7 @@ x86_64-linux-gnu
10
10
43
10
16
10
@@ -37728,6 +37837,10 @@ x86_64-linux-gnu
10
10
12
43
43
43
43
10
10
10
@@ -38287,10 +38400,13 @@ x86_64-linux-gnu
10
10
12
43
43
12
10
10
10
43
10
10
22
@@ -38333,6 +38449,8 @@ x86_64-linux-gnu
10
10
16
43
43
19
19
23
@@ -39071,6 +39189,8 @@ x86_64-linux-gnu
10
10
10
43
43
10
10
10
@@ -40785,6 +40905,7 @@ x86_64-linux-gnux32
28
28
43
28
28
28
@@ -41687,6 +41808,10 @@ x86_64-linux-gnux32
28
28
28
43
43
43
43
28
28
28
@@ -42246,10 +42371,13 @@ x86_64-linux-gnux32
28
28
28
43
43
28
28
28
28
43
28
28
28
@@ -42292,6 +42420,8 @@ x86_64-linux-gnux32
28
28
28
43
43
28
28
28
@@ -43030,6 +43160,8 @@ x86_64-linux-gnux32
28
28
28
43
43
28
28
28
@@ -44744,6 +44876,7 @@ i386-linux-gnu
5
5
43
0
16
0
@@ -45646,6 +45779,10 @@ i386-linux-gnu
0 5
1 5
12
43
43
43
43
0
1
1
@@ -46205,10 +46342,13 @@ i386-linux-gnu
0
1 5
12
43
43
12
0
1
0
43
0
0
22
@@ -46251,6 +46391,8 @@ i386-linux-gnu
5
0
16
43
43
19
19
23
@@ -46989,6 +47131,8 @@ i386-linux-gnu
0
0
0
43
43
0
1
1
@@ -48703,6 +48847,7 @@ powerpc64le-linux-gnu
42
29
29
29
29
29
@@ -49605,6 +49750,10 @@ powerpc64le-linux-gnu
29
29
29
43
43
43
43
29
29
29
@@ -50164,10 +50313,13 @@ powerpc64le-linux-gnu
29
29
29
43
43
29
29
29
29
43
29
29
29
@@ -50210,6 +50362,8 @@ powerpc64le-linux-gnu
29
29
29
43
43
29
29
29
@@ -50948,6 +51102,8 @@ powerpc64le-linux-gnu
29
29
29
43
43
29
29
29
@@ -52662,6 +52818,7 @@ powerpc64-linux-gnu
12
12
12
16
12
@@ -53564,6 +53721,10 @@ powerpc64-linux-gnu
12
12
12
43
43
43
43
12
12
12
@@ -54123,10 +54284,13 @@ powerpc64-linux-gnu
12
12
12
43
43
12
12
12
12
43
12
12
22
@@ -54169,6 +54333,8 @@ powerpc64-linux-gnu
12
12
16
43
43
19
19
23
@@ -54907,6 +55073,8 @@ powerpc64-linux-gnu
12 16
12
12
43
43
12
12
12
@@ -56621,6 +56789,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
5
5
0
16
0
@@ -57523,6 +57692,10 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
0 5
1 5
12
43
43
43
43
0
1
1
@@ -58082,10 +58255,13 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
0
1 5
12
43
43
12
0
1 14 15
0
43
0
0
22
@@ -58128,6 +58304,8 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
5
0
16
43
43
19
19
23
@@ -58866,6 +59044,8 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
0 16
0
0
43
43
0
1
1

View File

@@ -1194,6 +1194,7 @@ __write c
__wscanfieee128 c
__wuflow c
__wunderflow c
__x86_get_cpuid_feature_leaf c
__xmknod c
__xmknodat c
__xpg_basename c
@@ -2096,6 +2097,10 @@ fseeko64 c
fsetpos c
fsetpos64 c
fsetxattr c
fstat c
fstat64 c
fstatat c
fstatat64 c
fstatfs c
fstatfs64 c
fstatvfs c
@@ -2655,10 +2660,13 @@ lsearch c
lseek c
lseek64 c
lsetxattr c
lstat c
lstat64 c
lutimes c
madvise c
makecontext c
mallinfo c
mallinfo2 c
malloc c
malloc_get_state c
malloc_info c
@@ -2701,6 +2709,8 @@ mkdirat c
mkdtemp c
mkfifo c
mkfifoat c
mknod c
mknodat c
mkostemp c
mkostemp64 c
mkostemps c
@@ -3439,6 +3449,8 @@ srandom_r c
sscanf c
ssignal c
sstk c
stat c
stat64 c
statfs c
statfs64 c
statvfs c

View File

@@ -61,7 +61,7 @@ lose: SYSCALL_PIC_SETUP \
# define SETUP_PIC_REG(reg) \
.ifndef GET_PC_THUNK(reg); \
.section .gnu.linkonce.t.GET_PC_THUNK(reg),"ax",@progbits; \
.section .text.GET_PC_THUNK(reg),"axG",@progbits,GET_PC_THUNK(reg),comdat; \
.globl GET_PC_THUNK(reg); \
.hidden GET_PC_THUNK(reg); \
.p2align 4; \
@@ -97,8 +97,9 @@ GET_PC_THUNK(reg): \
# define SETUP_PIC_REG_STR(reg) \
".ifndef " GET_PC_THUNK_STR (reg) "\n" \
".section .gnu.linkonce.t." GET_PC_THUNK_STR (reg) ",\"ax\",@progbits\n" \
"section .text." GET_PC_THUNK_STR (reg) ",\"axG\",@progbits," \
".globl " GET_PC_THUNK_STR (reg) "\n" \
GET_PC_THUNK_STR (reg) ",comdat\n" \
".hidden " GET_PC_THUNK_STR (reg) "\n" \
".p2align 4\n" \
".type " GET_PC_THUNK_STR (reg) ",@function\n" \

View File

@@ -1,81 +0,0 @@
/* Machine-specific pthread type layouts. SPARC version.
Copyright (C) 2003-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#ifndef _BITS_PTHREADTYPES_ARCH_H
#define _BITS_PTHREADTYPES_ARCH_H 1
#include <bits/wordsize.h>
#if __WORDSIZE == 64
# define __SIZEOF_PTHREAD_ATTR_T 56
# define __SIZEOF_PTHREAD_MUTEX_T 40
# define __SIZEOF_PTHREAD_CONDATTR_T 4
# define __SIZEOF_PTHREAD_RWLOCK_T 56
# define __SIZEOF_PTHREAD_BARRIER_T 32
#else
# define __SIZEOF_PTHREAD_ATTR_T 36
# define __SIZEOF_PTHREAD_MUTEX_T 24
# define __SIZEOF_PTHREAD_CONDATTR_T 4
# define __SIZEOF_PTHREAD_RWLOCK_T 32
# define __SIZEOF_PTHREAD_BARRIER_T 20
#endif
#define __SIZEOF_PTHREAD_MUTEXATTR_T 4
#define __SIZEOF_PTHREAD_COND_T 48
#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
#define __SIZEOF_PTHREAD_BARRIERATTR_T 4
/* Definitions for internal mutex struct. */
#define __PTHREAD_COMPAT_PADDING_MID
#define __PTHREAD_COMPAT_PADDING_END
#define __PTHREAD_MUTEX_LOCK_ELISION 0
#define __PTHREAD_MUTEX_NUSERS_AFTER_KIND (__WORDSIZE != 64)
#define __PTHREAD_MUTEX_USE_UNION (__WORDSIZE != 64)
#define __LOCK_ALIGNMENT
#define __ONCE_ALIGNMENT
struct __pthread_rwlock_arch_t
{
unsigned int __readers;
unsigned int __writers;
unsigned int __wrphase_futex;
unsigned int __writers_futex;
unsigned int __pad3;
unsigned int __pad4;
#if __WORDSIZE == 64
int __cur_writer;
int __shared;
unsigned long int __pad1;
unsigned long int __pad2;
/* FLAGS must stay at this position in the structure to maintain
binary compatibility. */
unsigned int __flags;
#else
unsigned char __pad1;
unsigned char __pad2;
unsigned char __shared;
/* FLAGS must stay at this position in the structure to maintain
binary compatibility. */
unsigned char __flags;
int __cur_writer;
#endif
};
#define __PTHREAD_RWLOCK_ELISION_EXTRA 0
#endif /* bits/pthreadtypes.h */

View File

@@ -41,3 +41,4 @@ GLIBC_2.29
GLIBC_2.30
GLIBC_2.31
GLIBC_2.32
GLIBC_2.33

View File

@@ -1,5 +1,5 @@
/* O_*, F_*, FD_* bit values for the AArch64 Linux ABI.
Copyright (C) 2011-2020 Free Software Foundation, Inc.
Copyright (C) 2011-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2004-2020 Free Software Foundation, Inc.
/* Copyright (C) 2004-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,5 +1,5 @@
/* Define FP_FAST_* macros. AArch64 version.
Copyright (C) 2016-2020 Free Software Foundation, Inc.
Copyright (C) 2016-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or

View File

@@ -1,5 +1,5 @@
/* Defines for bits in AT_HWCAP. AArch64 Linux version.
Copyright (C) 2016-2020 Free Software Foundation, Inc.
Copyright (C) 2016-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -72,4 +72,5 @@
#define HWCAP2_BF16 (1 << 14)
#define HWCAP2_DGH (1 << 15)
#define HWCAP2_RNG (1 << 16)
#define HWCAP2_BTI (1 << 17)
#define HWCAP2_BTI (1 << 17)
#define HWCAP2_MTE (1 << 18)

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2005-2020 Free Software Foundation, Inc.
/* Copyright (C) 2005-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,5 +1,5 @@
/* Minimum guaranteed maximum values for system limits. Linux version.
Copyright (C) 1993-2020 Free Software Foundation, Inc.
Copyright (C) 1993-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,5 +1,5 @@
/* Properties of long double type. ldbl-128 version.
Copyright (C) 2016-2020 Free Software Foundation, Inc.
Copyright (C) 2016-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or

View File

@@ -1,5 +1,5 @@
/* Definitions for POSIX memory map interface. Linux/AArch64 version.
Copyright (C) 2020 Free Software Foundation, Inc.
Copyright (C) 2020-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -24,6 +24,7 @@
arch/arm64/include/uapi/asm/mman.h. */
#define PROT_BTI 0x10
#define PROT_MTE 0x20
#include <bits/mman-map-flags-generic.h>

View File

@@ -1,5 +1,5 @@
/* Types for registers for sys/procfs.h. AArch64 version.
Copyright (C) 1996-2020 Free Software Foundation, Inc.
Copyright (C) 1996-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2002-2020 Free Software Foundation, Inc.
/* Copyright (C) 2002-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2002-2020 Free Software Foundation, Inc.
/* Copyright (C) 2002-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 1997-2020 Free Software Foundation, Inc.
/* Copyright (C) 1997-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,5 +1,5 @@
/* sigstack, sigaltstack definitions.
Copyright (C) 2015-2020 Free Software Foundation, Inc.
Copyright (C) 2015-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 2011-2020 Free Software Foundation, Inc.
/* Copyright (C) 2011-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.

View File

@@ -1,5 +1,5 @@
/* AArch64 internal rwlock struct definitions.
Copyright (C) 2019-2020 Free Software Foundation, Inc.
Copyright (C) 2019-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,6 +1,6 @@
/* Copyright (C) 2011-2020 Free Software Foundation, Inc.
/* Definition for struct stat.
Copyright (C) 2020-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -17,29 +17,15 @@
<https://www.gnu.org/licenses/>. */
#if !defined _SYS_STAT_H && !defined _FCNTL_H
# error "Never include <bits/stat.h> directly; use <sys/stat.h> instead."
# error "Never include <bits/struct_stat.h> directly; use <sys/stat.h> instead."
#endif
#ifndef _BITS_STAT_H
#define _BITS_STAT_H 1
#ifndef _BITS_STRUCT_STAT_H
#define _BITS_STRUCT_STAT_H 1
#include <bits/endian.h>
#include <bits/wordsize.h>
/* 64-bit libc uses the kernel's 'struct stat', accessed via the
stat() syscall; 32-bit libc uses the kernel's 'struct stat64'
and accesses it via the stat64() syscall. All the various
APIs offered by libc use the kernel shape for their struct stat
structure; the only difference is that 32-bit programs not
using __USE_FILE_OFFSET64 only see the low 32 bits of some
of the fields (specifically st_ino, st_size, and st_blocks). */
#define _STAT_VER_KERNEL 0
#define _STAT_VER_LINUX 0
#define _STAT_VER _STAT_VER_KERNEL
/* Versions of the `xmknod' interface. */
#define _MKNOD_VER_LINUX 0
#if defined __USE_FILE_OFFSET64
# define __field64(type, type64, name) type64 name
#elif __WORDSIZE == 64 || defined __INO_T_MATCHES_INO64_T
@@ -138,37 +124,4 @@ struct stat64
/* Nanosecond resolution time values are supported. */
#define _STATBUF_ST_NSEC
/* Encoding of the file mode. */
#define __S_IFMT 0170000 /* These bits determine file type. */
/* File types. */
#define __S_IFDIR 0040000 /* Directory. */
#define __S_IFCHR 0020000 /* Character device. */
#define __S_IFBLK 0060000 /* Block device. */
#define __S_IFREG 0100000 /* Regular file. */
#define __S_IFIFO 0010000 /* FIFO. */
#define __S_IFLNK 0120000 /* Symbolic link. */
#define __S_IFSOCK 0140000 /* Socket. */
/* POSIX.1b objects. Note that these macros always evaluate to zero. But
they do it by enforcing the correct use of the macros. */
#define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode)
#define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
#define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
/* Protection bits. */
#define __S_ISUID 04000 /* Set user ID on execution. */
#define __S_ISGID 02000 /* Set group ID on execution. */
#define __S_ISVTX 01000 /* Save swapped text after use (sticky). */
#define __S_IREAD 0400 /* Read by owner. */
#define __S_IWRITE 0200 /* Write by owner. */
#define __S_IEXEC 0100 /* Execute by owner. */
#ifdef __USE_ATFILE
# define UTIME_NOW ((1l << 30) - 1l)
# define UTIME_OMIT ((1l << 30) - 2l)
#endif
#endif /* bits/stat.h */
#endif /* _BITS_STRUCT_STAT_H */

View File

@@ -1,5 +1,5 @@
/* bits/typesizes.h -- underlying types for *_t. For the generic Linux ABI.
Copyright (C) 2011-2020 Free Software Foundation, Inc.
Copyright (C) 2011-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.

View File

@@ -1,6 +1,6 @@
/* Determine the wordsize from the preprocessor defines.
Copyright (C) 2016-2020 Free Software Foundation, Inc.
Copyright (C) 2016-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
/* Copyright (C) 1996-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 1992-2020 Free Software Foundation, Inc.
/* Copyright (C) 1992-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 1996-2020 Free Software Foundation, Inc.
/* Copyright (C) 1996-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,5 +1,5 @@
/* `ptrace' debugger support interface. Linux/AArch64 version.
Copyright (C) 1996-2020 Free Software Foundation, Inc.
Copyright (C) 1996-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

View File

@@ -1,4 +1,4 @@
/* Copyright (C) 1998-2020 Free Software Foundation, Inc.
/* Copyright (C) 1998-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.

Some files were not shown because too many files have changed in this diff Show More