Commit Graph

5361 Commits

Author SHA1 Message Date
Veikka Tuominen
7f9e841f74 Sema: do not forcibly canonicalize unresolved pointer element type
Closes #13308
2022-12-03 00:09:23 +02:00
Veikka Tuominen
59dad43de2 Sema: add error for failed assumption about struct having runtime bits 2022-12-02 18:46:59 +02:00
Veikka Tuominen
86e6acb37b AstGen: improve error message for missing parameter name
Closes #13393
2022-12-02 15:39:40 +02:00
Andrew Kelley
665eba93c1 CBE: eliminate zig_void
C void is perfectly fine.
2022-12-02 00:46:27 -05:00
Andrew Kelley
4071b22454
Merge pull request #13715 from Vexu/cbe
cbe bug fixes and improvements
2022-12-01 17:38:11 -05:00
Veikka Tuominen
6ded2d2adb cbe: disable failing behavior test on aarch64 2022-12-01 12:18:10 +02:00
Veikka Tuominen
d0edaabf9d Value: fix elemValueAdvanced for optional payloads
Closes #13707
2022-12-01 11:49:06 +02:00
Andrew Kelley
a943422672
Merge pull request #13717 from GethDW/option-fix
std.build.Builder: fix for Allocator changes
2022-11-30 19:43:51 -05:00
Andrew Kelley
b1793c2b52 add test coverage for zig build CLI and options API 2022-11-30 13:22:43 -07:00
Luuk de Gram
090deae41d
wasm: enable behavior tests for packed structs 2022-11-30 21:01:09 +01:00
Veikka Tuominen
11ec7109c3 cbe: do not memcpy identical integer types when bitcasting 2022-11-30 17:11:06 +02:00
Veikka Tuominen
15cc83e27a cbe: reduce amount of temporary locals 2022-11-30 17:11:06 +02:00
Veikka Tuominen
f4afeb3ffd AstGen: fix incorrect handling of source cursor with shift builtins
Closes #13714
2022-11-30 17:11:06 +02:00
Veikka Tuominen
2dcac348e5 cbe: implement packed unions 2022-11-30 15:14:33 +02:00
Veikka Tuominen
1a1a5702ab cbe: correctly handle pointers to zero bit error union payloads 2022-11-30 15:14:33 +02:00
Veikka Tuominen
4def9c4a9b cbe: operand of address of operator must be an lvalue 2022-11-30 15:14:33 +02:00
Veikka Tuominen
6310186d52 cbe: cast pointer switch target to int 2022-11-30 15:14:33 +02:00
Veikka Tuominen
8af5648015 Sema: make inferred allocs always mutable
Const allocs don't make any sense, make_ptr_const handles making
the pointers not mutable.
2022-11-30 15:14:33 +02:00
Veikka Tuominen
63ae7899ae cbe: ensure test and tagName function names are unique 2022-11-30 15:14:33 +02:00
Andrew Kelley
ceb0a632cf std.mem.Allocator: allow shrink to fail
closes #13535
2022-11-29 23:30:38 -07:00
Andrew Kelley
deda6b5146 LLVM: fix canElideLoad behavior with loops
closes #13546
2022-11-30 00:20:49 -05:00
Veikka Tuominen
b2b1d421c3 Sema: add missing failWithBadMemberAccess to zirExport
The assumption that AstGen would error only holds when exporting
a identifier not a namespace member.
2022-11-29 21:44:08 +02:00
Veikka Tuominen
4b0ef6a409 Sema: make non-existent field error point to field name
Closes #13698
2022-11-29 21:44:08 +02:00
Veikka Tuominen
6f5a438946 AstGen: unstack block scope when creating opaque type
Closes #13697
2022-11-29 21:44:08 +02:00
Veikka Tuominen
ed73429926 Sema: explain why parameter must be declared comptime
Closes #13692
2022-11-29 21:44:08 +02:00
Veikka Tuominen
17ff002bc0 Sema: improve safety panic for access of inactive union field 2022-11-29 21:44:08 +02:00
Veikka Tuominen
6337c04244 Sema: improve panic for slice start index being greater than end index
Closes #13689
2022-11-29 15:47:02 +02:00
Veikka Tuominen
6f9c7e33b9 llvm: implement union_init for packed unions
Closes #13664
2022-11-29 15:47:02 +02:00
Jakub Konka
1829b6eab8
Merge pull request #13625 from kcbanner/windows_disable_symlink_tests
Skip linker tests requiring symlinks on Windows
2022-11-29 02:57:37 +01:00
Jakub Konka
033aa1d761 aarch64-windows: skip failing standalone tests 2022-11-28 19:45:53 -05:00
Jakub Konka
870872dd63 aarch64-windows: skip failing floatop behavior test 2022-11-28 18:10:51 -05:00
Jakub Konka
07bf4de6a9 aarch64-windows: skip failing align behavior test 2022-11-28 18:10:51 -05:00
kcbanner
ea84eda904 'fmt' 2022-11-26 17:16:56 -05:00
Veikka Tuominen
304e828088
Merge pull request #13637 from Vexu/stage2-fixes
Stage2 bug fixes
2022-11-26 22:03:49 +02:00
kcbanner
57bc61ab26 test-link: add -Denable-symlinks-windows to opt-in to using symlinks
Adds a way for standalone tests to declare they need symlinks, and these
tests won't be run on windows unless -Denable-symlinks-windows is set
2022-11-26 14:26:26 -05:00
Veikka Tuominen
71937f75d8 Sema: correctly detect union target in zirSwitchBlock
Closes #13655
2022-11-26 18:05:27 +02:00
Veikka Tuominen
fe38898246 Sema: pass c_import_buf to child block in more places
Closes  #13651
2022-11-26 18:05:27 +02:00
Veikka Tuominen
587ef60a28 Sema: resolve union fields before using getTagType
Closes #13649
2022-11-26 18:05:27 +02:00
Veikka Tuominen
bf62cb453b Sema: handle anytype parameter requiring comptime
Closes #13645
2022-11-26 18:05:27 +02:00
Veikka Tuominen
72fa8d4880 Sema: fix overflow arithmetic with runtime vectors
It should return a a vector of bools for compatibility with scalar
operands and stage1 until #10248 can be implemented.

Closes #13201
2022-11-26 18:05:27 +02:00
Andrew Kelley
30eb2a1753
Merge pull request #13627 from Vexu/tuple-decls
Implement tuple type declarations
2022-11-25 18:06:09 -05:00
Veikka Tuominen
9f055e2eb0 Sema: improve compile error for tuple coercion mismatch 2022-11-23 22:16:31 +02:00
Veikka Tuominen
8eea73fb92 add tests for tuple declarations 2022-11-23 22:16:31 +02:00
Andrew Kelley
4ec27a4e25 C backend: implement vector reduce and overflow intrinsics 2022-11-22 23:33:58 -07:00
Veikka Tuominen
fc5209c139 llvm: fix x86_64 sysV ABI of big vectors on avx512 enabled CPUs
Closes #13629
2022-11-23 00:05:07 +02:00
Andrew Kelley
5e42378227 disable failing C ABI test
see tracking issue #13629
2022-11-22 13:06:09 -07:00
Cody Tapscott
3fa226a80c AstGen: Pop error trace for continue
PR #12837 handled control flow for break and return, but I forgot
about `continue`. This is effectively another break, so we just
need another `.restore_err_ret_index` ZIR instruction.

Resolves #13618.
2022-11-22 14:00:41 +02:00
Andrew Kelley
7829c73ccf disable failing arm-linux non-llvm backend tests
See #13623
2022-11-21 22:56:05 -07:00
Veikka Tuominen
d968d9d103 llvm: add attributes to the arguments of function pointer calls
Closes #13605
2022-11-20 20:25:12 +02:00
Veikka Tuominen
9e276d32f3 Sema: fix memory management of missing field error
Closes #13590
2022-11-20 20:25:12 +02:00
Veikka Tuominen
9e7293619f llvm: aarch64 C ABI: pass byref params as mutable pointers
Closes  #13597
2022-11-20 20:25:12 +02:00
Veikka Tuominen
08a00f0d1c llvm: use alignment of ABI return type when it differs from raw return type
This would previously cause miscompilations when the ABI type had
bigger alignment than the raw type.
2022-11-20 20:25:12 +02:00
Veikka Tuominen
835a1f7f0c Sema: fix missing error on mismatched array init count
Closes #13582
2022-11-20 20:25:12 +02:00
Veikka Tuominen
034507ef7c Module: fix compile error for non-comptime-known global initializer 2022-11-20 20:25:12 +02:00
Veikka Tuominen
98b3734b67 Sema: prioritize Value.variable over OPV when resolving const value
Closes #12275
2022-11-20 20:25:12 +02:00
Veikka Tuominen
bc76873827 Sema: fix type check in zirIntToPtr
Simple fix: don't assume a ptr type before it has been checked.

Closes #13567
2022-11-20 20:25:11 +02:00
Veikka Tuominen
510b891d27 Sema: handle opt_payload in beginComptimePtrLoad 2022-11-20 20:25:11 +02:00
Veikka Tuominen
0616d2966a Sema: allow coercing typed undefined to int
Closes #13556
2022-11-20 20:25:11 +02:00
Veikka Tuominen
44f8714dfb translate-c: cast unsuffixed floats to f64 2022-11-20 16:10:54 +02:00
Guillaume Wenzek
476b946802
compute LLVMTypes in ParamTypeIterator (#13592)
follow up on #13376 - fixes a bug in the x86_64 C ABI. 

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-11-20 01:14:02 -08:00
Andrew Kelley
0697883d01 extract C backend behavior tests with vectors
No functional change. Separates various float operations behavior tests
from the ones that test vectors.
2022-11-19 01:29:51 -05:00
kkHAIKE
ea590ece4b
Sema: optimize compare comptime float with int 2022-11-18 22:06:49 +02:00
Stevie Hryciw
04f3067a79 run zig fmt on everything checked by CI 2022-11-18 19:22:42 +00:00
Veikka Tuominen
8082323dfd
Merge pull request #13411 from dweiller/custom-test-runner
Custom test runner
2022-11-18 14:47:21 +02:00
Guillaume Wenzek
5221c90164
add C ABI tests with double
const DC = extern struct { v1: f64, v2: u8 };
const CFF = extern struct { v1: u8, v2: f32, v3: f32 };
const PD = extern struct { v1: ?*anyopaque, v2: f64 };

Signed-off-by: Guillaume Wenzek <gwenzek@users.noreply.github.com>
2022-11-18 14:05:25 +02:00
Veikka Tuominen
28cbe5e92a Sema+llvm: improve handling of namespace-like unions
Closes #13557
2022-11-16 01:13:35 +02:00
Veikka Tuominen
fe6249348f Sema: ensure comptime reference to function points to original decl
This prevents sema from creating new decls for the functions and
passing them to the backends as non-function decls.

Closes #12501
2022-11-16 01:12:54 +02:00
Veikka Tuominen
2cfa7165e7 Sema: do not re-evaluate type of non-generic inline call parameters
Closes #13491
2022-11-16 01:12:27 +02:00
mparadinha
c4f7663c92
Fix error reporting the wrong line for struct field inits (#13502)
* point to init part of field delc when that's where the error occurs

* update test to reflect fixed error message

* only lookup source location in case of error
2022-11-15 15:17:23 +02:00
Andrew Kelley
a50ad04e85 disable failing test on aarch64-macos 2022-11-14 16:07:52 -07:00
Veikka Tuominen
87cf2783eb llvm: check that tuple fields have runtime bits
Just checking that they aren't comptime isn't enough for `@Type` constructed tuples.

Closes #13531
2022-11-12 15:41:29 +02:00
Veikka Tuominen
a760ce598c Sema: ensure that !is_comptime and !is_typeof implies sema.func != null
Closes #13481
2022-11-12 15:41:29 +02:00
Veikka Tuominen
d42f4abb9d llvm: correctly lower references to generic functions
Closes #13522
2022-11-12 15:41:29 +02:00
Veikka Tuominen
40a2dfc12a Sema: coerce array operands to shuffle
Closes #13494
2022-11-11 18:00:05 +02:00
Veikka Tuominen
9b832e7f53 Sema: make check for namespace lookup of private declarations more strict
Previously sema only checked that the private declaration was in the same
file as the lookup but now it also checks that the namespace where
the decl was included from was also in the same file.

Closes #13077
2022-11-11 17:59:53 +02:00
Veikka Tuominen
0a188190b3 AstGen: make pointless discard error more strict
The error should only happen as a result of `_ = <expr>` not
for an operand of a break expression that is discarded.

Closes #13212
2022-11-11 17:59:53 +02:00
Veikka Tuominen
d2cc55109a llvm: correct calculation of index of zero-bit field
If the field comes before any non-zero-bit field then the index of
the next field should be returned.

Closes #13363
2022-11-11 17:59:53 +02:00
Veikka Tuominen
c4465556fd Type: check return_type for generic poison before comparing
Closes #13423
2022-11-11 17:59:53 +02:00
Veikka Tuominen
89e8bb409a AstGen: use condbr_inline if force_comptime is set
The `finishThenElseBlock` would correctly use `break_inline`
which would cause Sema to use `addRuntimeBreak` instead of
doing the branch at comptime.
2022-11-11 17:59:53 +02:00
Cody Tapscott
2897641fb9 stage2: Support modifiers in inline asm
These are supported using %[ident:mod] syntax. This allows requesting,
e.g., the "w" (32-bit) vs. "x" (64-bit) views of AArch64 registers.

See https://llvm.org/docs/LangRef.html#asm-template-argument-modifiers
2022-11-11 16:01:31 +02:00
Cody Tapscott
b1357091ae Add test case for #12043
This bug is already resolved, just want to make sure we don't lose
the test case. Closes #12043
2022-11-10 12:23:59 -07:00
Cody Tapscott
fbda15632d stage2 sema: Make vector constants when operating on vectors
Resolves https://github.com/ziglang/zig/issues/13058
2022-11-10 12:22:40 -07:00
Cody Tapscott
8f3880074f stage2: Be more strict about eliding loads
This change makes any of the `*_val` instructions check whether it's
safe to elide copies for by-ref types rather than performing this
elision blindly.

AIR instructions fixed:
 - .array_elem_val
 - .struct_field_val
 - .unwrap_errunion_payload
 - .try
 - .optional_payload

These now all respect value semantics, as expected.

P.S. Thanks to Andrew for the new way to approach this. Many of the
lines here are from his recommended change, which comes with the
significant advantage that loads are now as small as the intervening
memory access allows.

Co-authored by: Andrew Kelley <andrew@ziglang.org>
2022-11-10 12:22:40 -07:00
Cody Tapscott
ff699722da stage2: Fix comptime array initialization
This is a follow-up to 9dc98fba, which made comptime initialization
patterns for union/struct more robust, especially when storing to
comptime-known pointers (and globals).

Resolves #13063.
2022-11-10 12:22:37 -07:00
Jakub Konka
04b8ce5fd3 Merge branch 'jcmoyer-lld-explicit-pdb' 2022-11-10 16:52:43 +01:00
Jakub Konka
4b3637820d
Merge pull request #13495 from ziglang/macho-dsym
stage2: misc DWARF debug info fixes and additions for x86_64 and aarch64
2022-11-10 16:50:57 +01:00
Jakub Konka
1357790ec9 win: combine PDB fixes into one changeset 2022-11-10 14:03:11 +01:00
Jakub Konka
0914e0a4ec dwarf: do not assume unsigned 64bit integer for the enum value 2022-11-10 09:36:45 +01:00
Jakub Konka
2d5fbbb44e
Merge pull request #13485 from ziglang/arm64-non-null-actual
aarch64: optionals
2022-11-09 21:13:50 +01:00
Veikka Tuominen
61842da9f7 llvm: implement packed unions
Closes #13340
2022-11-09 17:14:38 +02:00
Jakub Konka
e83590d0e8 aarch64: pass some tests dealing with optionals 2022-11-08 13:59:47 +01:00
Veikka Tuominen
dc128f403b
Merge pull request #13446 from Vexu/stage2-fixes
Stage2 bug fixes
2022-11-07 14:17:26 +02:00
Jakub Konka
72769f6cec link-tests: add test case for parsing weak imports 2022-11-06 15:21:28 +01:00
Jakub Konka
5ef33e7c7e
Merge pull request #13459 from ziglang/issue-13457
macho: do not zero-out file if there are no nonzerofill sects
2022-11-06 08:39:13 +01:00
Jakub Konka
aaaa7df152 macho: add linker test case for issue 13457 2022-11-06 00:10:12 +01:00
Veikka Tuominen
5d28d171df Sema: adjust result type of anyerror field access
Closes #13448
2022-11-05 13:22:21 +02:00
Veikka Tuominen
ea48f06fc2 stage2: address of threadlocal variable is not comptime known
Closes #13215
2022-11-05 13:22:21 +02:00
Veikka Tuominen
f96748ebc1 Sema: coerce elements of array cat
Closes #13347
2022-11-05 13:22:21 +02:00
Veikka Tuominen
f92e7bed7b stage2: bitsize of packed struct should trigger backing int ty check
Closes #13398
2022-11-05 12:54:38 +02:00
Andrew Kelley
1d68045919
Merge pull request #13101 from alichraghi/o4 2022-11-05 02:34:24 -04:00
Veikka Tuominen
51b1083d66 stage2: fix onePossibleValue of empty unions and enums
Closes #13402
2022-11-04 23:13:50 +02:00
Veikka Tuominen
42db468dcb Sema: make method call work with optionals and error unions
Closes #13414
2022-11-04 23:13:49 +02:00
Veikka Tuominen
35afa3fd8b Sema: correct condition in validateArrayInit
Closes #13425
2022-11-04 23:13:49 +02:00
Veikka Tuominen
799a558e39 Sema: implement peer type resolution of function pointers and function bodies
Closes  #13438
2022-11-04 23:13:49 +02:00
Veikka Tuominen
e6b3cb5043 Sema: detect division overflow
Closes #13434
2022-11-04 23:13:29 +02:00
Veikka Tuominen
8c4faa5f3f
Merge pull request #13338 from Vexu/stage2-compile-errors
Improve some error messages
2022-11-04 16:04:31 +02:00
Micah Switzer
ea54c9a375 Sema: resolve lazy align in zirReify for union fields
Closes #13435
2022-11-04 15:48:08 +02:00
Ali Chraghi
f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
Nathan Bourgeois
e64eef366c
Translate-C Remainder Macro Fix 2022-11-03 14:07:00 +02:00
Jacob Young
4537c1b8b6 cbe: fix crash rendering union with zero-bit tag 2022-11-02 21:42:40 -04:00
Jacob Young
fa46f9a3d7 cbe: fix extern 2022-11-02 21:42:40 -04:00
Andrew Kelley
e50789f1cb
Merge pull request #13389 from jacobly0/fix-only-c
cbe: enough fixes for `-Donly-c` to be able to produce an executable
2022-11-02 15:53:59 -04:00
Andrew Kelley
57dbeb90af
Merge pull request #13396 from Luukdegram/fix-12880
llvm: mangle extern function names for Wasm target
2022-11-02 14:10:07 -04:00
Jacob Young
37c104ade0 cbe: ignore comptime fields when generating tuple typedefs
This vastly reduces the amount of deduplication state we need to deal with.
2022-11-02 10:21:05 -04:00
Jacob Young
5f31070b8b cbe: hack around invalid Air
Can be changed to `!inst_ty.hisRuntimeBitsIgnoreComptime()` when the
"result location with inferred type ends up being pointer to comptime_int"
test stops producing Air containing a `bitcast(*comptime_int, ...)`.

See #13410
2022-11-02 10:20:31 -04:00
dweiller
ae0f12885b test: add test_runner_path test 2022-11-02 22:41:20 +11:00
Jacob Young
09763435a8 cbe: support arrays in more places 2022-11-01 20:39:06 -04:00
Jacob Young
071404ff65 cbe: fix optional access 2022-11-01 20:39:05 -04:00
Jacob Young
91fe0b80a2 cbe: fix threadlocal 2022-11-01 20:38:51 -04:00
Jacob Young
757db665a7 build: remove ofmt from LibExeObjStep which is redundant with target.ofmt 2022-11-01 20:38:37 -04:00
joachimschmidt557
3ecec50f0c
stage2 AArch64: implement basic switch statements 2022-11-01 20:43:27 +01:00
Luuk de Gram
ef0df24626
test/link: add linker test to verify mangling
This adds a simple linker test to ensure the built library contains
an import entry for each extern function call that was mangled.
2022-11-01 15:43:34 +01:00
Jacob Young
b35514ecfe cbe: disable aarch64 behavior tests that are broken with gcc 2022-10-31 21:01:04 -04:00
Jacob Young
b945d3eb90 cbe: improve support for non-native float types
* Fix _start on aarch64.
 * Add fallbacks when a float type is unsupported.

Fixes #13357
2022-10-31 20:18:15 -04:00
Andrew Kelley
ef761c2cbc
Merge pull request #13360 from topolarity/comptime-bool-binops
Make `x and false` and `x or true` comptime-known
2022-10-30 22:11:44 -04:00
Jacob Young
a77d89afe3 behavior: enable fixed cbe tests 2022-10-30 15:38:50 -04:00
Cody Tapscott
ca332f57f7 stage2: Make x and false/x or true comptime-known
Same as preceding change, but for stage2.
2022-10-30 12:38:08 -07:00
Andrew Kelley
17df35025b CI: disable failing C backend test
See #13357
2022-10-30 03:21:18 -07:00
Andrew Kelley
5f5a20ebaf
Merge pull request #13093 from jacobly0/backend-fixes
C backend fixes
2022-10-29 23:06:59 -04:00
Andrew Kelley
28dc208f65
Merge pull request #13082 from g-w1/unnamed-decls-and-relocs-p9
Plan9: Fix The Backend
2022-10-29 17:45:00 -04:00
Veikka Tuominen
d7314555f2 Sema: improve compile error for casting double pointer to anyopaque pointer
Closes #12042
2022-10-29 14:55:43 +03:00
Veikka Tuominen
1ea1228036 Sema: fix floatToInt to zero bit ints
Closes #9415
2022-10-29 14:55:43 +03:00
Veikka Tuominen
61f5ea4c9a Sema: add error note for wrong pointer dereference syntax
Closes #1897
2022-10-29 14:55:43 +03:00
Jacob Young
48a2783969 cbe: implement optional slice representation change 2022-10-29 05:58:41 -04:00
Andrew Kelley
c36eb4ede9
Merge pull request #13221 from topolarity/packed-mem
Introduce `std.mem.readPackedInt` and improve bitcasting of packed memory layouts
2022-10-28 21:15:16 -04:00
Evan Haas
c616141241 translate-c: Better support for division in macros
Perform C-style arithmetic conversions on operands to division operator
in macros

Closes #13162
2022-10-28 17:59:32 -04:00
Cody Tapscott
40b7792a4c Enable bitcast test now that #13214 is resolved. 2022-10-28 12:41:15 -07:00
Cody Tapscott
3295fee911 stage2: Use mem.readPackedInt etc. for packed bitcasts
Packed memory has a well-defined layout that doesn't require
conversion from an integer to read from. Let's use it :-)

This change means that for bitcasting to/from a packed value that
is N layers deep, we no longer have to create N temporary big-ints
and perform N copies.

Other miscellaneous improvements:
  - Adds support for casting to packed enums and vectors
  - Fixes bitcasting to/from vectors outside of a packed struct
  - Adds a fast path for bitcasting <= u/i64
  - Fixes bug when bitcasting f80 which would clear following fields

This also changes the bitcast memory layout of exotic integers on
big-endian systems to match what's empirically observed on our targets.
Technically, this layout is not guaranteed by LLVM so we should probably
ban bitcasts that reveal these padding bits, but for now this is an
improvement.
2022-10-28 08:41:04 -07:00
Veikka Tuominen
6fc71835c3 value: properly hash null_value pointer
Closes #13325
2022-10-28 13:31:16 +03:00
Veikka Tuominen
c3b85e4e2f Sema: further enhance explanation of why expr is evaluated at comptime 2022-10-28 13:31:16 +03:00
Andrew Kelley
c389f8800b
Merge pull request #13290 from Vexu/generic-deletion-mitigation
Mitigate generic deletion bug
2022-10-28 01:04:00 -04:00
Andrew Kelley
2991e4a454
Merge pull request #13288 from Vexu/opt-slice
Optimize size of optional slices (+ some fixes)
2022-10-27 22:09:17 -04:00
InKryption
bc72ae5e4e Sema: Prevent coercion from tuple pointer to mutable slice.
Also fix some stdlib code affected by this.

Co-authored by: topolarity <topolarity@tapscott.me>
2022-10-27 22:00:47 -04:00
Veikka Tuominen
d03c47bf85 Sema: use runtime_value instead of creating allocs 2022-10-27 21:08:25 -04:00
Veikka Tuominen
648d34d8ea Sema: coerce zero-bit generic args are coerced properly
Closes #13307
2022-10-27 13:40:20 +03:00
Veikka Tuominen
b937a04560 Sema: check coerceInMemoryAllowed earlier in resolvePeerTypes
Closes #13310
2022-10-27 01:31:18 +03:00
Veikka Tuominen
d9fe5ba7f8 Sema: add error for too big packed struct 2022-10-27 01:31:18 +03:00
Veikka Tuominen
4ac8ec4c5c AstGen: fix refing inferred allocs
Closes  #13285
2022-10-27 01:31:18 +03:00
Veikka Tuominen
4fc944dde8 translate-c: fix redefinition of label on left recursive comma operator
Closes #13239
2022-10-27 01:31:18 +03:00
Veikka Tuominen
78a7bb108a llvm: handle namespace like packed structs
Closes #13159
Closes #13188
2022-10-27 01:31:18 +03:00
Veikka Tuominen
dd437ae399 stage2: optimize size of optional slices 2022-10-27 01:31:17 +03:00
Veikka Tuominen
b12a5cea75 remove test case triggering generic deletion bug
This test should be restored once the underlying issue is resolved (with the typo fixed).
2022-10-27 01:31:05 +03:00
Hadrien Dorio
9db293492b make a .rsp file for zig clang
same as std.build.LibExeObjStep.make() for `zig build-exe`
closes #12419
2022-10-26 23:50:51 +02:00
Luuk de Gram
2f41109cc4
test/link: add Wasm linker tests for features
Adds a test for inferring features based on a different object file.
Also provides a test case where cpu features are explicitly set on
a library where the end result will output said target features.
2022-10-25 20:48:08 +02:00
Jacob Young
e20d2b3151 cbe: fix floating point builtins 2022-10-25 07:02:06 -04:00
Jacob Young
3d22327b23 cbe: enable test fixed by #13296 2022-10-25 05:43:00 -04:00
Jacob Young
94425fe46e cbe: improve floating point type support 2022-10-25 05:22:55 -04:00
Jacob Young
6021edd7ce cbe: add support for all float literals types 2022-10-25 05:22:55 -04:00
Jacob Young
54326cc554 cbe: implement field_parent_ptr 2022-10-25 05:11:29 -04:00
Jacob Young
361035fe7a cbe: implement cmp_lt_errors_len 2022-10-25 05:11:29 -04:00
Jacob Young
e470cf361f cbe: update test cases 2022-10-25 05:11:29 -04:00
Jacob Young
ab468d57e3 cbe: implement packed structs
Sometimes you have to break a test to make progress :)
2022-10-25 05:11:29 -04:00
Jacob Young
15df64ade8 std: add cbe hacks to more targets
These are needed because clang doesn't support anything in naked
functions, not even assembly register inputs.
2022-10-25 05:11:29 -04:00
Jacob Young
1bab854868 cbe: implement 128-bit and fix smaller integer builtins 2022-10-25 05:11:29 -04:00
Jacob Young
8b6a3ba74e cbe: fix typedef declaration order 2022-10-25 05:11:29 -04:00
Jacob Young
4765294ca4 cbe: get enough things working to support basic programs
* Enable advanced start support.
 * Enable advanced test_runner support.
 * Zig Language Reference's Hello World now works.
2022-10-25 05:11:29 -04:00
Jacob Young
912b84bbad cbe: fix atomics 2022-10-25 05:11:29 -04:00
Jacob Young
6921b0a850 cbe: implement some float ops 2022-10-25 05:11:29 -04:00
Jacob Young
b48417aed2 cbe: misc fixes 2022-10-25 05:11:29 -04:00
Jacob Young
1dd4a6102f cbe: implement global assembly 2022-10-25 05:11:29 -04:00
Jacob Young
e8bda9eb3a cbe: implement ptr slice ptr 2022-10-25 05:11:29 -04:00
Jacob Young
87d432328e cbe: implement aggregate_init of struct 2022-10-25 05:11:29 -04:00
Jacob Young
feb8f81cd9 cbe: canonicalize types that have the same C type when emitting typedefs 2022-10-25 05:11:29 -04:00
Jacob Young
5eafc10bf4 cbe: fix global access fix 2022-10-25 05:11:29 -04:00
Jacob Young
c126a1018e cbe: implement more asm features 2022-10-25 05:11:28 -04:00
Jacob Young
a12535f501 cbe: fix global access 2022-10-25 05:11:28 -04:00
Jacob Young
f399dd107a cbe: implement tag name 2022-10-25 05:11:28 -04:00
Jacob Young
40b5bb7161 cbe: fix loads and stores of 0-bit types 2022-10-25 05:11:28 -04:00
Jacob Young
962f33ee11 cbe: implement airUnionInit 2022-10-25 05:11:28 -04:00
Jacob Young
6a4266d62a cbe: fix infinite recursion on recursive types 2022-10-25 05:11:28 -04:00
Jacob Young
525dcaecba behavior: enable stage2_c tests that are currently passing
Also fix C warnings triggered by these tests.
2022-10-25 05:11:28 -04:00
Jacob Young
45c667eb21 behavior: fix redefined exports 2022-10-25 05:11:28 -04:00
Jacob Young
f81651932a c: hacks to fix incompatible redeclaration of library function warnings 2022-10-25 05:11:28 -04:00
Jacob Young
6f3654ad69 c: implement @errorName 2022-10-25 05:11:28 -04:00
Jacob Young
c8d0e71de6 c: fix mangling of error names
Closes #12751
2022-10-25 05:11:28 -04:00
Jacob G-W
5aef54cbc8 additional fixes for Plan9
with this, the tests should pass
2022-10-24 17:01:26 -04:00
Jacob G-W
c6fb798740 Revert "remove plan9 test coverage": Plan9 now works :^)
This reverts commit 67db2b85b7.
2022-10-24 16:53:12 -04:00
Andrew Kelley
04472af328
Merge pull request #13251 from Vexu/c-abi
implement ARM C ABI, separate C ABI tests from standalone tests
2022-10-23 12:16:58 -07:00
Veikka Tuominen
f2a7aba586 x86_64 llvm: correct lowering of ptr sized float struct
Closes #13211
2022-10-22 22:00:59 +03:00
Veikka Tuominen
3f41979061 replace some panics with try in C ABI tests 2022-10-22 14:52:26 +03:00
Veikka Tuominen
5e0b4836a1 stage2: implement RISCV C ABI 2022-10-22 14:52:26 +03:00
Veikka Tuominen
8fa91939a8 build.zig: separate C ABI tests from standalone tests 2022-10-22 11:31:41 +03:00
Veikka Tuominen
12a2ccfb45 make C ABI tests compile on powerpc 2022-10-22 11:31:41 +03:00
Veikka Tuominen
031c768cc8 add C ABI tests for simd vectors 2022-10-22 11:31:41 +03:00
Cody Tapscott
74b9cbd895 stage2: Skip test exposing #13175
This PR (#12873) in combination with this particular test exposed
a pre-existing bug (#13175).

This means that the test for #13038 has regressed
2022-10-21 12:40:33 -07:00
Cody Tapscott
d060cbbec7 stage2: Keep error return traces alive when storing to const
This change extends the "lifetime" of the error return trace associated
with an error to continue throughout the block of a `const` variable
that it is assigned to.

This is necessary to support patterns like this one in test_runner.zig:
```zig
const result = foo();
if (result) |_| {
    // ... success logic
} else |err| {
    // `foo()` should be included in the error trace here
    return error.TestFailed;
}
```

To make this happen, the majority of the error return trace popping logic
needed to move into Sema, since `const x = foo();` cannot be examined
syntactically to determine whether it modifies the error return trace. We
also have to make sure not to delete pertinent block information before it
makes it to Sema, so that Sema can pop/restore around blocks correctly.

* Why do this only for `const` and not `var`? *

There is room to relax things for `var`, but only a little bit. We could
do the same thing we do for const and keep the error trace alive for the
remainder of the block where the *assignment* happens. Any wider scope
would violate the stack discipline for traces, so it's not viable.

In the end, I decided the most consistent behavior for the user is just
to kill all error return traces assigned to a mutable `var`.
2022-10-21 12:40:29 -07:00
Cody Tapscott
b529d8e48f stage2: Propagate error return trace into fn call
This change extends the "lifetime" of the error return trace associated
with an error to include the duration of a function call it is passed
to.

This means that if a function returns an error, its return trace will
include the error return trace for any error inputs. This is needed to
support `testing.expectError` and similar functions.

If a function returns a non-error, we have to clean up any error return
traces created by error-able call arguments.
2022-10-21 11:22:49 -07:00
Cody Tapscott
77720e30aa Re-factor: Change AstGen.ResultLoc to be a struct
This re-factor is intended to make it easier to track what kind of
operator/expression consumes a result location, without overloading the
ResultLoc union for this purpose.

This is used in the following commit to keep track of initializer
expressions of `const` variables to avoid popping error traces
pre-maturely. Hopefully this will also be useful for implementing
RLS temporaries in the future.
2022-10-21 11:22:46 -07:00
Cody Tapscott
3007fdde45 stage2: Pop error trace when storing error to var/const
In order to enforce a strict stack discipline for error return traces,
we cannot track error return traces that are stored in variables:

  ```zig
  const x = errorable(); // errorable()'s error return trace is killed here

  // v-- error trace starts here instead
  return x catch error.UnknownError;
  ```

In order to propagate error return traces, function calls need to be passed
directly to an error-handling expression (`if`, `catch`, `try` or `return`):

  ```zig
  // When passed directly to `catch`, the return trace is propagated
  return errorable() catch error.UnknownError;

  // Using a break also works
  return blk: {
      // code here
      break :blk errorable();
  } catch error.UnknownError;
  ```

Why do we need this restriction? Without it, multiple errors can co-exist
with their own error traces. Handling that situation correctly means either:
  a. Dynamically allocating trace memory and tracking lifetimes, OR
  b. Allowing the production of one error to interfere with the trace of another
     (which is the current status quo)

This is piece (3/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21 10:44:20 -07:00
Cody Tapscott
0c3a50fe1c stage2: Do not pop error trace if result is an error
This allows for errors to be "re-thrown" by yielding any error as the
result of a catch block. For example:

```zig
fn errorable() !void {
    return error.FallingOutOfPlane;
}

fn foo(have_parachute: bool) !void {
    return errorable() catch |err| b: {
        if (have_parachute) {
            // error trace will include the call to errorable()
            break :b error.NoParachute;
        } else {
            return;
        }
    };
}

pub fn main() !void {
    // Anything that returns a non-error does not pollute the error trace.
    try foo(true);

    // This error trace will still include errorable(), whose error was "re-thrown" by foo()
    try foo(false);
}
```

This is piece (2/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21 10:44:19 -07:00
Cody Tapscott
eda3eb1561 stage2: "Pop" error trace for break/return within catch
This implement trace "popping" for correctly handled errors within
`catch { ... }` and `else { ... }` blocks.

When breaking from these blocks with any non-error, we pop the error
trace frames corresponding to the operand. When breaking with an error,
we preserve the frames so that error traces "chain" together as usual.

```zig
fn foo(cond1: bool, cond2: bool) !void {
    bar() catch {
    	if (cond1) {
	    // If baz() result is a non-error, pop the error trace frames from bar()
	    // If baz() result is an error, leave the bar() frames on the error trace
            return baz();
	} else if (cond2) {
	    // If we break/return an error, then leave the error frames from bar() on the error trace
	    return error.Foo;
	}
    };

    // An error returned from here does not include bar()'s error frames in the trace
    return error.Bar;
}
```

Notice that if foo() does not return an error it, it leaves no extra
frames on the error trace.

This is piece (1/3) of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574
2022-10-21 10:43:42 -07:00
Veikka Tuominen
9ae78a5890 stage2: implement ARM C ABI
Six new passing tests and the previously incorrectly passing
complex tests are now skipped.
2022-10-21 18:07:11 +03:00
Veikka Tuominen
972c39e2c0
Merge pull request #13219 from Vexu/stage2-fixes
Stage2 bug fixes
2022-10-21 12:11:49 +02:00
Veikka Tuominen
2609e33ab0 make C ABI tests compile on arm, mips and riscv
x86_64      24/25
x86         15/25
aarch64     25/25 - all
arm         18/25
mips        10/24
riscv64     13/25
wasm32      25/25 - all
2022-10-20 20:11:12 +03:00
Veikka Tuominen
646d927c79 stage2: fix handling of aarch64 C ABI float array like structs
Closes #11702
Closes #13125
2022-10-20 20:11:12 +03:00
Veikka Tuominen
07b6173cb8 delete failing recursive test
Don't forget to add these back when solving #12973
2022-10-20 20:11:12 +03:00
Veikka Tuominen
7e946bc790 make C ABI tests compile on i386 2022-10-20 20:11:12 +03:00
Veikka Tuominen
51491186cb stage2: fix x86_64 C ABI of struct with array member
Closes #12185
2022-10-20 20:11:12 +03:00
Veikka Tuominen
ce95cc170b Value: handle runtime_int in hashPtr
Closes #12702
2022-10-20 20:11:12 +03:00
Veikka Tuominen
9a52abf3b4 Sema: add missing calls to wip_captures.finalize
Closes #13171
2022-10-20 20:11:12 +03:00
Veikka Tuominen
3b60a6de2f Sema: fix using runtime instructions inside typeof in comptime only blocks
Closes #13210
Follow up to 3ccd4907fb
2022-10-20 20:11:12 +03:00
Veikka Tuominen
c95a34b68f stage2: improve source location of assignment 2022-10-20 20:11:00 +03:00
Veikka Tuominen
34e4b07d0c Sema: allow runtime only instructions to be emitted in outside functions
It is possible to get comptime-known values from runtime-known values
for example the length of array. Allowing runtime only instructions to
be emitted outside function bodies allows these operations to happen.
In places where comptime-known values are required we have other methods
to ensure that and they usually result in more specific compile errors too.

Closes #12240
2022-10-20 20:11:00 +03:00
Veikka Tuominen
13897be0ab Type: bitSizeOf non-packed structs should include padding
Closes #13214
2022-10-20 20:11:00 +03:00
Luuk de Gram
7d6596e979
Merge pull request #13218 from Luukdegram/fix-emulatable-step
std: CheckObject - correctly depend on its own step when creating an EmulatableRunStep
2022-10-19 08:36:14 +02:00
Veikka Tuominen
4aaff75c81 Sema: resolve tuple default values before hashing
Closes #12488
2022-10-19 01:38:19 +03:00
Veikka Tuominen
6582896ee0 Sema: remove unresolved inferred allocs
Closes #2557
2022-10-19 01:38:19 +03:00
Veikka Tuominen
4e134f6dcb Sema: respect inline call semantics
If an argument is comptime-known but shouldn't be create an alloc
to store it in to get a runtime-known value.
2022-10-19 01:38:18 +03:00
Andrew Kelley
b120c819db
Merge pull request #13055 from alichraghi/m2m
all: rename `@maximum` to `@max` and `@minimum` to `@min`
2022-10-18 14:42:55 -04:00
Andrew Kelley
7c7d9e13d7 Sema: fix runtime int to enum with one possible value 2022-10-18 10:18:09 -07:00
Luuk de Gram
c0fe135ff3
test/link: remove redundant dependOn statements
`runAndCompare` will already depend on the `CheckObject` step itself
so it's not needed to also have the test step depend on the
check object step.
2022-10-18 17:20:08 +02:00
Jacob Young
687a7d38a0 value: implement Value.eqlAdvanced on slices
* Support comparison between implicitly casted array pointer and slice.
 * Support comparison between slices with different value tags.

Closes #12700
2022-10-18 14:16:39 +02:00
Ali Chraghi
ca27055cda all: rename @maximum to @max and @minimum to @min 2022-10-18 14:15:16 +03:00
GethDW
edc842ff18
stage2: implement packedStuctToInt for more types 2022-10-18 14:05:48 +03:00
jacobly0
bd0dd225e8
Sema: implement linksection on functions
* Sema: implement linksection on functions

 * Implement function linksection in Sema.
 * Don't clobber function linksection/align/addrspace in Sema.
 * Fix copy-paste typo in tests.
 * Add a bunch of missing test_step.dependOn.
 * Fix checkInSymtab match.

Closes #12546
2022-10-18 14:02:10 +03:00
Andrew Kelley
ce3ffa5e1b
Merge pull request #11747 from Luukdegram/compiler-rt
compiler_rt: Move mem implementations from c.zig
2022-10-17 18:12:22 -04:00
Veikka Tuominen
be9a4a1f97 Sema: handle noreturn in boolBr
Closes #13112
2022-10-17 18:53:15 +03:00
Jacob Young
c7f9833238 Module: fix early exit conditions during compilation
* `--verbose-llvm-ir` should trigger analysis and codegen
 * `-femit-asm` etc should trigger codegen even with `-fno-emit-bin`

Closes #12588
2022-10-15 14:18:35 -04:00
Jacob Young
cb0e22db4e llvm: fix lowering of runtime refs to comptime-only decls
When we want a runtime pointer to a zero-bit value we use an undef
pointer, but what if we want a runtime pointer to a comptime-only value?
Normally, if `T` is a comptime-only type such as `*const comptime_int`,
then `*const T` would also be a comptime-only type, so anything
referencing a comptime-only value is usually also comptime-only, and
therefore not emitted to the executable.

However, what if instead we have a `*const anyopaque` pointing to a
comptime-only value?  Certainly, `*const anyopaque` is a runtime type,
and so we need some runtime value to store, even when it happens to be
pointing to a comptime-only value.  In this case we want to do the same
thing as we do when pointing to a zero-bit value, so we use
`hasRuntimeBits` to handle both cases instead of ignoring comptime.

Closes #12025
2022-10-15 14:17:25 -04:00
Guillaume Wenzek
419855c475 fix test 2022-10-15 10:39:19 -07:00
Guillaume Wenzek
b425d88737 re-enable nvptx tests 2022-10-15 10:39:19 -07:00
Jacob Young
400319872b llvm: fix bug lowering aggregate_init with a byref sentinel
Closes #12972
2022-10-15 11:12:04 -04:00
Andrew Kelley
b4e3424594
Merge pull request #13100 from topolarity/powerpc64le
stage2: Fix softfloat support for PPC64(LE)
2022-10-15 10:05:00 -04:00
Luuk de Gram
74108bb9c0 test/link: fix Wasm archive test
As memcpy is now part of compiler-rt, we no longer expect
any imports in the binary.
2022-10-15 07:02:38 -07:00
Evan Haas
e4e1c21e1f i386 ABI: Fix some sizes and alignments
This makes the following changes for i386:

long long and unsigned long long have 4 byte alignment on non-Windows

f64 (double) has 4-byte alignment on non-Windows

long double is 80 bits and has 4 byte alignment on mingw

long double on android is 64 bits, not 80: https://www.uclibc.org/docs/psABI-i386.pdf

Fixes #12453
Fixes #12987
2022-10-14 15:22:00 -04:00
Jacob Young
9b45dc1608 stage2: fix emitting asm and bin at the same time
This logic is copied from stage1.

Fixes #12800
2022-10-14 14:46:50 -04:00
Cody Tapscott
34863224c3 Re-enable mulAdd f128 tests on i386-linux 2022-10-13 12:53:30 -07:00
Cody Tapscott
1e278131e3 Re-enable @mulAdd f128 tests on aarch64-darwin
Closes #9900
2022-10-13 12:53:29 -07:00
Cody Tapscott
f035437b5d Re-enable Vector f16 tests on Windows
Closes #4952
2022-10-13 12:53:20 -07:00
Cody Tapscott
b8c587eb40 tests: Enable PPC64LE as a test target 2022-10-13 12:53:20 -07:00
Cody Tapscott
83e2d3fb37 stage1: Skip new tests that never passed in stage1
This gets the behavior tests passing for stage1 again.
2022-10-13 12:53:20 -07:00
kkHAIKE
d987bf859e Sema: add float128IntPartToBigInt to fix compare comptime float with int 2022-10-13 13:11:13 +02:00
Veikka Tuominen
3a8777a8bb fix hyphenation in test case
Follow up to 51d9db8569
2022-10-12 16:10:57 +03:00
jacobly0
562ac8be48
codegen: add support for lowering .field_ptr on a slice
Closes #13068
2022-10-12 12:40:59 +03:00
Andrew Kelley
7ce1ee1bce
Merge pull request #13081 from r00ster91/docs
fix(text): hyphenation and other fixes
2022-10-12 05:26:11 -04:00
Luuk de Gram
1f196b9e2f
stage2: implement exporting using field access (#13136)
This implements `@export(a.b, .{..});` in semantic analysis,
allowing users to directly export a variable from a namespace.

* add test case for exporting using field access
2022-10-12 04:38:07 -04:00
Cody Tapscott
e6ebdcb82e stage2 LLVM: Use a packed aggregate for union payload init
Without the packed qualifier, the type layout that we use to
initialize doesn't match the correct layout of the underlying
storage, causing corrupted data and past-the-end writes.
2022-10-11 15:42:01 -04:00
Luuk de Gram
8635c18e40
test/link: don't strip producers section for wasm
When testing the Wasm linker for the producers section
we do not ever want to strip the binary as this will remove
the producers section in release-small.

This fixes the CI errors by d086b371f0
2022-10-11 21:27:09 +02:00
Veikka Tuominen
a72b584c76
Merge pull request #13126 from tau-dev/master
translate-c: Fix function pointers, add cast to subscripts in macros
2022-10-11 19:04:44 +02:00
Ali Chraghi
d086b371f0 Compilation: strip debug info from ReleaseSmall by default 2022-10-11 17:51:25 +02:00