2909 Commits

Author SHA1 Message Date
Noam Preil
8538053940 Add header test harness 2020-12-23 01:14:35 +11:00
joachimschmidt557
45a88be573
stage2 ARM: add test cases for binary bitwise operations 2020-12-21 19:24:23 +01:00
Vexu
286077fec8 stage1: add missing error check on inferred struct field ptr 2020-12-21 12:40:51 +02:00
LemonBoy
84549b4267 stage1: Fix for generic fn monomorphization
Don't use the instantiation argument types to build the function
parameter array.

f416535768fc30195cad6cd481f73fd1e80082aa worked around the problem, this
commit solves it.
2020-12-19 19:45:48 -05:00
Andrew Kelley
53987c932c std.crypto.random: introduce fork safety
Everybody gets what they want!

 * AT_RANDOM is completely ignored.
 * On Linux, MADV_WIPEONFORK is used to provide fork safety.
 * On pthread systems, `pthread_atfork` is used to provide fork safety.
 * For systems that do not have the capability to provide fork safety,
   the implementation falls back to calling getrandom() every time.
 * If madvise is unavailable or returns an error, or pthread_atfork
   fails for whatever reason, it falls back to calling getrandom() every
   time.
 * Applications may choose to opt-out of fork safety.
 * Applications may choose to opt-in to unconditionally calling
   getrandom() for every call to std.crypto.random.fillFn.
 * Added `std.meta.globalOption`.
 * Added `std.os.madvise` and related bits.
 * Bumped up the size of the main thread TLS buffer. See the comment
   there for justification.
 * Simpler hot path in TLS initialization.
2020-12-18 15:54:01 -07:00
Andrew Kelley
d9368d7012 update test-stack-traces because start.zig updated 2020-12-18 12:22:46 -07:00
Andrew Kelley
7dab3ae135 update guess number standalone test 2020-12-18 12:22:46 -07:00
Veikka Tuominen
d3a57b96a9 translate-c: detect parenthesized string literals 2020-12-16 12:13:23 +02:00
Andrew Kelley
b3c1ced2c3
Merge pull request #7431 from LemonBoy/fix-7426
stage1: Fix crash in can_mutate_comptime_var_state
2020-12-15 15:07:49 -05:00
LemonBoy
8a2ab60fca stage1: Don't skip steps when analyzing union types
Don't cut any corner and properly run the type trough every single step
even though it has no fields (or, better, the sum of the size of all its
fields is zero).

Fix the logic to consider an explicit non-zero-sized tag enough to treat
the type as sized.

Closes #7451
2020-12-15 14:40:21 -05:00
LemonBoy
bbfa3550a0 Add a test case
Co-authored-with: Vexu <git@vexu.eu>
2020-12-14 17:39:35 +01:00
Andrew Kelley
c4f53d1ef6 fix deadlock with build-exe on an object for windows
The steps to repro this issue are:

zig build-obj hello.zig -target x86_64-windows-msvc
zig build-exe hello.obj -target x86_64-windows-msvc --subsystem console
-lkernel32 -lntdll

What was happening is that the main Compilation added a work item to
produce kernel32.lib. Then it added a sub-Compilation to build zig's
libc, which ended up calling a function with extern "kernel32", which
caused the sub-Compilation to also try to produce kernel32.lib. The main
Compilation and sub-Compilation do not coordinate about the set of
import libraries that they will be trying to build, so this caused a
deadlock.

This commit solves the problem by disabling the extern "foo" feature
from working when building compiler_rt or libc. Zig's linker code is now
responsible for putting the appropriate import libs on the linker line,
if any for compiler_rt and libc.

Related: #5825
2020-12-11 18:34:34 -05:00
Evan Haas
55cac65f95 Support casting enums to all int types.
In C, enums are represented as signed integers, so casting from an enum to an integer
should use the "cast integer to integer" translation code path. Previously it used the
"cast enum to generic non-enum" code path, because enums were not being treated as integers.
Ultimately this can produce zig code that fails to compile if the destination type does not
support the full range of enum values (e.g. translated C code that casts an enum value to an
unsigned integer would fail to compile since enums are signed integers, and unsigned integers
cannot represent the full range of values that signed ones can).

One interesting thing that came up during testing is that the implicit enum-to-int cast that
occurs when an enum is used in a boolean expression was parsed as an (int) by some versions of
the zig compiler, and an (unsigned int) cast by others. Specifically, the following code:

```c
	enum Foo {Bar, Baz};
	// ...
	enum Foo foo = Bar;
	if (0 || foo) {
		// do something
	}
```

When tested on MacOS, Linux, and Windows using a compiler built from the Windows Zig Compiler
Dev Kit, the above code would emit a cast to c_uint:

`if (false or (@bitCast(c_uint, @enumToInt(foo)) != 0)) {}`

However when tested on Windows with a Zig compiler built using MSVC, it produces:

`if (false or (@bitCast(c_int, @enumToInt(foo)) != 0)) {}`

In this particular case I don't think it matters, since a c_int and c_uint will have the same
representation for zero, but I'm not sure if this is ultimately the result of
implementation-defined behavior or something else.

Because of this, I added explicit casts in the `translate_c.zig` tests, to ensure that the
emitted zig source exactly matches across platforms. I also added a behavior test in
`run_translated_c.zig` that uses the old implicit casts from `translate_c.zig` to ensure
that the emitted Zig code behaves the same as the C code regardless of what cast is used.
2020-12-10 15:47:56 -05:00
Vexu
73016212a3 translate-c: support referencing c containers in macros 2020-12-10 14:45:48 +02:00
Vexu
7e30e83900
small fixes and zig fmt 2020-12-09 13:54:26 +02:00
Andrew Kelley
4592fd26b9 add std.testing.expectStringEndsWith 2020-12-08 21:59:24 -07:00
LemonBoy
8ac711596d stage1: Validate the specified cc for lazy fn types
Closes #7337
2020-12-08 19:09:25 -05:00
Andrew Kelley
58c8ad8ea8 tests: run-translated-c now respects -Dtarget 2020-12-08 13:46:05 -07:00
g-w1
6294c1136c
stage2: variable shadowing detection (#6969) 2020-12-06 19:36:49 +02:00
Veikka Tuominen
0268f54fcf
Merge pull request #7313 from LemonBoy/booo
Fix a few unsound optimizations on single-element union/enum
2020-12-06 19:31:07 +02:00
LemonBoy
b45d2968e5 Add some test cases for the previous commits 2020-12-05 20:14:04 +01:00
Andrew Kelley
2ed1ed9b32 stage2: introduce Module.failed_root_source_file
Use case:

zig build-exe non_existent_file.zig

Previous behavior:

error.FileNotFound, followed by an error return trace

Behavior after this commit:

error: unable to read non_existent_file.zig: FileNotFound
(end of stderr, exit code 1)

This turns AllErrors.Message into a tagged union which now has the
capability to represent both "plain" errors as well as source-based
errors (with file, line, column, byte offset). The "no entry point found"
error has moved to be a plain error message.
2020-12-04 17:21:55 -07:00
Jakub Konka
b6b7a6401c
Merge pull request #7293 from kubkon/fix-7030
stage1: allow idx 0 err to be put into error_name_table
2020-12-04 16:29:38 +01:00
Jakub Konka
e3db2be899 Add minimal standalone test case 2020-12-04 12:43:58 +01:00
Andrew Kelley
afaef36194 stage1: compile error for pointer arithmetic on ptr-to-array
See #2018
2020-12-03 17:07:13 -07:00
Timon Kruiper
ac85e1f2c8 stage2: make sure to emit the ZIR instructions of exported functions
Previously the emitted ZIR code would not have the ZIR instructions
of the exported functions.
2020-12-03 11:46:35 -08:00
Andrew Kelley
429a219f42 stage2: fix not detecting all dynamic libraries
Positional shared library arguments were not being detected as causing
dynamic linking, resulting in invalid linker lines. LLD did not have an
error message for this when targeting x86_64-linux but it did emit an
error message when targeting aarch64-linux, which is how I noticed the
problem.

This surfaced an error having to do with fifo.pipe() in the cat example
which I did not diagnose but solved the issue by doing the revamp that
was already overdue for that example.

It appears that the zig-window project was exploiting the previous
behavior for it to function properly, so this prompts the question, is
there some kind of static/dynamic executable hybrid that the compiler
should recognize? Unclear - but we can discuss that in #7240.
2020-11-30 20:25:28 -07:00
Andrew Kelley
263f25fea6
Merge pull request #7116 from joachimschmidt557/stage2-arm
stage2 ARM: add basic arithmetic instructions
2020-11-29 10:43:29 -08:00
LemonBoy
df99cfdf1e stage1: Fix typeInfo generation for arrays w/o sentinel
ZigTypeIdOptional types have a different way of specifying their payload
value depending on whether the child type is a pointer or not (plus some
other special cases).

Fixes #7251
2020-11-29 10:39:10 -08:00
LemonBoy
c80d196094 stage1: Add missing bitcast when rendering var ptr
Some types require this extra bitcast, eg. structs or unions with extra
padding fields inserted by the compiler.

Fixes #7250
2020-11-29 10:37:06 -08:00
joachimschmidt557
ceebcb2b4d
stage2 ARM: add test case for addition 2020-11-28 23:26:17 +01:00
LemonBoy
f91df39ad2 stage1: Fix crash in *[N]T to []T conversion with zst
Prevent the crash by not making the codegen try to access the
non-existing ptr field in the slice.

Closes #6951
2020-11-27 14:33:26 -08:00
Jakub Konka
f125c4f5c7 stage2 macho: enable end-to-end incremental linking tests on aarch64 2020-11-26 11:50:09 +01:00
LemonBoy
58c2bec589 stage1: Fix ICE when generating struct fields with padding
Make gen_const_ptr_struct_recursive aware of the possible presence of
some trailing padding by always bitcasting the pointer to its expected
type.

Not an elegant solution but makes LLVM happy and is consistent with how
the other callsites are handling this case.

Fixes #5398
2020-11-25 15:36:33 -08:00
Andrew Kelley
500fbdad57 update stack trace test with new start.zig line number 2020-11-25 00:40:50 -07:00
LemonBoy
bfa7e5c743 Update stack_traces test 2020-11-23 12:36:03 +01:00
Andrew Kelley
bf0cc32aa6
Merge pull request #7165 from LemonBoy/ppc64final
Make the PPC64 port usable
2020-11-20 17:40:17 -08:00
LemonBoy
6029114f84 stage1: Resolve usingnamespace decls when calling @typeInfo
Closes #7176
2020-11-20 17:01:23 -08:00
LemonBoy
2193bbfd93 Skip f16 to f128 conversion test for ppc64
As for aarch64 we're waiting for LLVM to emit calls to the specific
builtins that implement this conversion.
2020-11-20 08:38:11 +01:00
LemonBoy
f2b4e6b2e7 Better coverage in @splat tests
Cover more common and uncommon cases.
2020-11-20 08:38:10 +01:00
Andrew Kelley
73be59433f
Merge pull request #6928 from data-man/reduce_tests
Add more tests for reduce
2020-11-19 17:48:18 -08:00
Veikka Tuominen
cf819b95fe
Merge pull request #6829 from tadeokondrak/error-unsupported-callconv
stage1: Compile error instead of falling back to C for unsupported cc
2020-11-19 19:03:08 +02:00
Tadeo Kondrak
25ec2dbc1e Add builtin.Signedness, use it instead of is_signed 2020-11-19 18:59:21 +02:00
Vexu
3a28b659bd
add compile-error tests for unsupported calling convention 2020-11-19 14:25:46 +02:00
Tadeo Kondrak
c002a5026a
Update code to not use unsupported calling conventions for target 2020-11-19 14:01:07 +02:00
LemonBoy
2b7781d82a stage1: Fix undefined assignment for bitfields
Prevents silent memory corruption.

Closes #7055
2020-11-18 21:49:39 -08:00
pfg
cf7de64f1a stage1: improve error for missing a number type on a runtime var 2020-11-18 21:45:51 +02:00
Veikka Tuominen
a6470088c6
Merge pull request #6434 from daurnimator/fifo.pump
std: add LinearFifo(...).pump(src_reader, dest_writer)
2020-11-18 16:35:13 +02:00
frmdstryr
a39d3155b4 Change error when runtime value passed to comptime arg 2020-11-18 13:33:45 +02:00
LemonBoy
129ccad434 stage1: Reject undefined values when taking union ptr
The code rightfully assumes the union_val object to be fully initialized.

Closes #7019
2020-11-18 13:21:36 +02:00