16860 Commits

Author SHA1 Message Date
Jacob Young
6dbf1c7682 x86_64: rewrite scalar +| 2025-05-17 02:08:41 -04:00
Jacob Young
932298679f x86_64: rewrite scalar @shlWithOverflow 2025-05-17 02:08:41 -04:00
Alex Rønne Petersen
c5e669ff76
compiler: Link libc by default when targeting NetBSD.
We don't yet have a direct syscall layer in std.os.netbsd.
2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
d29ba75c84
Compilation.Config: Default to dynamic linking with NetBSD libc. 2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
e20fb7071c
compiler: Define __NetBSD_Version__ when targeting NetBSD libc. 2025-05-17 04:41:27 +02:00
Alex Rønne Petersen
0d35a7760e
freebsd: Fix selection of unversioned symbol inclusion.
We want the latest unversioned inclusion that fits the target version. This
theoretically matters because it might have a different global vs weak linkage
compared to an older inclusion.
2025-05-17 04:41:26 +02:00
Alex Rønne Petersen
76d525f74a
freebsd: Remove dead Thumb handling code. 2025-05-17 04:41:26 +02:00
Alex Rønne Petersen
e52ffe6738
glibc: Fix a benign bug when selecting the size of an object symbol.
This didn't cause any problems in practice, but doing it this way is technically
more correct.
2025-05-17 04:41:24 +02:00
mlugg
4296727050
Sema: improve "called from here" notes
To an average user, it may be unclear why these notes are not just in
the reference trace; that's because they are more important, because
they are inline calls through which comptime values may propagate. There
are now 3 possible wordings for this note:

* "called at comptime here"
* "called inline here"
* "generic function instantiated here"

An alternative could be these wordings:

* "while analyzing comptime call here"
* "while analyzing inline call here"
* "while analyzing generic instantiation here"

I'm not sure which is better -- but this commit is certainly better than
status quo.
2025-05-16 13:28:15 +01:00
mlugg
d717c96877
compiler: include inline calls in the reference trace
Inline calls which happened in the erroring `AnalUnit` still show as
error notes, because they tend to make very important context (e.g. to
see how comptime values propagate through them). However, "earlier"
inline calls are still useful to see to understand how something is
being referenced, so we should include them in the reference trace.
2025-05-16 13:28:15 +01:00
mlugg
70040778fb
Compilation: fix reference trace behavior without -freference-trace
When `-freference-trace` is not passed, we want to show exactly one
reference trace. Previously, we set the reference trace root in `Sema`
iff there were no other failed analyses. However, this results in an
arbitrary error being the one with the reference trace after error
sorting. It is also incompatible with incremental compilation, where
some errors might be unreferenced. Instead, set the field on all
analysis errors, and decide in `Compilation.getAllErrorsAlloc` which
reference trace[s] to actually show.
2025-05-16 11:55:35 +01:00
Bryson Miller
08d534e8d8
Introduce common strcasecmp and strncasecmp implementations (#23840) 2025-05-15 10:58:33 +02:00
Alex Rønne Petersen
5b606d435d
Merge pull request #21882 from alexrp/compiler-fixes
compiler: Fix some real and theoretical miscompilations with `allowzero` and `volatile`
2025-05-13 10:42:05 +02:00
wooster0
a365971a33 std.meta.intToEnum -> std.enums.fromInt
Also use an optional as the return type instead of an error code.
2025-05-13 07:28:41 +02:00
Alex Rønne Petersen
a3693aae3a
Merge pull request #23856 from alexrp/backport-llvm-120036 2025-05-13 01:08:07 +02:00
Alex Rønne Petersen
bc3c50c21e
Merge pull request #23700 from sorairolake/rename-trims
chore(std.mem): Rename `trimLeft` and `trimRight` to `trimStart` and `trimEnd`
2025-05-12 17:11:52 +02:00
Alex Rønne Petersen
aa7c6dcac1
main: List -f(no-)builtin as per-module options.
Contributes to #23424.
2025-05-12 17:07:50 +02:00
Alex Rønne Petersen
44bf64a709
llvm: Fix a bunch of volatile semantics violations.
Also fix some cases where we were being overzealous in applying volatile.
2025-05-12 17:07:50 +02:00
Alex Rønne Petersen
427810f3ed
llvm: Don't set nonnull attribute on pointers in non-generic address spaces.
LLVM considers null pointers to be valid for such address spaces.
2025-05-12 17:07:50 +02:00
Alex Rønne Petersen
e9ae9a5fc4
llvm: Don't set nonnull attribute on allowzero slices. 2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
e95e7651ec
llvm: Set null_pointer_is_valid attribute when accessing allowzero pointers.
This informs optimization passes that they shouldn't assume that a load from a
null pointer invokes undefined behavior.

Closes #15816.
2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
5c2e300f42
Air: Fix mustLower() to consider volatile for a handful of instructions.
These can all potentially operate on volatile pointers.
2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
47aaaec6ea
Air: Always return true for inline assembly in mustLower().
AstGen requires inline assembly to either have outputs or be marked volatile, so
there doesn't appear to be any point in doing these checks.
2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
4c36a403a8
Air: Fix mustLower() for atomic_load with inter-thread ordering. 2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
d4ca9804f8
riscv64: Handle writes to the zero register sensibly in result bookkeeping. 2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
61ae9a2f45
riscv64: Add missing fence for seq_cst atomic_store. 2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
e40de86082
riscv64: Get rid of some trailing whitespace. 2025-05-12 17:07:49 +02:00
Alex Rønne Petersen
2a55fcd03a
libtsan: Disable warnings when building. 2025-05-12 16:24:59 +02:00
Alex Rønne Petersen
833d4c9ce4
Merge pull request #23835 from alexrp/freebsd-libc
Support dynamically-linked FreeBSD libc when cross-compiling
2025-05-12 01:19:23 +02:00
Alex Rønne Petersen
f3e851dbd0
compiler: Link libc by default when targeting FreeBSD.
We don't yet have a direct syscall layer in std.os.freebsd.
2025-05-11 11:15:23 +02:00
Alex Rønne Petersen
4c2f1e01a7
freebsd: Create strong references to __progname and environ in stub libc.so.
These symbols are defined in the statically-linked startup code. The real
libc.so.7 contains strong references to them, so they need to be put into the
dynamic symbol table.
2025-05-11 11:15:23 +02:00
Alex Rønne Petersen
e8992af7f0
Compilation.Config: Default to dynamic linking with FreeBSD libc. 2025-05-11 11:15:09 +02:00
Alex Rønne Petersen
2116f2e3b2
Compilation: Don't pass -mabi to Clang on powerpc64(le)-freebsd.
The driver doesn't support it, and FreeBSD 13+ on PPC64 uses ELFv2 anyway.
2025-05-10 20:58:28 +02:00
Alex Rønne Petersen
d3a6236eef
compiler: Support building FreeBSD crt1.o/Scrt1.o and stub shared libraries.
Only works for FreeBSD 14+. Note that we still default to targeting FreeBSD 13.

Contributes to #2876.
2025-05-10 20:58:15 +02:00
Alex Rønne Petersen
837e0f9c37 std.Target: Remove ObjectFormat.nvptx (and associated linker code).
Textual PTX is just assembly language like any other. And if we do ever add
support for emitting PTX object files after reverse engineering the bytecode
format, we'd be emitting ELF files like the CUDA toolchain. So there's really no
need for a special ObjectFormat tag here, nor linker code that treats it as a
distinct format.
2025-05-10 12:21:57 +02:00
Alex Rønne Petersen
9e23e1d16c
compiler: Define __FreeBSD_version when targeting FreeBSD libc. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
162b11b250
libcxxabi: Pass -fPIC via module options instead of CFLAGS. 2025-05-10 12:19:26 +02:00
Alex Rønne Petersen
610d3cf9de
compiler: Move vendored library support to libs subdirectory. 2025-05-10 12:19:26 +02:00
David
2c241b263c
Introduce common bzero libc implementation. (#23812)
* Introduce common `bzero` libc implementation.

* Update test name according to review

Co-authored-by: Linus Groh <mail@linusgroh.de>

* address code review

- import common implementation when musl or wasi is included
- don't use `c_builtins`, use `@memset`

* bzero calling conv to .c

* Apply review

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

---------

Co-authored-by: Linus Groh <mail@linusgroh.de>
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2025-05-10 10:37:21 +02:00
Alex Rønne Petersen
85a6b75e18 glibc: Fix stub libraries containing unwanted symbols.
Closes #8096.
2025-05-09 13:16:35 +02:00
mlugg
787020b30b Compilation: don't warn about failure to delete missing C depfile
If clang encountered bad imports, the depfile will not be generated. It
doesn't make sense to warn the user in this case. In fact,
`FileNotFound` is never worth warning about here; it just means that
the file we were deleting to save space isn't there in the first place!
If the missing file actually affected the compilation (e.g. another
process raced to delete it for some reason) we would already error in
the normal code path which reads these files, so we can safely omit the
warning in the `FileNotFound` case always, only warning when the file
might still exist.

To see what this fixes, create the following file...

```c
#include <nonexist>
```

...and run `zig build-obj` on it. Before this commit, you will get a
redundant warning; after this commit, that warning is gone.
2025-05-09 11:52:26 +01:00
xdBronch
10bf6964ed translate-c: fix callconv attribute in macro 2025-05-07 16:15:51 +03:00
Alex Rønne Petersen
7401f06f99 compiler: Set libc++ ABI version to 2 for Emscripten.
It remains 1 everywhere else.

Also remove some code that allowed setting the libc++ ABI version on the
Compilation since there are no current plans to actually expose this in the CLI.
2025-05-05 14:34:05 +02:00
Alex Rønne Petersen
f0feda820e
Merge pull request #23727 from tjog/add-libfuzz-standalone-test
add standalone test for libfuzzer initialization
2025-05-05 07:23:18 +02:00
Xavier Bouchoux
bb79c85cb7 fix system library lookup when cross-compiling to windows-msvc 2025-05-04 10:57:04 +02:00
Alex Rønne Petersen
dffd18f133
Merge pull request #23752 from alexrp/static-native-glibc
compiler: Allow linking native glibc statically
2025-05-04 01:53:51 +02:00
Matthew Lugg
f4e9846bca
Merge pull request #23263 from mlugg/comptime-field-ptr
Sema: fix pointers to comptime fields of comptime-known aggregate pointers
2025-05-03 20:10:42 +01:00
mlugg
f83fe2714b compiler: fix comptime memory store bugs
* When storing a zero-bit type, we should short-circuit almost
  immediately. Zero-bit stores do not need to do any work.
* The bit size computation for arrays is incorrect; the `abiSize` will
  already be appropriately aligned, but the logic to do so here
  incorrectly assumes that zero-bit types have an alignment of 0. They
  don't; their alignment is 1.

Resolves: #21202
Resolves: #21508
Resolves: #23307
2025-05-03 20:10:26 +01:00
tjog
68700e5de1
link+macho+fuzz: use correct input type
A debug build of the compiler detects invalid union access since `classifyInputFile`
detects `.archive` and this line constructed a `.object` input.
2025-05-03 17:23:32 +02:00
Alex Rønne Petersen
bf9b15ee67 std.Target: Add Cpu.Arch.or1k and basic target info. 2025-05-03 11:22:27 +02:00