27052 Commits

Author SHA1 Message Date
Andrew Kelley
54d196bb30
Merge pull request #18057 from Vexu/fixes
Fix bad error location on field init with field access
2023-11-21 15:12:03 -05:00
Andrew Kelley
be6f76655f
Merge pull request #18055 from ziglang/zig-init 2023-11-21 11:59:24 -05:00
Jan Philipp Hafer
27b34a5b77 std.net: enable forcing non-blocking mode for accept
Justification: It is common for non-CPU bound short routines to do
non-blocking accept to eliminate unnecessary delays before subscribing
to data, for example in hardware integration tests.
2023-11-21 18:04:33 +02:00
Garrett
40b8c993f5
translate-c: skip blank macros when translating defines 2023-11-21 13:54:46 +00:00
Michael Pfaff
478c89b46f
std.heap: Use @alignOf(T) rather than 0 if not manually overridden for alignment of MemoryPool items 2023-11-21 13:23:53 +00:00
salo-dea
a58ecf7b09 Do not assume that FILE_BOTH_DIR_INFORMATION is correctly aligned 2023-11-21 15:21:41 +02:00
mataha
dc72f17d80 Reorder fields in build.zig.zon.md
The order of `dependencies` and `minimum_zig_version` was misleading.
2023-11-21 14:23:40 +02:00
Wooster
5d241a1478 std.debug: detect general protection faults on x86_64-linux
```zig
const std = @import("std");

pub fn main() !void {
	var addr: *u8 = @ptrFromInt(0xaaaaaaaaaaaaaaaa);
	addr.* = 1;
}
```

On x86_64-linux:

Before:
```
$ zig run x.zig
Segmentation fault at address 0x0
/home/wooster/Desktop/zig/x.zig:5:5: 0x21d887 in main (x)
    addr.* = 1;
    ^
/home/wooster/Desktop/zig-linux-x86_64/lib/std/start.zig:583:37: 0x21d847 in posixCallMainAndExit (x)
            const result = root.main() catch |err| {
                                    ^
/home/wooster/Desktop/zig-linux-x86_64/lib/std/start.zig:251:5: 0x21d371 in _start (x)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)
```

After:
```
$ zig run x.zig --zig-lib-dir lib
General protection exception
/home/wooster/Desktop/zig/x.zig:5:5: 0x21d907 in main (x)
    addr.* = 1;
    ^
/home/wooster/Desktop/zig/lib/std/start.zig:583:37: 0x21d8c7 in posixCallMainAndExit (x)
            const result = root.main() catch |err| {
                                    ^
/home/wooster/Desktop/zig/lib/std/start.zig:251:5: 0x21d3f1 in _start (x)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
Aborted (core dumped)
```

As @IntegratedQuantum pointed out in <https://github.com/ziglang/zig/issues/17745#issuecomment-1783815386>,
it seems that if `code` of the `siginfo_t` instance is a certain value (128), you are able to distinguish between
a general protection exception and a segmentation fault.

This does not seem to be documented on `man sigaction`:
```
The following values can be placed in si_code for a SIGSEGV signal:

           SEGV_MAPERR
                  Address not mapped to object.

           SEGV_ACCERR
                  Invalid permissions for mapped object.

           SEGV_BNDERR (since Linux 3.19)
                  Failed address bound checks.

           SEGV_PKUERR (since Linux 4.6)
                  Access was denied by memory protection keys.  See pkeys(7).  The protection key which applied to this access is available via si_pkey.
```
(those constants are 1, 2, 3, and 4; none of them are the 128)

I can't find a lot of documentation about this but it seems to work consistently for me on x86_64-linux.
Here is a gist which provides additional evidence that this is a reliable way of checking for a general protection fault:
https://gist.github.com/ytoshima/5682393 (read comment in first line)

See also: https://stackoverflow.com/questions/64309366/why-is-the-segfault-address-null-when-accessing-memory-that-has-any-of-the-16-mo

This only seems to affect x86_64 and on 32-bit x86 this does not seem to be a problem.

Helps with #17745 but doesn't close it because the issue still exists on Windows and other POSIX OSs.

I also limited this to x86_64-linux for now because that's the only platform where I tested it. Might work on more POSIX OSs.
2023-11-21 14:22:11 +02:00
Carl Åstholm
8bf4b3c611 translate-c: translate 80/128-bit long double literals 2023-11-21 14:14:01 +02:00
expikr
40bd93e2a2 replace qpf and qpc
Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update windows.zig

Update ntdll.zig

Update windows.zig

Update ntdll.zig

Update kernel32.zig
2023-11-21 14:10:25 +02:00
Veikka Tuominen
d63298da65 InternPool: handle funcZirBodyInst for func_coerced
Closes #18039
2023-11-21 13:59:14 +02:00
Veikka Tuominen
a947f97331 Sema: fix bad error location on field init with field access
Closes #14753
2023-11-21 13:59:14 +02:00
Naboris
c25f2fa561 std.RingBuffer.zig: Fix typo in readLastAssumeLength 2023-11-21 13:55:09 +02:00
expikr
27353bb936
langref: emphasize the use of dereferencing string literals 2023-11-21 13:54:13 +02:00
Ryan Liptak
15a6b27957 std.unicode: Disable utf8 -> utf16 ASCII fast path on mips
Fixes a compile error when the target is mips, since std.simd.interlace does not work correctly on mips and raises a compile error if it is used.
2023-11-21 13:51:03 +02:00
Bogdan Romanyuk
583afd6f0c
value: update isDeclRef for anonymous declarations 2023-11-21 13:21:32 +02:00
Andrew Kelley
9f363cd679 zig init: also create a build.zig.zon 2023-11-20 23:30:51 -07:00
Andrew Kelley
f645022d16 merge zig init-exe and zig init-lib into zig init
Instead of `zig init-lib` and `zig init-exe`, now there is only
`zig init`, which initializes any of the template files that do not
already exist, and makes a package that contains both an executable and
a static library. The idea is that the user can delete whatever they
don't want. In fact, I think even more things should be added to the
build.zig template.
2023-11-20 23:01:45 -07:00
Maciej 'vesim' Kuliński
f64f3423e4 std.tar: trim also spaces from the beginning of file size 2023-11-21 00:55:22 -05:00
Tw
8ca4a5240e linux/bpf: update helper definitions
Signed-off-by: Tw <tw19881113@gmail.com>
2023-11-19 19:01:18 +02:00
Matthew Lugg
6b1a823b2b
Merge pull request #18017 from mlugg/var-never-mutated
compiler: add error for unnecessary use of 'var'
2023-11-19 16:19:06 +00:00
mlugg
9cf6c1ad11
behavior: work around LLVM bug
See #18034
2023-11-19 11:11:50 +00:00
mlugg
766306793a
std: correct faulty test 2023-11-19 11:11:50 +00:00
mlugg
ff838d8631
translate-c: work around unnecessary uses of 'var' 2023-11-19 11:11:50 +00:00
mlugg
3c585730f2
AstGen: preserve result type in comptime block 2023-11-19 11:11:50 +00:00
mlugg
38b373bf0b
cases: add compile error test for never-mutated local variable 2023-11-19 11:11:50 +00:00
mlugg
b355893438
compiler: correct unnecessary uses of 'var' 2023-11-19 11:11:49 +00:00
mlugg
172c2797bd
link: fix MachO boundary symbol resolution 2023-11-19 11:11:49 +00:00
mlugg
ed4bab66d8
langref: correct unnecessary uses of 'var' 2023-11-19 11:11:49 +00:00
mlugg
026a8278f8
tools: correct unnecessary uses of 'var' 2023-11-19 09:57:04 +00:00
mlugg
d82d327de2
test: update remaining code to fix 'var is never mutated' errors 2023-11-19 09:57:04 +00:00
mlugg
9c16b2370d
test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
mlugg
21fa187abc
test: update cases to silence 'var is never mutated' errors 2023-11-19 09:56:51 +00:00
mlugg
2c1acb6180
test: update translate-c tests to match new discard format 2023-11-19 09:55:07 +00:00
mlugg
51595d6b75
lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
mlugg
baabc6013e
compiler: add error for unnecessary use of 'var'
When a local variable is never used as an lvalue, we can determine that
`const` would be sufficient for this variable, so emit an error in this
case. More sophisticated checking is unfortunately not possible with
Zig's current analysis model, since whether an lvalue is actually
mutated depends on semantic analysis, in which some code paths may not
be analyzed, so attempting to determine this would result in false
positive compile errors.

It's worth noting that an unfortunate consequence of this is that any
field call `a.b()` will allow `a` to be `var`, even if `b` does not take
a pointer as its first parameter - this is again a necessary compromise
because the parameter type is not known until semantic analysis.

Also update `translate-c` to not trigger these errors. This is done by
replacing the `_ = @TypeOf(x)` emitted with `_ = &x` - the reference
there means that the local is permitted to be `var`. A similar strategy
will be used to prevent compile errors in the behavior tests, where we
sometimes want to force a value to be runtime-known.

Resolves: #224
2023-11-19 09:55:07 +00:00
dweiller
325e0f5f0e test: check compile errors when compilation has no errors 2023-11-19 00:12:43 +02:00
Eric Joldasov
4e212f1650 std.enums: allow non-exhaustive enums in EnumIndexer and make count comptime_int instead of usize
Seems like this restriction was actual when Ziglang had extern enums,
but now it's not neccessary and can be lifted. It was present since
original PR which introduced std.enums, https://www.github.com/ziglang/zig/pull/8171.
See also: https://ziggit.dev/t/catching-invalid-enum-value-errors/2206/11

* Make `count` comptime_int instead of usize

With previous type, creating EnumIndexer for enum(usize) and enum(isize)
would cause compile error since `count` could not store maxInt(usize) + 1.
Now it can store it and reflects len field from std.builtin.Type.Array
(most common use case of count field inside std.enums functions is creating arrays).

Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-11-18 16:25:55 +02:00
Curtis Tate Wilkinson
7b99189f19
Add struct declaration location to empty root struct field member error 2023-11-18 12:03:10 +00:00
Lucas Santos
d44f822821 Faster implementation of intToEnum. 2023-11-18 11:24:13 +02:00
Jakub Konka
91329ce944 std.macho: fix LoadCommandIterator to work with underaligned data 2023-11-17 20:49:32 +01:00
Veikka Tuominen
5f86414019
Merge pull request #18006 from Vexu/aro-translate-c
Sync Aro dependency & translate-c progress
2023-11-17 09:02:11 +02:00
Veikka Tuominen
acebf05be9 aro-translate-c: update to upstream changes 2023-11-17 09:01:25 +02:00
David
673a1efa22
Sema: include sentinel in type of pointer-to-array ptr field
Resolves: #18007
2023-11-16 16:08:30 +00:00
Jakub Konka
b173088089
Merge pull request #18015 from ziglang/elf-tests
More ELF tests
2023-11-16 16:11:24 +01:00
David
941090d94f
Move duplicate field detection for struct init expressions into AstGen
Partially addresses #17916.
2023-11-16 14:38:16 +00:00
Jakub Konka
85c0485fd9 elf: test -r mode does not create unneeded .eh_frame section 2023-11-16 10:54:39 +01:00
Jakub Konka
f6bf3353b1 elf: test -r mode with archive on the linker line 2023-11-16 10:51:21 +01:00
Krzysztof Wolicki
acf9de376d
Sema: Add error for non-power of 2 field alignment when reifying Unions, Structs, Pointers 2023-11-16 10:19:54 +02:00
Jakub Konka
359842f8d5
Merge pull request #18010 from ziglang/elf-symtab-fixes
elf: actually write synthetic globals to output symtab and other misc fixes
2023-11-16 01:18:22 +01:00