Commit Graph

17489 Commits

Author SHA1 Message Date
Mitchell Hashimoto
67647154c1
stage2: apply fix for #11165 to codegen.zig for native backends
Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
2022-03-14 20:00:17 -07:00
Mitchell Hashimoto
a859f94644
stage2: LLVM codegen of arrays should use type length, not value length
It is possible for the value length to be longer than the type because
we allow in-memory coercing of types such as `[5:0]u8` to `[5]u8`. In
such a case, the value length is 6 but the type length if 5.

The `.repeated` value type already got this right, so this is extending
similar logic out to `.aggregate` and `.bytes`. Both scenarios are
tested in behavior tests.

Fixes #11165
2022-03-14 17:41:12 -07:00
Andrew Kelley
5ea94e7715 stage2: rework Value storage of structs and arrays
Now they both use `Value.Tag.aggregate`.

Additionally the LLVM backend now has implemented lowering of
tuple values.
2022-03-14 12:28:52 -07:00
Mitchell Hashimoto
1ebe3bd01d
stage2: reify structs and tuples (#11144)
Implements `@Type` for structs, anon structs, and tuples. This is another place that would probably benefit from a `.reified_struct` type tag but will defer for later in the interest of getting tests passing first.
2022-03-14 13:47:35 -04:00
Andrew Kelley
5919b10048
Merge pull request #11155 from ziglang/stage2-float-fixes
stage2 float fixes
2022-03-14 12:38:56 -04:00
Andrew Kelley
b2a1b4c085 Sema: improve lowering of stores to bitcasted vector pointers
Detect if we are storing an array operand to a bitcasted vector pointer.
If so, we instead reach through the bitcasted pointer to the vector pointer,
bitcast the array operand to a vector, and then lower this as a store of
a vector value to a vector pointer. This generally results in better code,
as well as working around an LLVM bug.

See #11154
2022-03-14 00:11:46 -07:00
Andrew Kelley
eee989d2a0 Sema: Type.abiSize asserts instead of using max with alignment
ABI size is guaranteed to always be >= alignment.
2022-03-14 00:11:46 -07:00
Andrew Kelley
2a50a4629b freestanding libc: include roundl 2022-03-14 00:11:46 -07:00
Andrew Kelley
547e6f6ee1 disable failing nvptx test cases
See #10968
2022-03-14 00:11:46 -07:00
Andrew Kelley
7a477a1110 LLVM: fix int_to_float signedness detection
It was checking if the result (float) type was a signed int rather than
checking the operand (integer) type.
2022-03-14 00:11:46 -07:00
Andrew Kelley
d42d31f72f basic language features do not belong in std.meta 2022-03-14 00:11:46 -07:00
Andrew Kelley
eeaaefb925 LLVM: fix debug info for local vars
Previously we incorrectly used the pointer type as the debug info type.
2022-03-14 00:11:46 -07:00
Koakuma
cb3b1dd6dd c/linux: Fix stat struct definition for SPARCv9
The libc interface uses `stat` instead of `stat64` struct.
This fixes, among other things, `zig fmt` accidentally setting the
formatted file's permission to 000.
2022-03-13 16:48:02 -04:00
Joachim Schmidt
bb859a0be7
Merge pull request #11150 from joachimschmidt557/stage2-aarch64
stage2 AArch64: misc improvements
2022-03-13 18:43:18 +01:00
Jakub Konka
76bceb240d std+macho: revert and fix exposing Mach wrappers in std.os and std.c 2022-03-13 17:03:04 +01:00
Jakub Konka
4a2100e820 std: more c/darwin.zig fixes 2022-03-13 15:42:40 +01:00
Jakub Konka
1af0c75d71 std: fix imports for darwin specific flags and funcs 2022-03-13 14:59:15 +01:00
Jakub Konka
68c224d6ec macho: simplify writing atoms for stage2
Also, fix premature exit in `link.File.makeWritable` in case we
are running M1 but executing binaries using Rosetta2.
2022-03-13 14:15:26 +01:00
Jakub Konka
633c4a2a60 macos: add Mach task abstraction
`std.os.darwin.MachTask` wraps `mach_port_t` and can be used to issue
kernel calls tied to the wrapped Mach kernel port/task.
2022-03-13 13:35:39 +01:00
joachimschmidt557
b74cd902c6
stage2 AArch64: enable mul for ints with <= 64 bits 2022-03-13 11:32:08 +01:00
joachimschmidt557
1f28c72c39
stage2 AArch64: implement ptr_add for all element sizes 2022-03-13 11:32:08 +01:00
joachimschmidt557
384e4ddb06
stage2 AArch64: spill compare flags when necessary 2022-03-13 11:32:08 +01:00
joachimschmidt557
12207bbbd6
stage2 AArch64: Implement bit shifting with immediate operands 2022-03-13 11:32:07 +01:00
joachimschmidt557
03dddc8d9c
stage2 AArch64: implement bit shifts with register operands 2022-03-13 11:32:04 +01:00
Jakub Konka
2036af94e9 macos: add kernel return values 2022-03-13 10:49:09 +01:00
Jakub Konka
a60292dfb3 macos: add more mach primitives 2022-03-13 09:42:24 +01:00
Andrew Kelley
0bc9635490 stage2: add debug info for locals in the LLVM backend
Adds 2 new AIR instructions:
 * dbg_var_ptr
 * dbg_var_val

Sema no longer emits dbg_stmt AIR instructions when strip=true.

LLVM backend: fixed lowerPtrToVoid when calling ptrAlignment on
the element type is problematic.

LLVM backend: fixed alloca instructions improperly getting debug
location annotated, causing chaotic debug info behavior.

zig_llvm.cpp: fixed incorrect bindings for a function that should use
unsigned integers for line and column.

A bunch of C test cases regressed because the new dbg_var AIR
instructions caused their operands to be alive, exposing latent bugs.
Mostly it's just a problem that the C backend lowers mutable
and const slices to the same C type, so we need to represent that in the
C backend instead of printing two duplicate typedefs.
2022-03-13 03:41:31 -04:00
Mitchell Hashimoto
7ec2261dbf stage2: add compiler test to ensure typed null doesn't coerce to any
In stage1, this behavior was allowed (by accident?) and also
accidentally exercised by the behavior test changed in this commit. In
discussion on Discord, Andrew decided this should not be allowed in
stage2 since there is currently on real world reason to allow this
strange edge case.

I've added the compiler test to solidify that this behavior should NOT
occur and updated the behavior test to the new valid semantics.
2022-03-12 22:03:01 -05:00
Andrew Kelley
804b82b6e8
Merge pull request #11130 from mitchellh/reify-enum
stage2: zirReify for enums
2022-03-12 16:20:43 -05:00
Guillaume Wenzek
f000f8a59a fix nvptx test failure #10968
allow test cases to chose wether to link libc or not.
default behavior is to not link libc, except for `exeUsingLLVMBackend`
2022-03-12 14:25:59 -05:00
Andrew Kelley
5ff7b04a6a
Merge pull request #11133 from Vexu/stage2
stage2: misc fixes on the way to `std.debug.dumpCurrentStackTrace`
2022-03-12 14:18:58 -05:00
Mitchell Hashimoto
ef68420b78
stage2: reify opaque {} 2022-03-12 11:02:24 -08:00
joachimschmidt557
01081ce5a5 stage2 x86_64: Fix assertion in getResolvedInstValue 2022-03-12 18:33:25 +01:00
Veikka Tuominen
d532c21d89 AstGen: fix nosuspendExpr handling result location twice 2022-03-12 13:42:17 +02:00
Veikka Tuominen
487ee79ec9 stage2 llvm: do not use getIntrinsic for airFrameAddress
getIntrinsic gets the return type wrong so we have to add the function manually
2022-03-12 12:33:32 +02:00
Veikka Tuominen
a3cfb15fb4 Sema: always allow coercing error set to current inferred error set 2022-03-12 11:36:05 +02:00
Veikka Tuominen
07cc2fce2a Sema: fix else branch check when switching on error set 2022-03-12 11:25:37 +02:00
Veikka Tuominen
98a01f99c9 Sema: fix typo in resolvePeerTypes 2022-03-12 11:14:17 +02:00
matu3ba
e5d4a694ea
std: add test for child_process
- Cli operations should be refactored, since the standard test runner
  has an expected argument structure. This would also ensure that the
  test cli is usable as tested library with checks for subprocess
  error or success instead of "hacky shell script interfaces".
- Default paths generation based on tmpDir would also be useful.
- Anonymous pipes on windows are generated from named pipes
- Async IO does not work on anonymous pipes
- Remove finished TODO
2022-03-12 10:25:18 +02:00
ominitay
42d75f1a25 std.math.lossyCast: fix integer overflow
Fixes integer overflow caused by cast from maxInt(u32) as an f32 to u32.
2022-03-12 10:23:57 +02:00
Andrew Kelley
b3259b47ad Type.eql: check fn attributes before params
slightly better for cache locality
2022-03-11 22:49:08 -07:00
Andrew Kelley
f6b479b81d LLVM: use hasRuntimeBitsIgnoreComptime instead of hasRuntimeBits
LLVM codegen doesn't care whether types are comptime or not. Comptime
types aren't supposed to make it to codegen anyway.
2022-03-11 22:48:35 -07:00
Andrew Kelley
98c950827f std.math: remove redundant namespace in test names
related: #7923
2022-03-11 22:47:45 -07:00
Andrew Kelley
0f3e849719 std.ArrayList: use variable for local mutable state
stage1 has the wrong semantics here
2022-03-11 22:47:24 -07:00
Mitchell Hashimoto
237d08389a
stage2: use usizecast for safety 2022-03-11 21:37:41 -08:00
Mitchell Hashimoto
744b4ad578
stage2: reify should use pointerDecl to get array value 2022-03-11 21:36:06 -08:00
Mitchell Hashimoto
08159be375
stage2: enum field length must be a usize 2022-03-11 21:21:29 -08:00
Andrew Kelley
491e3ba6b1 LLVM: fix debug info for pointers to void 2022-03-11 21:00:07 -07:00
Andrew Kelley
60d6037f23 Sema: fix inline/comptime function calls with inferred errors 2022-03-11 20:44:10 -07:00
Andrew Kelley
55ba335e0f Sema: fix resolution of inferred error sets
Introduce `Module.ensureFuncBodyAnalyzed` and corresponding `Sema`
function. This mirrors `ensureDeclAnalyzed` except also waits until the
function body has been semantically analyzed, meaning that inferred
error sets will have been populated.

Resolving error sets can now emit a "unable to resolve inferred error
set" error instead of producing an incorrect error set type. Resolving
error sets now calls `ensureFuncBodyAnalyzed`. Closes #11046.

`coerceInMemoryAllowedErrorSets` now does a lot more work to avoid
resolving an inferred error set if possible. Same with
`wrapErrorUnionSet`.

Inferred error set types no longer check the `func` field to determine if
they are equal. That was incorrect because an inline or comptime function
call produces a unique error set which has the same `*Module.Fn` value for
this field. Instead we use the `*Module.Fn.InferredErrorSet` pointers to
test equality of inferred error sets.
2022-03-11 19:38:07 -07:00