Commit Graph

2481 Commits (129a4fb251f8eab22eacf219fbf81006baec3251)

Author SHA1 Message Date
Alexandros Naskos 908b908481 Added tests. 2020-04-27 15:22:15 +03:00
LemonBoy a7a8c433d0 stage1: Prevent the creation of illegal ptr types
Closes #5140
2020-04-24 15:55:32 -04:00
Timon Kruiper c829f2f7b7 Add mips support to standard library 2020-04-24 15:28:55 -04:00
xackus a9eb4a6740 stage1: fix crash on accessing an array of size zero with runtime index 2020-04-23 12:45:32 -04:00
LemonBoy e6428f9401
stage1: Fix bitcast of immediate to ptr type (#5131)
Consider a (legal according to the `@bitCast` rules) conversion from u16
to [2]u8: since the former is a scalar and the latter is a pointer
(arrays are represented at pointers in the codegen phase) we have to
allocate a temporary slot on the stack and then bitcast the resulting
pointer to the desired destination type.

Beware that this means the lifetime of the resulting value is the same
of the function it's contained in and for all intents and purposes
should be regarded as a local (eg. it should not escape).

Closes #4395
Closes #5121
2020-04-23 12:44:16 -04:00
Andrew Kelley e8545db9d4
Merge pull request #5130 from ziglang/stage2-ir
beginnings of non-LLVM self-hosted backend
2020-04-22 14:42:46 -04:00
LemonBoy b5e72c0148 stage1: Prevent the creation of illegal pointer types
Changing the pointer length from Unknown to Single/C now resets the
sentinel value too.

Closes #5134
2020-04-22 14:40:57 -04:00
elucent 48dc3b6fe9 Added peer type resolution for [*]T and *[N]T. 2020-04-21 18:09:03 -04:00
Andrew Kelley cc1c2bd568 simplify ZIR spec; separate parsing/rendering from analysis 2020-04-20 19:21:03 -04:00
Andrew Kelley f92ccf365b generic ir parsing framework 2020-04-19 19:31:50 -04:00
Andrew Kelley bd4280decf beginnings of zig ir parser 2020-04-19 19:31:50 -04:00
Vexu b6fe839248
update std lib to decls being disallowed between fields 2020-04-18 23:56:05 +03:00
Vexu fff00c3bbb
disallow declarations between container fields 2020-04-18 23:56:03 +03:00
Vexu 4f02cf32b4
fix typeInfo tests 2020-04-18 11:39:52 +03:00
Vexu 1afaf42525
add error for non-exter variadic functions 2020-04-17 22:02:49 +03:00
Vexu c026a9f6d2 fix missing compile errors on builtin cast functions 2020-04-17 14:22:20 -04:00
LemonBoy 8e96922f31 stage1: Fix several bugs in constant generation
The codegen would sometimes change the LLVM type for some constants to
an unnamed structure in order to accomodate extra padding. This is fine
as long as the alignment of each field is still respected and it was not
the case for structure types, leading to ill-formed constants being
generated.

Optional types suffer from this to a lower extent as their layout is
quite lucky, the only missing piece was the tail padding.

Closes #4530
Closes #4594
Closes #4295
Closes my will to live
2020-04-17 13:42:23 -04:00
Vexu ca3bf6e6ad
translate-c cleanup and zig fmt 2020-04-15 15:15:32 +03:00
Vexu a016fb8c62
translate-c: correct invalid shortcut 2020-04-15 15:14:10 +03:00
foobles 022a71ca7d
Shift error message now says "fixed-width integer type" instead of just "integer type" (#5028)
* error message of ir_analyze_bit_shift now more accurate/specific

* fixed compile error test to match bit shift error message
2020-04-14 16:19:45 -04:00
LemonBoy ce21a784a4 stage1: More fixes for BE targets
* Fix packed struct alignment
* Adjust some tests
2020-04-13 17:35:14 -04:00
xackus dbc00e2424 ArrayList: remove old (before span) API 2020-04-11 20:40:34 -04:00
Vexu 1b1cbd9358
Merge pull request #4973 from SuperAuguste/nameless-fields
Nameless fields
2020-04-10 21:31:32 +03:00
Auguste Rame df14578c9d
Merge branch 'master' into nameless-fields 2020-04-10 11:49:50 -04:00
Vexu f60e7348d5
add error message for invalid assignment 2020-04-09 11:50:32 +03:00
Andrew Kelley beae932e0f
Merge pull request #4975 from Vexu/param-reassign
Fix missing compile error on assign to slice and array parameters
2020-04-08 21:02:50 -04:00
Lachlan Easton d7902707bc
Translate C: Allow casting literal ints to pointers 2020-04-08 14:11:01 -04:00
Vexu 7b5fb79b5b
Translate C: Put an alignCast in c style pointer casts to allow opaque types to cast properly in C macros
Translate C: add test case for aligning opaque types in pointer casts
2020-04-08 14:11:01 -04:00
Vexu b1e44adcba
move array and struct const checks to more appropriate places 2020-04-08 14:32:02 +03:00
xackus 66b2477ab6 fix lazy value in ir_analyze_instruction_elem_ptr 2020-04-07 18:22:17 -04:00
Vexu ff0f97a1bc
fix missing compile error on assign to slice and array parameters 2020-04-08 00:27:14 +03:00
Andrew Kelley ed23dad487
fix the new runtime-safety tests
Thanks to Vexu's work in e62671f643, compile errors were identified in
these test cases! This commit fixes them to use `const` as appropriate.
2020-04-07 16:05:42 -04:00
SuperAuguste 116c76cf82 fix tests 2020-04-07 15:19:28 -04:00
SuperAuguste 882aa86843 more fixes 2020-04-07 15:08:46 -04:00
Andrew Kelley 22dbeab29d
Merge pull request #4857 from LemonBoy/fix-4777
Rewrite the bound checks in slice operator
2020-04-07 14:51:25 -04:00
Vexu 95fefcd4c9
fix broken tests 2020-04-07 16:56:48 +03:00
Vexu e62671f643
fix missing const on address of literal 2020-04-07 15:25:44 +03:00
LemonBoy 0a936c1d76 Add some tests for the runtime safety checks 2020-04-06 20:14:06 +02:00
LemonBoy a59d31bd28 ir: Support tuple multiplication 2020-04-06 14:03:43 -04:00
Vexu c5ced0d74a
Merge pull request #4939 from SuperAuguste/master
translate-c: Properly translate C multicharacter literals
2020-04-06 10:31:17 +03:00
SuperAuguste 6106cf4419 fixes 2020-04-05 19:06:43 -04:00
Andrew Kelley e84b9b70ff
annotate disabled tests with github issue links 2020-04-05 18:34:32 -04:00
Andrew Kelley 5597b11a52
add runtime safety tests for SIMD integer division 2020-04-05 18:34:31 -04:00
LemonBoy 0f964e1910
I'm getting tired of this shit LLVM 2020-04-05 18:34:31 -04:00
LemonBoy 91a8e3b47b
tests: Chop away some flaky tests 2020-04-05 18:34:31 -04:00
LemonBoy d2d97e55cc
ir: Support shift left/right on vectors 2020-04-05 18:34:31 -04:00
LemonBoy 2485f30046
ir: Support bitwise not on vectors 2020-04-05 18:34:31 -04:00
LemonBoy 54ffcf95a8
ir: Support div/mod/rem on vector types
Closes #4050
2020-04-05 18:34:31 -04:00
Andrew Kelley e2dc63644a
type_has_one_possible_value takes comptime struct fields into account
Before, type_has_one_possible_value would return false for the value
`.{1}`. But actually, that type is a tuple with a single comptime field.
Such a type, in fact, has one possible value.

This plus the corresponding adjustment to get_the_one_possible_value
solves #3878.
2020-04-05 17:09:01 -04:00
Vexu 6ef15fc8d0
Merge pull request #4901 from phase/feature/translate-c-remassign
translate-c: RemAssign and DivAssign
2020-04-05 21:05:18 +03:00
xackus cd20e0cc67 rename mem.separate to mem.split 2020-04-04 17:37:51 -04:00
Jadon Fowler 391ee996a5 translate-c: account for signedness when translating div & mod
Signed-off-by: Jadon Fowler <j@jadon.io>
2020-04-04 02:16:30 -04:00
Andrew Kelley e89c42655c
Merge pull request #4868 from xackus/new-arraylist-api
new ArrayList API
2020-04-03 22:31:15 -04:00
Michael Dusan 8b6a06eefe
add compiler-error test: coerce
Issue fixed by an unknown commit.

closes #4207
2020-04-03 19:11:51 -04:00
Michael Dusan db4c06ce60 stage1: add compile errors for sentinel slicing
closes #3963
2020-04-03 19:05:30 -04:00
Andrew Kelley a2cad9a3d9
add issue links to disabled test cases 2020-04-03 18:36:13 -04:00
Andrew Kelley 11b50e3ad8 change the default ABI of riscv64-linux-musl
Before, this would cause a link failure when mixing Zig and C code for
RISC-V targets.

Now, the ABIs match and Zig and C code can be mixed successfully.

I will file a follow-up issue for the ability to deal more explicitly
with ABIs.

closes #4863
2020-04-03 13:13:09 -04:00
Andrew Kelley 048da6f631 ci: enable riscv64-linux tests
Thanks to Michael Dusan's work in
deef063bbf these tests can be enabled.
2020-04-02 21:44:03 -04:00
xackus 7a28c644aa new ArrayList API: fix everything else 2020-04-02 16:12:08 +02:00
Michael Dusan f6d384450f add compile-error test: bitcast
Issue fixed by an unknown commit.

closes #3818
2020-04-01 18:07:45 -04:00
LemonBoy 6695fa4f32 ir: Fix comparison of ?T values
The code assumed that every ?T had a pointer child type T, add some more
checks to make sure the type is effectively a pointer.

Closes #4789
2020-04-01 15:56:38 -04:00
Andrew Kelley 0f1f56bb69
Merge pull request #4896 from FireFox317/fix-arm32-stuff
fix some nullptr dereferences on arm-linux-musleabhif
2020-04-01 15:55:31 -04:00
Timon Kruiper d9cf779b47 Fix some nullptr dereferences on arm-linux-musleabhif 2020-04-01 20:38:32 +02:00
Jadon Fowler b9cb1e0d83 translate-c: add tests for div & rem assignment
Signed-off-by: Jadon Fowler <j@jadon.io>
2020-04-01 14:28:21 -04:00
Andrew Kelley 2e806682f4
(breaking) std.Buffer => std.ArrayListSentineled(u8, 0)
This new name (and the fact that it is a function returning a type) will
make it more clear which use cases are better suited for ArrayList and
which are better suited for ArrayListSentineled.

Also for consistency with ArrayList,
 * `append` => `appendSlice`
 * `appendByte` => `append`

Thanks daurnimator for pointing out the confusion of std.Buffer.
2020-04-01 13:30:07 -04:00
Michael Dusan e3d12471a2 add compile-error test for #2687
Issue fixed by an unknown commit.

closes #2687
2020-03-31 20:08:00 -04:00
Andrew Kelley 47a0e3ec5e
Merge pull request #4871 from boothby/issue4769
Address bugs when //, /// or //! are immediately followed by EOF
2020-03-31 10:56:21 -04:00
Kelly Boothby 44aadaff59 added unit tests to demonstrate #4769 and related bugs 2020-03-30 18:29:48 -07:00
Andrew Kelley 9e7ae06249
std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
Andrew Kelley b980568c81
add peer type resolution for mixed-const []T and *[N]T
closes #4766

This commit also fixes the implementation of some utility functions for
adjusting properties of pointer types. Previously these functions would
incorrectly drop vector, sentinel, and inference metadata.
2020-03-30 13:02:50 -04:00
LemonBoy c1cc1ebc35 ir: Avoid constant-folding ptr to sentinels
Constant-folding the pointers to the expected sentinel value have some
big problems: it hides the real content of the array, makes the pointer
to the sentinel point to a completely different memory region and treats
it like a const value even when the underlying array is mutable.

Fixes #4840
2020-03-30 11:03:56 -04:00
Andrew Kelley c70471fae6
enable now-passing test cases
These can now be enabled thanks to bug fixes that landed in
LLVM 10.
2020-03-29 10:34:12 -04:00
Layne Gustafson a55897106e Add macro string concat tests 2020-03-28 20:40:26 -04:00
LemonBoy d788b0cd8b std: Minor changes to TLS handling
* Always allocate an info block per-thread so that libc can store
  important stuff there.
* Respect ABI-mandated alignment in more places.
* Nicer code, use slices/pointers instead of raw addresses whenever
  possible.
2020-03-28 11:20:38 -04:00
Andrew Kelley ab20b351ce
update compile error tests 2020-03-26 14:07:19 -04:00
Andrew Kelley ddd98a7f10
prevent ptr cast from forcing alignment resolution unnecessarily 2020-03-26 12:34:16 -04:00
Andrew Kelley 93c7fa105f
Merge remote-tracking branch 'origin/llvm10'
LLVM 10 was released today
2020-03-24 09:57:09 -04:00
LemonBoy 0cd953d40e ir: Prevent crash when slicing hardcoded pointer
Closes #4780
2020-03-23 09:13:52 -04:00
Andrew Kelley 13d04f9963
Merge pull request #4741 from momumi/master
allow `_` separators in number literals (stage 1)
2020-03-23 00:54:54 -04:00
Andrew Kelley e5e5196d8e
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-22 20:48:21 -04:00
LemonBoy 6a89751025 ir: Implement cast from anon struct to union 2020-03-22 19:06:22 -04:00
Andrew Kelley 3bded9cf29
disable failing stack trace test for aarch64 2020-03-22 18:54:19 -04:00
Andrew Kelley 380c276deb
ci: disable qemu-riscv64 tests due to qemu being too old 2020-03-22 17:36:58 -04:00
Andrew Kelley 87b8b69eb0
update stack trace test expected output 2020-03-22 17:07:24 -04:00
Andrew Kelley 23c263776c
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-22 15:09:29 -04:00
LemonBoy dc79f181a5
ir: Disallow comparison between enum literal and untagged enum
Closes #4770
2020-03-21 20:54:05 -04:00
LemonBoy 28dbc58837 Address review comments 2020-03-21 09:54:49 +01:00
LemonBoy 128e70ff3a ir: Allow errdefer with payload
Closes #1265
2020-03-21 09:54:49 +01:00
Andrew Kelley 3a2c490889 "generate .h files" feature is no longer supported in stage1 2020-03-20 18:33:36 -04:00
LemonBoy 541e763010 ir: Peer type resolution between ?[]T and *[N]T
Closes #4767
2020-03-20 12:23:05 -04:00
Andrew Kelley 53b5aa812b
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-19 22:19:24 -04:00
Andrew Kelley 160367e0dd
fix compile error for reading past end of pointer casted array 2020-03-19 17:23:53 -04:00
Andrew Kelley 8ddf9d84ff
add behavior tests for slicing with comptime indexes 2020-03-19 11:17:46 -04:00
Andrew Kelley f824658e13
slicing sentinel-terminated slice without end
now results in a sentinel-terminated slice.
2020-03-19 10:54:20 -04:00
Andrew Kelley 61266d2621
test & docs fixups to work with new semantics 2020-03-19 09:53:55 -04:00
Andrew Kelley b5dba702ff
fixes to std.meta
behavior tests are passing now
2020-03-19 09:53:55 -04:00
Andrew Kelley 2164b511cc
partial revert of an improvement this branch made
because it uncovered a result location bug, and I need to get this
branch merged before going into a result location rabbit hole.

also fix the result type of slicing when the indexes are runtime known
and the result should be sentinel terminated.
2020-03-19 09:53:55 -04:00
Andrew Kelley 2b4134459d
fix alignment when slicing with comptime start and end index 2020-03-19 09:53:54 -04:00
Andrew Kelley 0707be8de8
fixes in semantic analysis needed to support this feature 2020-03-19 09:53:54 -04:00
LemonBoy e3c92d0532 ir: More changes to sentinel-terminated const arrays
* Don't add an extra slot for the sentinel. Most of the code keeps using
  the constant value from the type descriptor, let's harmonize all the
  code dealing with sentinels.

* Properly write out sentinel values when reinterpreting pointers at
  comptime.

* Allow the reading of the 0th element in a `[0:S]T` type.
2020-03-19 09:53:30 -04:00
Andrew Kelley 46ffc798b6
fix swapped logic for Windows
Remove `std.fs.deleteTree`. Callers instead should use
`std.fs.cwd().deleteTree`.

Add `std.fs.deleteTreeAbsolute` for when the caller has an absolute
path.
2020-03-18 16:42:47 -04:00
LemonBoy 1479c28b49
ir: Correct ABI size calculation for arrays
Zero-length array with a sentinel may not have zero size.

Closes #4749
2020-03-18 11:10:45 -04:00
momumi 47f7e66580 add more test cases for invalid number literals 2020-03-15 23:42:29 +10:00
momumi 925f710852 make parsing `0.0_e1` an error 2020-03-15 13:05:24 +10:00
momumi 7aac21c6f5 allow `_` separators in number literals (stage 1)
* Underscores `_` may be placed between two digits in a int/float literal
* Consecutive underscores are not allowed
* Fixed parsing bug in exponents of hexadecimal float literals.
  Exponents should always be base 10, but hex characters would be parsed
  inside the exponent and everything after them would be ignored. eg:
  `0x1.0p1ab1` would be parsed as `0x1.0p1`.
2020-03-15 12:38:35 +10:00
Andrew Kelley 75bda408cd
update stack traces test expectations 2020-03-13 17:50:29 -04:00
Andrew Kelley 656ba530d8
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-13 15:17:53 -04:00
Andrew Kelley f51bec321b
Merge pull request #4707 from Vexu/small-atomics
Support atomic operations with bools and non power of two integers
2020-03-12 18:55:16 -04:00
Vexu 71d776c3be
add note to disabled tests, improve comptime cmpxchg 2020-03-12 22:42:01 +02:00
Vexu 6dde769279
Simplify stores, use sext for signed ints 2020-03-12 22:02:58 +02:00
Vexu ce19638cd4
disable test on mipsel 2020-03-12 17:31:10 +02:00
Vexu 02c491e42a
translate-c fix order of tokens 2020-03-12 17:14:01 +02:00
Vexu 710b05b153
support `@atomicRmw` at comptime 2020-03-12 16:46:16 +02:00
Vexu dda711ba0d
translate-c treat c bools as ints 2020-03-12 14:40:47 +02:00
Andrew Kelley 895f67cc6d
Merge pull request #4710 from ziglang/io-stream-iface
rework I/O stream abstractions
2020-03-11 18:54:52 -04:00
Andrew Kelley 571f3ed161 fix stray warn() in runtime safety test 2020-03-11 18:45:09 -04:00
Andrew Kelley 04626c176b
Merge remote-tracking branch 'origin/master' into io-stream-iface 2020-03-11 15:47:07 -04:00
Vexu ec906a9771
fix codegen, update docs 2020-03-11 13:55:52 +02:00
Vexu 1f66435a6b
support cmpxchg at comptime 2020-03-11 12:02:05 +02:00
Vexu 64e60d8ae2
special case atomic operations on zero bit types 2020-03-11 10:29:15 +02:00
Andrew Kelley 2bff0dda79
fix regressions found by test suite 2020-03-10 20:22:30 -04:00
LemonBoy 4ab13a359d ir: Fix shift code for u0 operands 2020-03-10 23:04:49 +01:00
Vexu ee5b00a8b9
use atomic bools in std lib 2020-03-10 22:54:47 +02:00
Vexu 8dc188ebe0
support atomic operations with bools 2020-03-10 22:33:32 +02:00
LemonBoy 300fceac6e ir: Implement more safety checks for shl/shr
The checks are now valid on types whose size is not a power of two.

Closes #2096
2020-03-10 20:54:05 +01:00
Vexu cb4c488cbd
translate-c support struct field alignment 2020-03-10 15:57:57 +02:00
Vexu 4cace8f7c3
properly mangle shadowed primitive types 2020-03-10 15:52:54 +02:00
Vexu baec74645d
translate-c add daurnimator's pointer check to macro cast 2020-03-10 15:52:03 +02:00
Andrew Kelley 675f01f176
Merge pull request #4590 from xackus/fix-4587
fix failed assert on generic fn opaque return type
2020-03-09 22:10:57 -04:00
LemonBoy 1f44b29724 ir: Fix codegen of ?*T types where T is zero-sized
* Fix codegen for optional types that decay to a pointer, the type
  behaves as a boolean
* Fix comptime evaluation of zero-sized arrays, always initialize the
  internal array elements

Closes #4673
2020-03-09 22:08:56 -04:00
Andrew Kelley 638d5c3aca
Merge pull request #4700 from Vexu/noasync
Implement new noasync syntax
2020-03-09 18:36:01 -04:00
xackus e7cc456421 better error messages and more tests 2020-03-09 22:33:18 +01:00
LemonBoy 14bbb82832
ir: Fix lazy comparison between @alignOf and zero
Closes #4527
2020-03-09 14:05:38 -04:00
Vexu 3fd2cd4367
add LemonBoy's test 2020-03-09 18:43:09 +02:00
Vexu 3618256c97
implement noasync scopes 2020-03-09 12:33:24 +02:00
LemonBoy e2fd289a33 ir: Create usize result_loc for array subscript expr
Allow the subscript expression to infer the resulting type.

Closes #4169
2020-03-08 18:52:44 -04:00
LemonBoy 06d0dac0fb ir: Prevent crash in compiler error
Anonymous containers have no struct_field->type AstNode set, let's
always use the field node itself to make the error messages consistent.

Closes #4691
2020-03-08 18:12:50 -04:00
xackus 7782c76bee fix failed assert on generic fn opaque return type 2020-03-08 18:05:45 +01:00
Andrew Kelley f90fe1f8f2
Merge pull request #4687 from daurnimator/fix-typo
Fix grammar from "C pointers cannot point opaque types"
2020-03-08 12:44:56 -04:00
Vexu 692a974c3e
translate-c reject structs with VLAs 2020-03-08 12:11:37 +02:00
Vexu 5aa993cd61
translate-c fix nested loops without blocks. 2020-03-08 11:26:53 +02:00
daurnimator b85bb152bf
Fix grammar in error message 2020-03-08 19:18:06 +11:00
Andrew Kelley 9e60c89601
Revert "Translate C: Group generated casts"
This reverts commit 895672b3f9.
2020-03-08 03:53:06 -04:00
Andrew Kelley 8b80cb3072
Revert "translate-c remove redundant grouping, fix nested loops without blocks."
This reverts commit abe7305e16.
2020-03-08 03:52:52 -04:00
Andrew Kelley 96c07674fc
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-07 12:18:41 -05:00
Vexu abe7305e16 translate-c remove redundant grouping, fix nested loops without blocks. 2020-03-07 12:14:44 -05:00
Lachlan Easton 895672b3f9 Translate C: Group generated casts
Translate C: Put an alignCast in c style pointer casts to allow opaque types to cast properly in C macros

Translate C: add test case for aligning opaque types in pointer casts

Translate C: Fix @typeId -> @typeInfo

Add test case to run_translated_c for casting from pointer to opaque type
2020-03-07 03:26:42 -05:00
daurnimator 8f627593eb
Use in_stream.readAllAlloc where sensible 2020-03-06 18:49:12 -05:00
Andrew Kelley fa46bcb368
stage1: make get_optional_type more robust
Now it will emit a compile error rather than crashing when the child
type has not been resolved properly.

Introduces `get_optional_type2` which should be used generally inside
ir.cpp.

Fix some std lib compile errors noticed by the provided test case.

Thanks @LemonBoy for the test case. Closes #4377.

Fixes #4374.
2020-03-06 18:30:30 -05:00
Vexu 83d27f71ef translate-c more macro ops 2020-03-06 17:34:37 -05:00