Commit Graph

19225 Commits

Author SHA1 Message Date
Andrew Kelley
ca3adb83b7
Merge pull request #12111 from ziglang/ci-stage3
CI: increase stage3 test coverage
2022-07-20 17:07:19 -07:00
Andrew Kelley
5b7e332b28 disable new behavior test in stage1
I regressed this in 379beceffd1b0a0b0d8f3163dc02eba1e53ffa39; sorry
about that.
2022-07-20 16:17:33 -07:00
Motiejus Jakštys
fd9b55a640 build.zig: teach --compress-debug-sections
Now that #11863 is landed, let's expose it to the zig programs that
build stuff via `build.zig`. "Benchmarks" with [turbonss](https://git.sr.ht/~motiejus/turbonss):

Built with:

    $ zig build -Dtarget=x86_64-linux-gnu.2.19 -Dcpu=x86_64_v3 -Drelease-small=true

*Debug, uncompressed*

    174K turbonss-analyze
    161K turbonss-getent
    1.2M turbonss-unix2db
    448K libnss_turbo.so.2.0.0

*Debug, compressed*

     78K turbonss-analyze
     86K turbonss-getent
    572K turbonss-unix2db
    190K libnss_turbo.so.2.0.0

*Stripped, for completeness*

     17K turbonss-analyze
     20K turbonss-getent
    197K turbonss-unix2db
     26K libnss_turbo.so.2.0.0
2022-07-20 18:26:17 -04:00
Andrew Kelley
c1f3aca602
Merge pull request #12177 from Vexu/packed-ptr
stage2 llvm: fix handling of pointer fields in packed structs
2022-07-20 18:22:25 -04:00
Andrew Kelley
379beceffd improve test case from previous commit
Now it checks that the code is correctly compiled rather than only checking
that it does not crash the compiler.
2022-07-20 15:21:24 -07:00
Andrew Kelley
21064d9144 disable std lib test failing with self-hosted ReleaseSafe
I opened a corresponding issue #12178 which has the 0.10.0 milestone, so
this must be fixed before we release.
2022-07-20 12:50:58 -07:00
Andrew Kelley
1ec50613bf CI: increase stage3 test coverage
* Use a debug build of stage3 instead of a debug build of stage2 for
   our self-hosted compiler test coverage.
 * Move coverage from stage1 to stage3 for:
   - building self-hosted without LLVM
   - building self-hosted for 32-bit arm
   - test-compiler-rt
   - test-behavior
   - test-std
   - test-compare-output
   - test-asm-link
   - test-fmt
2022-07-20 12:27:03 -07:00
Veikka Tuominen
d41dd499a9 stage2 llvm: fix handling of pointer fields in packed structs 2022-07-20 17:07:12 +03:00
Cody Tapscott
de62bd0647 macho: Pass sections by pointer when slicing names
We were accidentally returning a pointer to stack memory, because these
arguments were passed by value. It's just an accident that stage 1 was
passing these by reference, so things were alright until stage 3.
2022-07-20 03:45:29 -04:00
Andrew Kelley
0efc6a35be Sema: fix enum value without tag name used as switch item
Previously stage2 would report a false positive compile error saying there
was no tag for this value.
2022-07-19 18:39:48 -07:00
Andrew Kelley
1d5f865cfa Sema: fix runtime instructions omitted
in the presence of comptime control flow.

fixes #12171
2022-07-19 17:45:38 -07:00
Andrew Kelley
046df9b7d0
Merge pull request #12131 from hnakamur/fix_big_int_Managed_mul_sqr_capacity_too_large
Fix std.math.big.int.Managed capacity after mul and sqr
2022-07-19 18:54:30 -04:00
Andrew Kelley
6fab6c3e46
Merge pull request #12164 from ziglang/llvm-opt-byref
LLVM: lower optional types as byref=true
2022-07-19 14:50:03 -04:00
Andrew Kelley
fe8c3ffeb1 LLVM: change commentary on isByRef
This branch originally started out as a potential workaround to
address #11450. It did not solve that problem, however, it did end
up fixing #11498!
2022-07-19 11:31:37 -07:00
Andrew Kelley
74fb65fb42 LLVM: lower all error unions as byref=true
Same reasoning as previous commit.
2022-07-19 11:26:19 -07:00
Andrew Kelley
bab570a225 LLVM: lower all structs as byref=true
Same reasoning as previous commit.
2022-07-19 11:26:18 -07:00
Andrew Kelley
65bc4d915d LLVM: lower optional types as byref=true
This is a possible workaround for
https://github.com/llvm/llvm-project/issues/56585

On my computer it makes stage3-release go from false positive
compilation errors on the behavior tests to "segmentation fault".
Is this forwards progress or backwards progress? I have no idea.

See #11450
2022-07-19 11:22:48 -07:00
LeRoyce Pearson
c26d9f6287 Read dynstr starting at rpath offset
Since we know the offset, we may as well read starting there. Still expects
rpath to fit in 4096 bytes; that might be worth fixing in the future.

Fixes issue #12112
2022-07-19 14:01:35 -04:00
Cody Tapscott
b93a38860d stage2: Change optional non-null field to i8
This is a workaround for https://github.com/llvm/llvm-project/issues/56585
which causes writes to i1 in memory to be optimized to an incorrect value.
Unfortunately, this does not save users from running into this bug with u1
in their own types.

However, this does seem to be enough to get the behavior tests working.
This resolves #11450 on my machine.
2022-07-19 13:33:41 -04:00
Veikka Tuominen
0e26c61499 std.fs: remove accidental comptime block 2022-07-17 11:54:13 +03:00
Veikka Tuominen
fcaeca5b0a std.fs: add Iterable versions of openDirAbsolute*
Follow up to 262f4c7b3a
2022-07-17 11:52:30 +03:00
Andrew Kelley
a39c51c6a4 Sema: fix UAF in coerceInMemoryAllowed 2022-07-16 13:48:12 -07:00
Vincent Rischmann
47c58cba59
Fix io_uring tests (#12134)
* io_uring: fix the timeout_remove test

The test does a IORING_OP_TIMEOUT followed with a IORING_OP_TIMEOUT_REMOVE
and assumed we would get the CQEs in the same order.

Linux v5.18 changed how this works and we now get them in the reverse order.

The documentation doesn't explicitly say which CQE we should get first
so just make the test work with both cases.

* io_uring: fix the remove_buffers test

The original test was buggy but accidentally worked with kernels < 5.18

The test assumed that IORING_OP_REMOVE_BUFFERS removed from the start of
but in fact the documentation doesn't specify which buffer is removed,
only that a certain number of buffers are removed.

Starting with the kernel 5.18 the check for the `used_buffer_id` fails.
Turns out that previous kernels removed buffers in such a way that the
remaining buffer for this read would always be 0, however this isn't
true anymore.

Instead of checking a specific value just check that the `used_buffer_id`
corresponds to a valid ID.
2022-07-16 10:05:11 -05:00
alichraghi
9c66fdadc7 std.testing: add refAllDeclsRecursive function 2022-07-16 12:33:25 +03:00
Ryan Liptak
43770c0103 Fix checkAllAllocationFailures being too strict when checking arg types
Before this would fail to compile:

```
fn testFn(alloc: std.mem.Allocator, arr: []const u8) !void {
    _ = alloc;
    _ = arr;
}

test "checkAll" {
    var arr = [_]u8{ 1, 2, 3 };
    try std.testing.checkAllAllocationFailures(std.testing.allocator, testFn, .{arr[0..]});
}
```

with the error `error: Unexpected type for extra argument at index 0: expected []const u8, found *[3]u8`

By removing this strict equality check, we allow the type checking to be done during the `@field(args, arg_i_str) = @field(extra_args, field.name);` instead, which then allows for things like type coercion to work, but still will give a compile error if the types are incorrect. So, after this change, the above succeeds (because `*[3]u8` can be coerced to `[]const u8`).

The new compile error when providing an incorrect type that can't be coerced looks like this:

```
zig/lib/std/testing.zig:639:35: error: expected type '[]const u8', found '*[3]u32'
        @field(args, arg_i_str) = @field(extra_args, field.name);
                                  ^
```
2022-07-16 12:32:20 +03:00
Veikka Tuominen
b2486fbc5e
Merge pull request #12121 from Vexu/span
Stage2 point to error location using spans
2022-07-16 12:22:53 +03:00
Veikka Tuominen
da94227f78
Merge pull request #12060 from Vexu/IterableDir
std.fs: split `Dir` into `IterableDir`
2022-07-16 12:18:21 +03:00
r00ster91
8f943b3d33 style: add missing comma
This is really minor but the issue this fixes is that if you copy-paste this output of `--show-builtin` into your `build.zig` for example then the formatter will format
```
pub const os = std.Target.Os{
    .tag = .freestanding,
    .version_range = .{ .none = {} }
};
```
to
```
pub const os = std.Target.Os{ .tag = .freestanding, .version_range = .{ .none = {} } };
```
which doesn't match the output.
With this comma, the output will stay the way it is after a `zig fmt`.
2022-07-16 09:03:04 +00:00
Hiroaki Nakamura
3e667fd292 Use Managed.len in sub, divFloor, and divTrunc too 2022-07-16 11:46:13 +09:00
Hiroaki Nakamura
0cee8372cf Use Managed.len() instead of Managed.toConst().limbs.len 2022-07-16 08:14:16 +09:00
Andrew Kelley
e867127a6c
Merge pull request #12127 from ziglang/llvm-abi-size
Audit LLVM ABI size
2022-07-15 14:48:21 -04:00
Hiroaki Nakamura
d63604b116 Fix std.math.big.int.Managed capacity after mul and sqr 2022-07-16 00:08:55 +09:00
Luuk de Gram
6ba2fb3db7 zig cc: support -Wl,--export=<symbol> 2022-07-15 16:59:23 +02:00
Jakub Konka
e3c8ba2dc5 ci: bump macOS image on Github Actions to macos-11
The currently used image is getting deprecated and every user is advised
to switch to either macos-11 or macos-12. The link to upstream
issue/notification:

https://github.com/actions/virtual-environments/issues/5583
2022-07-15 07:56:21 -07:00
Veikka Tuominen
cf207df592 Module: improve source spans for initializers and var types
```zig
const U = union { foo: u32, bar: u32 };
test {
    var a = U{ .foo = 1213, .bar = 1123 };
    _ = a;
}
test {
    var a: (123 + 5238094) = 0;
    _ = a;
}
```

before:
```
:30: note: additional initializer here
    var a = U{ .foo = 1213, .bar = 1123 };
                             ^~~
:12: error: expected type 'type', found 'comptime_int'
    var a: (123 + 5238094) = 0;
           ^
```
after:
```
:30: note: additional initializer here
    var a = U{ .foo = 1213, .bar = 1123 };
                            ~^~~~~~~~~~
:12: error: expected type 'type', found 'comptime_int'
    var a: (123 + 5238094) = 0;
           ^~~~~~~~~~~~~~~
```
2022-07-15 16:06:16 +03:00
Veikka Tuominen
1463144fc8 Compilation: point caret in error message at the main token 2022-07-15 15:11:43 +03:00
Veikka Tuominen
262f4c7b3a std.fs: remove OpenDirOptions.iterate 2022-07-15 14:39:21 +03:00
Veikka Tuominen
2b67f56c35 std.fs: split Dir into IterableDir
Also adds safety check for attempting to iterate directory not opened with `iterate = true`.
2022-07-15 13:04:21 +03:00
Yujiri
577f9fdbae doc/langref: clarify behavior of slicing with constant indexes
Fixes #11219.
2022-07-15 10:17:22 +03:00
Kim SHrier
397e6547a9 add FreeBSD support to std.os.getFdPath
This implementation uses the F_KINFO fcntl command added in FreeBSD
13 release. FreeBSD 12 users get a compile error.

Co-authored-by: Stephen Gregoratto <dev@sgregoratto.me>
2022-07-15 10:16:31 +03:00
Andrew Kelley
9329b93b88 LLVM: disable the ABI size safety check
There are many more instances of this check being tripped that we need
to fix before we can enable this.
2022-07-14 23:26:32 -07:00
Andrew Kelley
040cb585e8 LLVM: fix ABI size of optional and error union types
Previously, the Zig ABI size and LLVM ABI size of these types disagreed
sometimes. This code also corrects the logging messages to not trigger
LLVM assertions.
2022-07-14 23:24:57 -07:00
Andrew Kelley
8c14d170b5 Revert "stage2 llvm: Use unpacked struct for unions and arrays"
This reverts commit 2eaef84ebe.

Here is a motivating example:

```zig
const E = union(enum) {
    A: [9]u8,
    B: u64,
};
```

```llvm
%test2.E = type { { i64, [1 x i8] }, i1, [6 x i8] }
```

```
error(codegen): when lowering test2.E, Zig ABI size = 16 but LLVM ABI size = 24
```
2022-07-14 22:26:11 -07:00
Andrew Kelley
9c136be78f LLVM: add padding to optional types when lowering
If the LLVM ABI size does not agree with the Zig ABI size.
2022-07-14 22:26:11 -07:00
Andrew Kelley
070e3ea37d LLVM: insert debug logging when LLVM ABI size is wrong 2022-07-14 22:26:11 -07:00
Andrew Kelley
4c7fe74b2c
Merge pull request #12124 from ziglang/stage2-coerce-result-ptr
Sema: fix coerce_result_ptr in case of inferred result type
2022-07-15 01:06:05 -04:00
Cody Tapscott
dd70336f3a CMake: Use NAMES_PER_DIR in all lookups
CMake has a surprising default behavior where looking up a library by
multiple names gives the name order higher priority than the directory
search order.

For example, if your system provides "llvm-config-14" and
CMAKE_PREFIX_PATH includes "llvm-config", CMake will always end up
choosing the system-provided llvm-config-14.

This change add NAMES_PER_DIR to request the more sensible behavior:
directory search order has higher priority than name order, so
CMAKE_PREFIX_PATH always wins over system-provided tools/libraries.
2022-07-14 22:18:10 -04:00
Andrew Kelley
04572f6e34 Sema: fix coerceResultPtr
It did not handle properly when the dummy operand was a comptime_int; it
was crashing in coerce because comptime_int is supposed to be
comptime-known. So when calling coerceResultPtr, we pass the actual
operand, not a dummy operand, which means it will have the proper
comptime value when necessary.
2022-07-14 18:11:46 -07:00
Andrew Kelley
d7711ec953 print_zir: fix wrong union tag for validate_deref
closes #12125
2022-07-14 17:16:07 -07:00
Andrew Kelley
667ad9250f Sema: fix coerce_result_ptr in case of inferred result type
Previously, the logic for analyzing coerce_result_ptr would generate
invalid bitcast instructions which did not include coercion logic, such
as optional wrapping, resulting in miscompilations.

Now, the logic of resolve_inferred_alloc goes back over all the
placeholders inserted by coerce_result_ptr, and replaces them with logic
doing the proper coercions.

Closes #12045
2022-07-14 16:48:44 -07:00