24750 Commits

Author SHA1 Message Date
Jacob Young
8d30cb3f22 x86_64: turn f80 operation crashes into errors 2023-06-25 19:14:03 -04:00
Jacob Young
b18a72ec35 x86_64: fix crash emitting a packed undefined u128 2023-06-25 19:14:03 -04:00
Jacob Young
054536f343 x86_64: fix unimplemented type crashes 2023-06-25 19:14:03 -04:00
Jacob Young
614c807702 x86_64: fix packed store crash 2023-06-25 19:14:03 -04:00
Maciej 'vesim' Kuliński
d98147414d update Ascon.zig to use @min builtin 2023-06-25 15:39:17 -07:00
Eric Joldasov
0a868dacdd std.cstr: deprecate namespace
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-25 14:51:03 -07:00
Jakub Konka
852eb272bf macho: add fixes to __eh_frame parsing emitted by Nix C++ compiler 2023-06-25 14:33:00 -07:00
Andrew Kelley
df389b62de
Merge pull request #16192 from mlugg/builtins-infer-dest-ty-fixes
Follow-up to cast builtin result type inference
2023-06-25 12:38:56 -07:00
David CARLIER
d07149c56d std.c: few freebsd's kinfo api fixes.
following up on 4a0508e and 3dd0afe.

- kinfo_vmentry, removing kve_ prefix.
- kinfo_getproc, returns one entry at most.
2023-06-25 12:27:45 -07:00
Jacob Young
b9c4857ed6 AstGen: add source location to certain const initializers
Before:

    assign_local_bad_coercion.zig:5:1: error: expected type 'u32', found 'u64'
    export fn constEntry() u32 {
    ^~~~~~
    assign_local_bad_coercion.zig:11:19: error: expected type 'u32', found 'u64'
        var x: u32 = g();
                     ~^~

After:

    assign_local_bad_coercion.zig:6:21: error: expected type 'u32', found 'u64'
        const x: u32 = g();
                       ~^~
    assign_local_bad_coercion.zig:11:19: error: expected type 'u32', found 'u64'
        var x: u32 = g();
                     ~^~
2023-06-25 12:00:48 -07:00
Evin Yulo
17e12960b5 remove mention of stage1 from langref 2023-06-25 21:13:56 +03:00
mlugg
fec7565da6
behavior: add tests for cast builtins coercing to optional and error union 2023-06-25 13:28:32 +01:00
mlugg
d249629ef1
cases: add tests for errors introduced by cast builtin result type inference 2023-06-25 13:28:32 +01:00
mlugg
569ae762e1
compiler: allow cast builtins to coerce result to error union or optional
Also improves some error messages
2023-06-25 13:28:32 +01:00
mlugg
8afadee45a
AstGen: use usize as result type of for loop range operands 2023-06-25 13:28:31 +01:00
mlugg
5311916928
langref: neaten up @errSetCast example 2023-06-25 13:28:31 +01:00
Josh Wolfe
3f04231600 std: re-pub new json symbols in json.zig 2023-06-25 04:56:38 -07:00
Frank Denis
e7f872c9c6
wasi-libc: compile emmalloc.c without strict aliasing (#16157)
emmalloc.c does a fair amount of type punning in order to access
the size of memory regions and traverse them.

Unfortunately, that can lead to unwanted optimizations.

This simple test case currently triggers a memory fault:

int main(void) {
    char * volatile p = malloc(1);
    p = realloc(p, 12);
    p = malloc(1);
    printf("%p\n", p);
}

Work around this by adding "-fno-strict-aliasing" when compiling
that file.
2023-06-25 11:24:54 +02:00
Ryan Liptak
b111702940 Recognize the .res extension and link it as if it were an object file
.res files are compiled Windows resource files that get linked into executables/libraries. The linker knows what to do with them, but previously you had to trick Zig into thinking it was an object file (by renaming it to have the .obj extension, for example).

After this commit, the following works:

    zig build-exe main.zig resource.res

or, in build.zig:

    exe.addObjectFile("resource.res");

Closes #6488
2023-06-25 01:42:12 -07:00
Andrew Kelley
9684947faa compiler: start moving safety-checks into backends
This actually used to be how it worked in stage1, and there was this
issue to change it: #2649

So this commit is a reversal to that idea. One motivation for that issue
was avoiding emitting the panic handler in compilations that do not have
any calls to panic. This commit only resolves the panic handler in the
event of a safety check function being emitted, so it does not have that
flaw.

The other reason given in that issue was for optimizations that elide
safety checks. It's yet to be determined whether that was a good idea or
not; this can get re-explored when we start adding optimization passes
to AIR.

This commit adds these AIR instructions, which are only emitted if
`backendSupportsFeature(.safety_checked_arithmetic)` is true:
 * add_safe
 * sub_safe
 * mul_safe

It removes these nonsensical AIR instructions:
 * addwrap_optimized
 * subwrap_optimized
 * mulwrap_optimized

The safety-checked arithmetic functions push the burden of invoking the
panic handler into the backend. This makes for a messier compiler
implementation, but it reduces the amount of AIR instructions emitted by
Sema, which reduces time spent in the secondary bottleneck of the
compiler. It also generates more compact LLVM IR, reducing time spent in
the primary bottleneck of the compiler.

Finally, it eliminates 1 stack allocation per safety-check which was
being used to store the resulting tuple. These allocations were going to
be annoying when combined with suspension points.
2023-06-25 01:41:08 -07:00
Andrew Kelley
82ad66b2f2 liveness: fix merge typo logic error
Oops, I made a terrible mistake when applying a small fixup when merging
f10b9e8fd72aae33b127c18e3f8a64a4f56b1b69.
2023-06-25 01:02:55 -07:00
Andrew Kelley
a31ba25a3d
Merge pull request #16188 from kcbanner/fix_cbe_airErrUnionPayloadPtrSet
cbe: fix crash caused by calling `mod.intValue` on `type_inferred_error_set`
2023-06-24 21:53:59 -07:00
Andrew Kelley
146b79af15
Merge pull request #16163 from mlugg/feat/builtins-infer-dest-ty
Infer destination type of cast builtins using result type
2023-06-24 16:58:19 -07:00
mlugg
21ac0beb43 update zig1.wasm
Needed due to the breaking changes to casting builtins, which are used
by the compiler when building itself.

Note from Andrew: I re-ran update-zig1 on my PC and replaced this
commit.

Signed-off-by: Andrew Kelley <andrew@ziglang.org>
2023-06-24 16:56:54 -07:00
mlugg
67997a699a cbe: codegen int_from_ptr of slice correctly
CBE was translating to access the `len` field rather than `ptr`.
Air.zig specifies that this operation is valid on a slice.
2023-06-24 16:56:40 -07:00
mlugg
a84a895325 langref: update to new cast builtin syntax 2023-06-24 16:56:39 -07:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00
mlugg
447ca4e3ff translate-c: update to new cast builtin syntax 2023-06-24 16:47:49 -07:00
mlugg
283d650973 fmt: add rewrite for cast builtin type parameters 2023-06-24 16:47:49 -07:00
mlugg
be0c69957e compiler: remove destination type from cast builtins
Resolves: #5909
2023-06-24 16:47:49 -07:00
Jakub Konka
13853bef0d cmake: fix typo in flag value for single threaded build 2023-06-24 13:51:42 -07:00
Matteo Briani
8ced903d61
Add support for the "--version" linker argument (#16154)
closes #15549

Co-authored-by: Matteo Briani <matteo.briani@icvox.com>
2023-06-24 16:24:50 -04:00
Jacob Young
d3fed1a87e cbe: fix another instance of calling intValue with an error type 2023-06-24 16:22:00 -04:00
David CARLIER
72dd22f262 std.c: fix few capcisum api calls, following-up on 6ae19fa.
only variadic calls are prefixed with underscores.

ref: 59833b089e/sys/sys/capsicum.h (L326)
2023-06-24 13:05:45 -07:00
Andrew Kelley
7ad1042279 Revert "fix parseInt failing when a correct base is given"
This reverts commit fa6cea22bf9cd5ff6a9dd882166cf7e479acfd6c.

Apologies for the merge. I thought this was a bug fix, but I see that it
is implementing a proposal that I intended to reject.
2023-06-24 13:03:51 -07:00
Mikko Kaihlavirta
fa6cea22bf fix parseInt failing when a correct base is given 2023-06-24 13:02:45 -07:00
David CARLIER
ea1d64dae4 std.c: fix host_basic_info definition for darwin.
follow-up on ff59c45.

ref: a5e15eced0/lib/libc/include/any-macos-any/mach/host_info.h (L116)
2023-06-24 13:00:14 -07:00
David CARLIER
e9dd0a22f0 std.c: freebsd fix typo for PROC.PROCCTL_MD_MIN constant.
follow-up on 2e2d379.
2023-06-24 12:59:18 -07:00
Xavier Bouchoux
f10b9e8fd7 update Liveness to detect that safety checks do not modify memory
followup to [25d3713b07a100d8fdb349317db97fd9d0c1e366]
Resolves #12215

Previous code didn't account for the extra unreach() that now exists in the air:

```
 %29!= block(void, {
    %30!= cond_br(%22!, {
      %31!= br(%29, @Air.Inst.Ref.void_value)
    }, {
      %2! %15!
      %27!= call(%26, [%19!, %21])
      %28!= unreach()
    })
  } %22!)
```
2023-06-24 12:57:46 -07:00
kcbanner
baa2b62e88 cbe: fix crash caused by calling mod.intValue on type_inferred_error_set 2023-06-24 13:49:24 -04:00
Andrew Kelley
a5e15eced0 LLVM: move many DeclGen methods to Object
DeclGen/FuncGen methods are for things that pertain to a particular
declaration or function, while Object methods are for things that
pertain to the entire LLVM Module. Many methods were in the wrong
category, such as type and value lowering.

This is a prerequisite commit for a local branch I am working on, which
needs to be able to call lowerValue() without the context of any
particular function or declaration.
2023-06-24 02:29:49 -07:00
r00ster91
d82ab4fd8a ErrorBundle: fix integer overflow printing caret 2023-06-23 23:58:21 -07:00
Andrew Kelley
b129f1b046
Merge pull request #16037 from Jan200101/PR/cmakedefine-fix
Correct cmakedefine implementation
2023-06-23 23:56:18 -07:00
Ali Chraghi
ff0a88b133 spirv: fix a few conflicts caused by intern-pool 2023-06-23 23:52:45 -07:00
Michael Dusan
1cf06706be openbsd: fix NativeTargetInfo semver
- supply ".0" as .Z component and satisfy semver X.Y.Z requirement
- previously only X.Y was supplied and semver parse failed
2023-06-23 23:41:29 -07:00
Zachary Raineri
148e2a5a89
Removed unnecessary return switch on void method
Removed an unnecessary "return switch" on the Atomic.store method
2023-06-24 05:12:07 +00:00
Andrew Kelley
5288929ffd sema.addConstant: remove type parameter
Now that InternPool migration is finished, all values have types. So
only the value parameter is required.
2023-06-23 21:59:42 -07:00
kcbanner
5fc5e4fbe0 sema: Fix overflow when analyzing an inline switch prong range that ends on the maximum value of the switched type 2023-06-23 18:28:33 -07:00
kcbanner
9d66481e3d llvm: fixup elem_count argument of ZigLLVMCreateDebugArrayType to be i64
The signature is `getOrCreateSubrange(int64_t  Lo, int64_t  Count)`, so this updates the bindings to match.

This fixes a crash in `lowerDebugTypeImpl` when analyzing slices that have a length of 2^32 or
larger (up to `2^64 >> 3`, which still crashes, because above that the array size in bits overflows u64).
2023-06-23 14:53:17 -07:00
Ed Yu
8dcb4a3dc4 std.http: fix the http.Client.wait() hanging when there is 1 more byte left 2023-06-23 20:18:24 +02:00