4815 Commits

Author SHA1 Message Date
Timon Kruiper
ec3aedffb1 stage2: add initial implementation of func arguments in LLVM backend
The following works:
```
export fn _start() noreturn {
    assert(true);
    exit();
}

fn assert(cond: bool) void {}

fn exit() noreturn {
    unreachable;
}
```
2020-12-28 21:20:49 +01:00
Timon Kruiper
4a32d4f288 stage2: refactor (simplify) code structure of llvm_backend.zig 2020-12-28 21:20:49 +01:00
Timon Kruiper
09cf043efd stage2: add missing asserts and early returns for LLVM backend 2020-12-28 21:20:49 +01:00
Timon Kruiper
6b8d28312c stage2: fix building self-hosted without llvm-backend enabled. 2020-12-28 21:20:49 +01:00
Timon Kruiper
b059bb84b8 stage2: add LLVM codegen windows support to the self-hosted compiler
The following example generates a valid `main.exe`:
`zig build-exe main.zig -fLLVM -target x86_64-windows-gnu --subsystem console`

```
export fn wWinMainCRTStartup() noreturn {
    foo();
    exit();
}

fn foo() void {}

fn exit() noreturn {
    unreachable;
}
```
2020-12-28 21:20:46 +01:00
Timon Kruiper
071417161d stage2: add initial impl of LLVM backend in self-hosted compiler 2020-12-28 21:19:40 +01:00
Timon Kruiper
4a0d64300b stage2: rename llvm.zig to llvm_bindings.zig
Putting functions in this file will create functions like
`llvm.function`, and the compiler thinks these are llvm intrinsics.
2020-12-28 21:15:13 +01:00
Timon Kruiper
c81ae52ee0 stage2: fix compilation of self-hosted compiler with -Denable-llvm 2020-12-28 21:15:13 +01:00
Andrew Kelley
f75d4cbe56 Revert "stage2: add compile log statement (#7191)"
The addition of `addDeclErr` introduced a memory leak at every call
site, and I also would like to push back on having more than 1
compilation error per `Decl`.

This reverts commit 1634d45f1d53c8d7bfefa56ab4d2fa4cc8218b6d.
2020-12-28 11:24:53 -07:00
g-w1
c234761edd
stage2: make Alloc(Inferred) have mutabality info (#7570) 2020-12-28 15:42:22 +02:00
LemonBoy
fffb0904f8 stage1: Prevent crash with some lazy pointer types
Make sure the child element is not undefined, let's catch this problem
early on.

Closes #7568
2020-12-28 15:27:31 +02:00
Veikka Tuominen
d96f5b38a3
Merge pull request #7556 from Vexu/translate-c
some fixes
2020-12-28 00:55:44 +02:00
Veikka Tuominen
5acfaa35d3
Merge pull request #7557 from g-w1/stage2-hookup-compilerror
stage2: compileError builtin for zig code
2020-12-28 00:54:44 +02:00
Andrew Kelley
e5894221f7
Merge pull request #7553 from ziglang/fix-the-damn-deadlock
Fix the damn deadlock
2020-12-26 16:33:38 -08:00
Andrew Kelley
cb290ed6c9 stage2: Cache deadlock debugging only for safe build modes 2020-12-26 17:33:15 -07:00
Andrew Kelley
3f9588ca29 std: do not call malloc() between fork() and execv()
We were violating the POSIX standard which resulted in a deadlock on
musl v1.1.24 on aarch64 alpine linux, uncovered with the new ThreadPool
usage in the stage2 compiler.

std.os execv functions that accept an Allocator parameter are removed
because they are footguns. The POSIX standard does not allow calls to
malloc() between fork() and execv() and since it is common to both
(1) call execv() after fork() and (2) use std.heap.c_allocator,
Programmers are encouraged to go through the `std.process` API
instead, causing some dissonance when combined with `std.os` APIs.

I also slapped a big warning message on all the relevant doc comments.
2020-12-26 13:50:26 -07:00
g-w1
af80240678 make compileError use an UnOp since its operand is just a *Inst 2020-12-26 12:01:14 -05:00
g-w1
d6e9862049 add test for @compileError in zig code, not only zir 2020-12-26 11:34:15 -05:00
g-w1
504c78c022 change zir definition to use *Inst instead of []const u8 2020-12-26 11:13:13 -05:00
Veikka Tuominen
795770bcb4
stage1: const_values_equal error union, improve remaining "TODO" panics 2020-12-26 13:29:48 +02:00
Veikka Tuominen
50e8c3882a
translate-c: demote variadic functions to declarations 2020-12-26 13:02:17 +02:00
Veikka Tuominen
641bf4c46e
Merge pull request #7552 from Vexu/stage2-continue
stage2 continue
2020-12-26 12:26:16 +02:00
Andrew Kelley
ed39ff202b stage2: Cache: fix resource management of the deadlock debug code 2020-12-25 19:02:15 -07:00
Andrew Kelley
c7834f274d stage2: Cache: add debug deadlock detection code 2020-12-25 18:38:49 -07:00
g-w1
1634d45f1d
stage2: add compile log statement (#7191) 2020-12-26 02:40:49 +02:00
g-w1
939bd52c8a remove '||=' from stage1
It seems depreciated.
2020-12-26 02:39:34 +02:00
Veikka Tuominen
a50759325c
stage2: add error for unused labels 2020-12-26 02:36:12 +02:00
Veikka Tuominen
40aad4f47e
stage2: break and continue out of loops 2020-12-26 02:26:53 +02:00
Evan Haas
830bc41b1f Correctly cast bool to signed int in translate-c
Previously casting a bool to an int would result in the following Zig code:

    @intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(b))));

This is incorrect if `b` is true, since bitcasting a `u1` with the value 1
to an `i1` will result in the value -1. Instead, generate the following code:

    @as(c_int, @boolToInt(b));

Since @boolToInt returns a `u1`, this is only disallowed if the destination
type is one-bit and signed, which can only happen if it's a bitfield
(currently not supported by translate-c)
2020-12-25 14:38:31 +02:00
Andrew Kelley
9f33984119
Merge pull request #7520 from ziglang/tsan
add support for TSAN
2020-12-24 15:17:52 -08:00
Andrew Kelley
6ab9268a90 stage2: re-use compiler runtime libs across opt modes and strip flag
Previously Zig would need to recompile runtime libs if you changed the
values of --strip or -O. Now, unless the `debug_compiler_runtime_libs`
flag is set (which is currently not exposed to the CLI), Zig will always
choose ReleaseFast or ReleaseSmall for compiler runtime libraries.

When the main application chooses ReleaseFast or ReleaseSmall, that
value is propagated to compiler runtime libraries. Otherwise a decision
is made based on the target, which is currently ReleaseSmall for
freestanding WebAssembly and ReleaseFast for everything else.

Ultimately the purpose of this commit is to have Debug and ReleaseSafe
builds of applications still get optimized builds of, e.g. libcxx and
libunwind, as well as to spend less time unnecessarily rebuilding compiler
runtime libraries.
2020-12-24 14:11:58 -07:00
Andrew Kelley
894434988d libunwind: fix compile errors and warnings for 32-bit arm 2020-12-24 13:31:41 -07:00
LemonBoy
e18abab55a stage1: Create a new declaration scope for union enum types
Making the enum type share the scope with the parent union means every
declaration "bleeds" into the enum scope.
Let's mint a fresh empty scope for the enum type.

Thanks to @Vexu for the test case.

Closes #7532
2020-12-24 15:57:12 +02:00
Veikka Tuominen
83646df2cc
Merge pull request #7531 from Vexu/orphanage
Move ArrayListSentineled to std lib orphanage
2020-12-24 10:59:37 +02:00
Andrew Kelley
ed26b3204a stage2: tsan forces linking libc 2020-12-24 01:18:48 -07:00
Andrew Kelley
4d8c5dd4be stage1: add tsan LLVM passes when appropriate 2020-12-24 01:18:48 -07:00
Andrew Kelley
a4b134746f zig cc: support both ubsan and tsan at the same time 2020-12-24 01:18:48 -07:00
Andrew Kelley
3002856a7f libunwind: add __gcc_personality_v0 symbol 2020-12-24 01:18:48 -07:00
Andrew Kelley
8219d92987 stage2: fix Cache deadlock and build more of TSAN
* rename is_compiler_rt_or_libc to skip_linker_dependencies
   and set it to `true` for all sub-Compilations. I believe
   this resolves the deadlock we were experiencing on Drone
   CI and on some users' computers. I will remove the CI workaround in
   a follow-up commit.
 * enabling TSAN automatically causes the Compilation to link against
   libc++ even if not requested, because TSAN depends on libc++.
 * add -fno-rtti flags where appropriate when building TSAN objects.
   Thanks Firefox317 for pointing this out.
 * TSAN support: resolve all the undefined symbols. We are still seeing
   a dependency on __gcc_personality_v0 but will resolve this one in a
   follow-up commit.
 * static libs do not try to build libc++ or libc++abi.
2020-12-24 01:18:48 -07:00
Andrew Kelley
42b4a48bc9 WIP start adding support for TSAN 2020-12-24 01:18:47 -07:00
Andrew Kelley
177377b6e3 rework std.ResetEvent, improve std lib Darwin integration
* split std.ResetEvent into:
   - ResetEvent - requires init() at runtime and it can fail. Also
     requires deinit().
   - StaticResetEvent - can be statically initialized and requires no
     deinitialization. Initialization cannot fail.
 * the POSIX sem_t implementation can in fact fail on initialization
   because it is allowed to be implemented as a file descriptor.
 * Completely define, clarify, and explain in detail the semantics of
   these APIs. Remove the `isSet` function.
 * `ResetEvent.timedWait` returns an enum instead of a possible error.
 * `ResetEvent.init` takes a pointer to the ResetEvent instead of
   returning a copy.
 * On Darwin, `ResetEvent` is implemented using Grand Central Dispatch,
   which is exposed by libSystem.

stage2 changes:
 * ThreadPool: use a single, pre-initialized `ResetEvent` per worker.
 * WaitGroup: now requires init() and deinit() and init() can fail.
   - Add a `reset` function.
   - Compilation initializes one for the work queue in creation and
     re-uses it for every update.
   - Rename `stop` to `finish`.
   - Simplify the implementation based on the usage pattern.
2020-12-23 16:57:18 -08:00
Andrew Kelley
b2e1bce240 minor code readability changes 2020-12-23 13:36:21 -08:00
Andrew Kelley
78ab1f609a apply kprotty's WaitGroup fix 2020-12-23 13:36:21 -08:00
Andrew Kelley
829c00a77f kprotty ThreadPool and WaitGroup patch 2020-12-23 13:36:21 -08:00
Koakuma
588e828759 float_*_ieee597: only swap bytes when targeting different endianness than native
float_*_ieee597 functions should fill the buffer with the target endianness,
instead of always filling it in LE ordering.
2020-12-23 20:22:43 +02:00
xackus
1d3ceac770 stage1: LLVMSetModuleInlineAsm is deprecated 2020-12-23 20:21:47 +02:00
Veikka Tuominen
e5aab62228
move ArrayListSentineled to std lib orphanage 2020-12-23 16:24:22 +02:00
Alex Cameron
ca282184ae Implement parsing for multi-arg Clang options. 2020-12-23 15:03:11 +02:00
g-w1
51a904677c
update depreciated code (#7502)
* `zig env`:

* fix depreciated interface, update outStream -> writer
* make code more readable by updating `anytype` -> `std.fs.File.Writer`
2020-12-23 13:01:29 +02:00
Veikka Tuominen
ce7dcf2294
Merge pull request #7507 from joachimschmidt557/stage2-arm
stage2 ARM: implement basic binary bitwise operations
2020-12-23 12:17:40 +02:00