Commit Graph

2656 Commits

Author SHA1 Message Date
Andrew Kelley
09cff0d2bd
fix translate-c regression
introduced in eb65410b62
2019-05-09 20:11:56 -04:00
Andrew Kelley
eea2de108d
translate-c: progress on self-hosted function prototypes
See #1964
2019-05-09 16:52:30 -04:00
Andrew Kelley
214625587c
translate-c: use C API for builtin types
See #1964
2019-05-09 15:46:48 -04:00
Andrew Kelley
010963ce43
stage1: make some asserts print source location 2019-05-09 14:52:06 -04:00
Andrew Kelley
c459edac18
compile error for attempt to cast enum literal to error
closes #2203
2019-05-09 13:18:13 -04:00
Andrew Kelley
eb65410b62
translate-c: enough C tokenization/parsing to handle shifting in macros
See #2451
2019-05-09 12:48:38 -04:00
Andrew Kelley
62065a9aea
translate-c: handle int to ptr and ptr to int casting
See #2451
2019-05-09 12:17:23 -04:00
Andrew Kelley
a7346ea49f fix build on macOS
Sadly due to a workaround for LLD linker limitations on macOS
we cannot put libuserland into an .a file; instead we have to use object
files. Again due to linker limitations, bundling compiler_rt.o into
another relocatable object also doesn't work. So we're left with
disabling stack probing on macOS for the stage1 self-hosted code.

These workarounds could all be removed if the macos support in the LLD
linker improved, or if Zig project had its own linker that did not have
these issues.
2019-05-08 22:45:49 -04:00
Andrew Kelley
46e1c34fcf
self-hosted translate-c progress on function decls
See #1964
2019-05-08 22:05:59 -04:00
Andrew Kelley
9bbd71c9ab
add --bundle-compiler-rt function to link options
and use it when building libuserland.a

The self-hosted part of stage1 relies on zig's compiler-rt, and so we
include it in libuserland.a.

This should potentially be the default, but for now it's behind a linker
option.

self-hosted translate-c: small progress on translating functions.
2019-05-08 20:51:49 -04:00
Andrew Kelley
3bd5c16f39
stage1: remove unneeded extern function 2019-05-08 19:33:57 -04:00
Andrew Kelley
e3542196c0
translate-c: NULL pointers translate to null
See #1967
2019-05-08 19:21:54 -04:00
Andrew Kelley
a4aee8b24d
C pointers support if and orelse
See #1967
2019-05-08 18:47:14 -04:00
Andrew Kelley
0099583bd3
C pointers support .? operator
see #1967
2019-05-08 17:39:00 -04:00
Andrew Kelley
50bbb34594
C pointers support null
See #1967
2019-05-08 16:06:34 -04:00
LemonBoy
be7cacfbbe Implement stack probes for x86/x86_64
Enabled on non-Windows systems only since it already requires stack
probes.
2019-05-08 12:36:54 -04:00
Andrew Kelley
bd9c629c4c
always respect threadlocal for variables with external linkage
Previously if you had, for example:

extern "c" threadlocal var errno: c_int;

This would turn errno into a normal variable for --single-threaded
builds. However for variables with external linkage, there is an ABI
to uphold.

This is needed to make errno work for DragonFly BSD. See #2381.
2019-05-03 14:39:54 -04:00
Benjamin Feng
8d58dc715b Switch wasm export-all to only values marked exports 2019-05-03 13:23:02 -04:00
Andrew Kelley
3552180143
optimize @memset with undefined
When using `@memset` to set bytes to `undefined`, Zig notices this
case and does a single Valgrind client request rather than N.

Speeds up all allocators in safe modes.

Closes #2388
2019-05-03 01:25:03 -04:00
Dong-hee Na
c00c18de6a main: change --enable-pic and --disable-pic to -fPIC and -fno-PIC 2019-05-01 16:11:08 -04:00
Andrew Kelley
b4f8d68e2e
translate-c: fix using wrong enum
closes #2385
2019-04-30 03:14:45 -04:00
Andrew Kelley
a7f99c8ee9
self-hosted translate-c: iterate over top level decls
See #1964
2019-04-30 00:21:45 -04:00
LemonBoy
77383f968d translate-c: Emit @ptrCast + @alignPtr sequence
Avoid producing Zig code that doesn't compile due to mismatched
alignments between pointers.

Always emit a @alignOf instead of hardcoding the alignment value
returned by LLVM for portability sake of the generated code.
2019-04-29 21:30:19 -04:00
Matt Stancliff
a4e506510b Fix crash due to command line argument parsing
zig --help -> ok
zig --help --c-source -> ok
zig --c-source --help -> crash [fixed]

'i' was being incremented without regard for the 'argc' limit, so
we were running off the end of 'argv'.
2019-04-29 17:34:23 -04:00
Andrew Kelley
8afa1e800b
fix build (unused function warning)
d3c88a89 needed some #ifdefs shuffled around
2019-04-29 13:18:16 -04:00
Andrew Kelley
d3c88a8949
Merge pull request #2139 from emekoi/lib-on-mingw
implement linking to libc on mingw
2019-04-29 13:16:41 -04:00
LemonBoy
9902b604cb Fix generation of container initializers
The code creates temporary ConstExprValue with global_refs set to
nullptr and that's carried over to the final value. Doing so prevents
the deduplication mechanism to work correctly, causing all sorts of
runtime crashes.

Fixes #1636
Fixes #1608 (Even though it was already fixed by #1991)
2019-04-28 13:13:42 -04:00
emekoi
6057513cc7 fixed visibility of zig_libc_cc_print_file_name 2019-04-27 16:17:07 -05:00
emekoi
dfada0cc77 added static_crt_dir to libc file 2019-04-27 00:24:26 -05:00
Andrew Kelley
2d6520d5d4
zig fmt is built directly into stage1 rather than child process
Previously, `zig fmt` on the stage1 compiler (which is what we currently
ship) would perform what equates to `zig run std/special/fmt_runner.zig`

Now, `zig fmt` is implemented with the hybrid zig/C++ strategy outlined
by #1964.

This means Zig no longer has to ship some of the stage2 .zig files, and
there is no longer a delay when running `zig fmt` for the first time.
2019-04-26 20:46:28 -04:00
Andrew Kelley
c82acdbb9e
clean up test output
After 4df2f3d74f test names have the word "test" in them so the
redundant word is removed from test runner. Also move the prefix/suffix
to where it logically belongs in the fully qualified symbol name.
2019-04-26 15:10:13 -04:00
Andrew Kelley
1d95fdaf6e
Fix path canonicalization when $HOME has a trailing slash 2019-04-26 14:37:26 -04:00
LemonBoy
9ec4ccc68f Do not invoke UB in BigInt shr operations
Shifting a value of type T by an amount that's greater or equal to the
size of the type itself is UB.

Spotted by @tgschultz
2019-04-26 14:24:35 -04:00
rylmovuk
4df2f3d74f Change symbol name of tests in codegen
Tests now have the symbol name of the format `test "<name>"` in order
to be more easily distinguished from functions with similar names.
See issue #2267.
2019-04-26 14:23:56 -04:00
Andrew Kelley
e1bf74fca3
translate-c: put -x c back in there, it's necessary 2019-04-25 00:06:58 -04:00
Andrew Kelley
712274997e
translate-c: unify API for self-hosted and C++ translate-c
See #1964
2019-04-25 00:06:57 -04:00
Andrew Kelley
976080462c
translate-c: a little closer to self-hosted implementation 2019-04-25 00:06:54 -04:00
Shawn Landden
8ef7f6febb remove Shebang (#!) support
Closes:  #2165
2019-04-24 23:34:19 -04:00
Andrew Kelley
fb2acaff06
@sizeOf returns 0 for comptime types
This defines `@sizeOf` to be the runtime size of a type, which means
that it is zero for types such as comptime_int, type, and (enum
literal).

See #2209
2019-04-24 22:31:53 -04:00
Andrew Kelley
ad994c9642
Merge pull request #2296 from LemonBoy/translate-c-stuff
Handle implicit casts in translate-c
2019-04-24 14:43:46 -04:00
Jimmi Holst Christensen
e4a86d4653
Merge pull request #2351 from ziglang/fixed-2346
fixes #2346
2019-04-24 18:42:55 +02:00
Jimmi HC
1a2e02e267 fixed #2356
const_ptr_pointee_unchecked did not take into account that if the
pointer is zero sized, then const_val->data.x_ptr.special would be
ConstPtrSpecialInvalid. This commit fixes this by also checking
that the child type of the pointer only have one possible value
and just returns that value.
2019-04-24 15:04:58 +02:00
LemonBoy
70c2e86da3 Add translation from pointer to boolean 2019-04-22 22:23:41 +02:00
LemonBoy
a44ad08954 Add some zig_panic for 80-bit float codepaths 2019-04-22 22:23:41 +02:00
LemonBoy
9ea600b634 Correct rendering of AST Char literals 2019-04-22 22:23:41 +02:00
LemonBoy
8d05330cf7 More precise translation of char literals 2019-04-22 22:23:41 +02:00
LemonBoy
69bc5fd04d translate-c: Pointer to/from integral conversion 2019-04-22 22:16:30 +02:00
LemonBoy
d3dd49c403 translate-c: Support for integer to boolean conversions 2019-04-22 22:16:29 +02:00
hryx
5765cbd2de
Allow tag expr for enum but not struct 2019-04-22 00:14:51 -07:00
emekoi
f4c5fa7ff4 renamed add_gnu_link_args 2019-04-20 00:12:33 -05:00
LemonBoy
19b8278f91 translate-c: Convert char literals 2019-04-19 11:50:30 +02:00
LemonBoy
6d95c5d15c translate-c: Parse float/double literals 2019-04-19 11:50:30 +02:00
LemonBoy
1fda44cbc8 translate-c: support conversion to/from fp types 2019-04-19 11:50:30 +02:00
Andrew Kelley
ff3cdbc3a0
stage1 assertions always on, and have stack traces 2019-04-17 15:58:20 -04:00
Andrew Kelley
89763c9a0d
stage1 is now a hybrid of C++ and Zig
This modifies the build process of Zig to put all of the source files
into libcompiler.a, except main.cpp and userland.cpp.

Next, the build process links main.cpp, userland.cpp, and libcompiler.a
into zig1. userland.cpp is a shim for functions that will later be
replaced with self-hosted implementations.

Next, the build process uses zig1 to build src-self-hosted/stage1.zig
into libuserland.a, which does not depend on any of the things that
are shimmed in userland.cpp, such as translate-c.

Finally, the build process re-links main.cpp and libcompiler.a, except
with libuserland.a instead of userland.cpp. Now the shims are replaced
with .zig code. This provides all of the Zig standard library to the
stage1 C++ compiler, and enables us to move certain things to userland,
such as translate-c.

As a proof of concept I have made the `zig zen` command use text defined
in userland. I added `zig translate-c-2` which is a work-in-progress
reimplementation of translate-c in userland, which currently calls
`std.debug.panic("unimplemented")` and you can see the stack trace makes
it all the way back into the C++ main() function (Thanks LemonBoy for
improving that!).

This could potentially let us move other things into userland, such as
hashing algorithms, the entire cache system, .d file parsing, pretty
much anything that libuserland.a itself doesn't need to depend on.

This can also let us have `zig fmt` in stage1 without the overhead
of child process execution, and without the initial compilation delay
before it gets cached.

See #1964
2019-04-16 19:12:20 -04:00
Michael Dusan
611d4bc6a1 stage1: const_values_equal support tagged union 2019-04-16 13:55:23 -04:00
Andrew Kelley
4e2f6ebf39
freestanding target adds -ffrestanding to cc parameters
closes #2287
2019-04-16 12:06:14 -04:00
Andrew Kelley
3226b5315e
translate-c: move some code to the C API
See #1964
2019-04-16 04:32:48 -04:00
Andrew Kelley
f488f3fd03
remove workaround for LLD bug
Zig's embedded LLD now has a patch to resolve the deadlock race
condition, and the patch is getting upstreamed too, so this
closes #2283.
2019-04-16 03:58:15 -04:00
Andrew Kelley
6692cbbe18
disable threads when linking WebAssembly to work around an LLD bug
See #2283
2019-04-15 20:41:50 -04:00
Andrew Kelley
579dd74114
fix Debug mode when error return tracing is off
Previously the code for generating a panic crash expected
one of the parameters to be the error return trace. Now
it does not expect that parameter when g->have_err_ret_tracing
is false.

Closes #2276
2019-04-15 20:17:06 -04:00
Shritesh Bhattarai
a0d2185199 wasm: add wasm-import-module attr to extern 2019-04-15 17:00:04 -05:00
Shritesh Bhattarai
9465c6d538 link: exemption for wasm instead of wasi 2019-04-15 16:59:34 -05:00
Andrew Kelley
5cb18e9c6f
translate-c: move some code to the C API
See #1964
2019-04-15 00:32:27 -04:00
Andrew Kelley
27253f09b6
organize how the single threaded option is passed around 2019-04-14 11:01:01 -04:00
Andrew Kelley
63a970a548
Merge pull request #2268 from shritesh/wasi
wasm: preliminary WASI OS support
2019-04-14 10:45:30 -04:00
Shritesh Bhattarai
0f1d92e2cf wasm: force single threaded 2019-04-14 10:21:48 -04:00
Shritesh Bhattarai
94e0871603 wasi: don't pass --no-entry to linker 2019-04-14 00:03:32 -05:00
Shritesh Bhattarai
ecd0f89254 wasi: better extern wasi logic 2019-04-13 23:49:02 -05:00
Shritesh Bhattarai
a2d8f03092 support extern "wasi" functions 2019-04-13 22:28:58 -05:00
Andrew Kelley
68d7e4a1b6
better handle quota of setEvalBranchQuota
Now that c58b802034 has removed
the "top of the comptime stack" requirement, the branch quota
can be modified somewhere other than the top of the comptime stack.

This means that the quota of a parent IrExecutable has to be
modifiable by an instruction in the child.

Closes #2261
2019-04-13 16:55:59 -04:00
Andrew Kelley
4a2ccd6fb8
Merge pull request #2266 from bnoordhuis/fix-cache-lseek-ebadf
don't close cache manifest file prematurely
2019-04-13 16:17:12 -04:00
Ben Noordhuis
93e89b3b7e don't close cache manifest file prematurely
ErrorInvalidFormat is not a fatal error so don't close the cache
manifest file right away but instead let cache_final() handle it.

Fixes the following (very common) warning when running the test suite:

    Warning: Unable to write cache file [..]: unexpected seek failure

The seek failure is an lseek() system call that failed with EBADF
because the file descriptor had already been closed.
2019-04-13 12:33:29 +02:00
Ben Noordhuis
ea5518f69e make os_file_close poison file handle after close
This helps track down use-after-close bugs.
2019-04-13 12:31:49 +02:00
Andrew Kelley
9d229791c6
translate-c: move some code to the C API
See #1964
2019-04-12 14:39:12 -04:00
Shritesh Bhattarai
63f2e96eea wasm: use .wasm ext for exe 2019-04-12 13:17:59 -04:00
Andrew Kelley
6284a4c534
translate-c: move some code to the C API
See #1964
2019-04-12 03:56:38 -04:00
Andrew Kelley
f860493f23
translate-c: move some code to the C API
See #1964
2019-04-12 03:12:22 -04:00
Andrew Kelley
6f34d08aed
translate-c: move some code to the C API
See #1964
2019-04-11 23:38:41 -04:00
Shritesh Bhattarai
5f8dbcac06 wasm: disable error ret tracing 2019-04-11 16:37:40 -04:00
Andrew Kelley
b960f1d922
translate-c: move some code to the C API
See #1964
2019-04-11 15:33:26 -04:00
Andrew Kelley
a895c59971
delete unused function
missed by 27cd830ec8
2019-04-11 14:33:43 -04:00
Matthew Iannucci
27cd830ec8 Add initial support for iOS targets (#2237)
* Add iOS C int sizes... try to hack in iOS DebugInfo

* Get rid of ios link check for now

* Remove macos linkversion check
2019-04-11 13:15:17 -04:00
Andrew Kelley
dff201540f
translate-c: move some code to the C API
See #1964
2019-04-11 03:59:12 -04:00
LemonBoy
8f5753ba9f Fix normalization of right-shifted BigInt at CT
The pointer value for the `digits` field was being treated as if it were
a limb.

Fixes #2225
2019-04-11 03:49:15 -04:00
Shritesh Bhattarai
13798d26c7 pass exec_path to zig run 2019-04-10 20:07:35 -04:00
Shritesh Bhattarai
666e879925 Build compiler_rt for WASM exe 2019-04-10 19:14:19 -04:00
Andrew Kelley
a71bfc249d compiler-rt: better way to do the ABI required on Windows
This removes the compiler_rt.setXmm0 hack. Instead, for
the functions that use i128 or u128 in their parameter and
return types, we use `@Vector(2, u64)` which generates
the LLVM IR `<2 x i64>` type that matches what Clang
generates for `typedef int ti_int __attribute__ ((mode (TI)))`
when targeting Windows x86_64.
2019-04-10 18:47:14 -04:00
kristopher tate
627b52fe65
src/ir.cpp: don't call-out to analyze_type_expr;
replaces `analyze_type_expr` with `ir_analyze_type_expr`
2019-04-07 10:37:43 +09:00
Jimmi Holst Christensen
65cf5a8e44 removed todo comment and added test 2019-04-06 11:04:55 +02:00
Jimmi Holst Christensen
3109c89850 fixed 1726 2019-04-06 10:56:07 +02:00
Andrew Kelley
f00adb47f5
ir: avoid dependency on isnan
there's a simple way to check for nan that does not need this header.
hryx on IRC reported that Linux Mint based on ubuntu 16.04, kernel
4.15.0, x86_64 did not have the isnan function.
2019-04-06 01:03:30 -04:00
Andrew Kelley
83390bdfdd
fix dereferencing a zero bit type
Before only u0 was special cased in handling a dereference;
now all zero bit types are handled the same way. Dereferencing
a pointer to a zero bit type always gives a comptime-known
result.

This previously had been failing on master branch but went unnoticed
because until 846f72b57c the CI server was mistakenly not actually
running the single-threaded tests with --single-threaded.

This fixes the standard library tests with --single-threaded
--release-fast.
2019-04-05 20:18:26 -04:00
Shritesh Bhattarai
3854bb9198 wasm: Pass --allow-undefined and --export-all to the linker 2019-04-05 18:46:11 -04:00
Andrew Kelley
c47c2a2f2a stage1: fix debug builds on macOS 2019-04-05 15:39:00 -04:00
Andrew Kelley
1dc6751721
fix NaN comparing equal to itself
This was broken both in comptime code and in runtime code.

closes #1174
2019-04-04 22:07:15 -04:00
emekoi
0bd4901a17 fixed linking of system libraries on mingw 2019-04-04 21:07:02 -05:00
emekoi
6cc443ee45 added code for linking libc on mingw 2019-04-04 19:51:55 -05:00
emekoi
ecd2332bb5 made lld flags on windows consistent 2019-04-04 19:51:55 -05:00
Andrew Kelley
5866dfe4d9
Merge pull request #2109 from emekoi/fix-mingw
fixed libc command on mingw
2019-04-04 15:55:40 -04:00