13814 Commits

Author SHA1 Message Date
dweiller
ae19f699ab sema: implement switch_block_err_union on comptime operands 2024-01-09 14:42:12 +11:00
dweiller
2cf648fba7 astgen: use switch_block_err_union 2024-01-09 14:42:12 +11:00
dweiller
b784f64a6e sema: refactor error set switch logic 2024-01-09 14:42:11 +11:00
dweiller
4136097566 zir: add switch_block_err_union 2024-01-09 14:42:11 +11:00
dweiller
063d55c504 zir: remove unused zir as instruction 2024-01-09 14:42:11 +11:00
Ali Chraghi
0e856da224 add type safety to ZIR for null terminated strings 2024-01-08 16:33:33 -08:00
Andrew Kelley
4cf08932b5
Merge pull request #16109
Update mingw-w64 to latest git commit
2024-01-08 16:13:14 -08:00
Andrew Kelley
ed410b9c1e lift artificial restriction on minimum glibc version
Fixes a regression introduced in
c22d1c00a8825f60e7b01b97c6f73cbc21ca8257.

See #17769
2024-01-08 13:43:10 -07:00
Andrew Kelley
9a4a74eb65 mingw: remove pow.c from aarch64-windows mingw builds
I observed a duplicate symbol linker error; pow was defined both by
mingwex.lib and ucrtbase.dll.
2024-01-08 11:53:06 -07:00
Andrew Kelley
f5ed441ddb mingw: add the build logic for the previous commit
Separate commits for the zig logic and the copied files.
2024-01-08 11:52:38 -07:00
Andrew Kelley
99922c2708 Compilation: only add __MSVCRT_VERSION__ for -lc
prevents it from being defined twice when building mingw-w64 libs.
2024-01-08 11:52:38 -07:00
Andrew Kelley
7b3afc880b Compilation: add definition to prefer ucrt for windows C/C++ files
This makes C/C++ files when targeting mingw-w64 choose to depend on ucrt
for stdio.
2024-01-08 11:52:38 -07:00
Andrew Kelley
e2a8fe721d mingw: add comments so that I don't regress this code later
Martin Storsjö kindly took the time to discuss things at length with me,
and the results are that this status quo is correct. I added comments so
that I don't think it should be changed later.
2024-01-08 11:52:38 -07:00
Andrew Kelley
3f4c73ae93 mingw: update from msvcrt to ucrt 2024-01-08 11:52:38 -07:00
Andrew Kelley
c26bace606 mingw-w64: update CRT files to latest git commit
Upstream commit dddccbc3ef50ac52bf00723fd2f68d98140aab80

* adds ucrtbase.def.in
* mingwex: replace mingw crt files with ucrt files
* adds missing mingw-w64 ucrt files

The rules that govern which set of files are included or excluded is
contained in the logic for tools/update_mingw.zig
2024-01-08 11:52:38 -07:00
Andrew Kelley
491b460e0a add tool for updating mingw crt files 2024-01-08 11:52:38 -07:00
Jeremy Volkman
8fd15c6ca8 Use a fixed chunk size when calculating MachO UUID 2024-01-08 10:23:07 +01:00
Andrew Kelley
3176fdc0b9
Merge pull request #18470 from castholm/typeInfo-sentinels
Make `@typeInfo` return null-terminated strings
2024-01-07 22:28:24 -08:00
Veikka Tuominen
faeb0ef032 llvm: optional slices cannot be passed in parts when they allowzero
Closes #18428
2024-01-08 06:57:06 +02:00
Carl Åstholm
01b48e9381 InternPool: Fix rare buffer overflow when initializing aggregate with sentinel 2024-01-07 21:46:52 +01:00
Carl Åstholm
c8fa767f08 Work around stage1 not yet returning null-terminated @typeInfo strings
These changes can be reverted the next time stage1 is updated.
2024-01-07 16:21:08 +01:00
Carl Åstholm
a02bd81760 Make @typeInfo return null-terminated strings
Changes the types of `std.builtin.Type` `name` fields from `[]const u8`
to `[:0]const u8`, which should make them easier to pass to C APIs
expecting null-terminated strings.

This will break code that reifies types using `[]const u8` strings, such
as code that uses `std.mem.tokenize()` to construct types from strings
at comptime. Luckily, the fix is simple: simply concatenate the
`[]const u8` string with an empty string literal (`name ++ ""`) to
explicitly coerce it to `[:0]const u8`.

Co-authored-by: Krzysztof Wolicki <der.teufel.mail@gmail.com>
2024-01-07 15:35:18 +01:00
Tristan Ross
c78b6564df Compilation: pass code model in buildOutputFromZig 2024-01-06 18:33:24 -08:00
Krzysztof Wolicki
42389cb9c5
autodoc: Reimplement array_mul after ZIR changes. Change some vars to const where possible. (#17939) 2024-01-05 15:28:42 +01:00
Andrew Kelley
362460ec24 minor cosmetic fixups
* fix typos and redundancies in docs
* use Target.isGnuLibc
2024-01-04 17:26:06 -07:00
Pat Tullmann
c22d1c00a8 src/target: Restrict usable glibc versions
At a minimum required glibc is v2.17, as earlier versions do not define
some symbols (e.g., getauxval()) used by the Zig standard library.

Additionally, glibc only supports some architectures at more recent
versions (e.g., riscv64 support came in glibc v2.27).  So add a
`glibc_min` field to `available_libcs` for architectures with stronger
version requirements.

Extend the existing `canBuildLibC` function to check the target against
the Zig minimum, and the architecture/os minimum.

Also filter the list shown by `zig targets`, too:

  $ zig targets | jq -c '.glibc'
  ["2.17.0","2.18.0","2.19.0","2.20.0","2.21.0","2.22.0","2.23.0","2.24.0","2.25.0","2.26.0","2.27.0","2.28.0","2.29.0","2.30.0","2.31.0","2.32.0","2.33.0","2.34.0","2.35.0","2.36.0","2.37.0","2.38.0"]

Fixes #17034
Fixes #17769
2024-01-04 17:12:07 -07:00
Kang Seonghoon
7dcf7412c4 glibc: get correct files compiled into libc_nonshared.a
The scope of libc_nonshared.a was greatly changed in glibc 2.33 and
2.34, but only the change from 2.34 was reflected so far. Glibc 2.33
finally switched to versioned symbols for stat functions, meaning that
libc_nonshared.a no longer contains them since 2.33. Relevant files were
therefore reverted to 2.32 versions and renamed accordingly.

This commit also removes errno.c, which was probably added to
libc_nonshared.a based on a wrong assumption that glibc/include/errno.h
requires glibc/csu/errno.c. In reality errno.h should refer to
__libc_errno (not to be confused with the public __errno_location),
which should be imported from libc.so. The inclusion of errno.c resulted
in wrong compile options as well; this commit fixes them as well.

Fixes #16152
2024-01-04 17:12:07 -07:00
Carl Åstholm
501a2350ab sema: Prevent reifying non-empty union with empty tag type 2024-01-04 22:38:31 +02:00
Ryan Liptak
0527cab71b Use std.fs.path.relative for @import and @embedFile sub paths
Fixes edge cases where the `startsWith` that was used previously would return a false positive on a resolved path like `foo.zig` when the resolved root was `foo`. Before this commit, such a path would be treated as a sub path of 'foo' with a resolved sub file path of 'zig' (and the `.` would be assumed to be a path separator). After this commit, `foo.zig` will be correctly treated as outside of the root of `foo`.

Closes #18355
2024-01-04 17:34:34 +02:00
amp-59
10016e0368 Sema: fix crash compiling @shlExact
Updated `zirShl`, to compute `shl_exact` with `comptime_int` LHS operand
like `shl`, and added test case for `@shlExact` with `comptime_int` LHS
operand.
2024-01-04 00:10:41 -07:00
Andrew Kelley
2ac315c245 compiler: fix build runner not added to cache hash
Closes #18438
2024-01-03 17:36:54 -08:00
Andrew Kelley
a9337bef2d
Merge pull request #18431 from jacobly0/cbe-extern
cbe: fix non-msvc externs and exports
2024-01-03 12:57:01 -08:00
xdBronch
d03649ec2f add missing resolveStructFieldInits 2024-01-03 11:05:25 +02:00
Jacob Young
047d6d996e cbe: fix non-msvc externs and exports
Closes #17817
2024-01-03 02:52:25 -05:00
Jacob Young
98b633ff17 Reapply "Merge pull request #17824 from kcbanner/fixup_msvc_fmax"
This reverts commit 2b589783602c5428ecde9dbb3f41a81f85eb0f25.
2024-01-03 02:41:21 -05:00
amp-59
ca4ee9ae73
Sema: Added logic to avoid unchecked operations calling preparePanicId (#18416)
Fixes #18415
2024-01-03 02:34:24 -05:00
Andrew Kelley
289ae45c1b
Merge pull request #18160 from ziglang/std-build-module
Move many settings from being per-Compilation to being per-Module
2024-01-02 14:11:27 -08:00
Veikka Tuominen
d9d840a33a
Merge pull request #18410 from dweiller/by-length-slice-bug
sema: add compile error for OOB by-length slice of array
2024-01-02 17:37:21 +02:00
arbrk1
024540de15
Liveness: fix branch operands becoming aliased 2024-01-02 12:08:26 +02:00
Andrew Kelley
d5c1e7f7b1 link: accept the update arena in flush
This branch introduced an arena allocator for temporary allocations in
Compilation.update. Almost every implementation of flush() inside the
linker code was already creating a local arena that had the lifetime of
the function call. This commit passes the update arena so that all those
local ones can be deleted, resulting in slightly more efficient memory
usage with every compilation update.

While at it, this commit also removes the Compilation parameter from the
linker flush function API since a reference to the Compilation is now
already stored in `link.File`.
2024-01-01 19:49:08 -07:00
Andrew Kelley
eae6d45cde CLI: introduce global -I args for C include paths
This isn't technically needed since per-module -I args can suffice, but
this can produce very long CLI invocations when several --mod args are
combined with --search-prefix args since the -I args have to be repeated
for each module.

This is a partial revert of ecbe8bbf2df2ed4d473efbc32e0b6d7091fba76f.
2024-01-01 19:49:08 -07:00
Andrew Kelley
7fb9f58f85 Compilation: rename before flush during whole cache mode
The linker needs to know the file system path of output in the flush
function because file paths inside the build artifacts reference each
other. Fixes a regression introduced in this branch.
2024-01-01 19:49:08 -07:00
Andrew Kelley
6b2709616e frontend: ignore AccessDenied when writing builtin.zig
This issue already existed in master branch, however, the more
aggressive caching of builtin.zig in this branch made it happen more
often. I added doc comments to AtomicFile to explain when this problem
can occur.

For the compiler's use case, error.AccessDenied can be simply swallowed
because it means the destination file already exists and there is
nothing else to do besides proceed with the AtomicFile cleanup.

I never solved the mystery of why the log statements weren't printing
but those are temporary debugging instruments anyway, and I am already
too many yaks deep to whip out another razor.

closes #14978
2024-01-01 19:49:08 -07:00
Andrew Kelley
a89d6878d2 Compilation: fix cache hash of incremental builds
Without this commit, unrelated test builds using incremental cache mode
(self-hosted, no lld) would end up using the same cache namespace, which
is undesireable since concurrent builds will clobber each other's work.

This happened because of passing the root module to
addModuleToCacheHash. In the case of a test build, the root module
actually does not connect to the rest of the import table. Instead, the
main module needs to be passed, which has "root" in its import table.

The other call to addModuleTableToCacheHash which is in
addNonIncrementalStuffToCacheManifest already correctly passes the main
module.

In the future, I think this problem can be fully addressed by obtaining
an advisory lock on the output binary file. However, even in that case,
it is still valuable to make different compilations use different cache
namespaces lest unrelated compilations suffer from pointless thrashing
rather than being independently edited.
2024-01-01 19:49:08 -07:00
Andrew Kelley
e22102dfc6 Compilation: make create() take an arena allocator
Instead of making its own inside create. 10 out of 10 calls to create()
had already an arena in scope, so this commit means that 10 instances of
Compilation now reuse an existing arena with the same lifetime rather
than creating a redundant one.

In other words, this very slightly optimizes initialization of the
frontend in terms of memory allocation.
2024-01-01 19:49:08 -07:00
Andrew Kelley
c2cc1b3792 frontend: add logging to help troubleshoot builtin.zig write failures 2024-01-01 19:49:08 -07:00
Andrew Kelley
668c0cdeda compiler: Compilation.Config: trivial refactor 2024-01-01 19:49:08 -07:00
Andrew Kelley
196ddf010c frontend: fix populateTestFunctions accessing the wrong module
The test runner reads the list of test function pointers from its own
builtin module, which is the root_mod, not main_mod.
2024-01-01 19:49:08 -07:00
Andrew Kelley
b8674910d4 restore -fno-emit-bin -femit-llvm-ir functionality
Now, link.File will always be null when -fno-emit-bin is specified, and
in the case that LLVM artifacts are still required, the Zcu instance has
an LlvmObject.
2024-01-01 19:49:08 -07:00
Andrew Kelley
92cc2f41e6 CLI: fix compilation on Windows 2024-01-01 19:49:08 -07:00