Commit Graph

1573 Commits

Author SHA1 Message Date
Andrew Kelley 2475f653fd stage1: add missing math.h includes 2020-07-24 17:02:03 -07:00
Andrew Kelley 995fd7314c Revert "Support taking extern pointers at comptime"
This reverts commit d3ebd42865.

This caused a build failure on multiple targets.
2020-07-24 14:06:44 -07:00
yvt d3ebd42865 Support taking extern pointers at comptime
This commit makes it possible to obtain pointers to `extern` variables
at comptime.

 - `ir_get_var_ptr` employs several checks to determine if the given
   variable is eligible for obtaining its pointer at comptime. This
   commit alters these checks to consider `extern` variables, which have
   runtime values, as eligible.

 - After this change, it's now possible for `render_const_val` to be
   called for `extern` variables. This commit modifies
   `render_const_val` to suppress the value generation for `extern`
   variables.

 - `do_code_gen` now creates `ZigValue::llvm_global` of `extern`
   variables before iterating through module-level variables so that
   other module-level variables can refer to them.

This solution is incomplete since there are several cases still
failing:

 - `global_var.array[n..m]`
 - `&global_var.array[i]`
 - `&global_var.inner_struct.value`
 - `&global_array[i]`

Closes #5349
2020-07-24 13:33:17 -07:00
Hiroki Noda 68e0632aa5 Use function attribute "frame-pointer" 2020-07-21 21:03:02 +00:00
Vexu 8110639c79 add 'anytype' to stage1 and langref 2020-07-11 17:41:33 +03:00
xackus 51f8c306d9 stage1: add missing runtime safety for @intCast unsigned -> signed of same bit count 2020-07-05 17:58:21 +02:00
Andrew Kelley 6938245fcc Merge remote-tracking branch 'origin/master' into zig-ast-to-zir 2020-06-22 23:22:17 -04:00
Robin Voetter 8696e52a3d Make unary minus for unsigned types a compile error (#5654)
* Make unary minus for unsigned types a compile error

* Add unreachable when generating unsigned negate
2020-06-21 14:55:44 -04:00
Andrew Kelley 355319fb67 zig cc: add missing cxxabi include path 2020-06-18 18:17:26 -04:00
Andrew Kelley 46b57748a5 stage1: stop emitting memset to undefined when safety is off 2020-06-18 17:12:56 -04:00
Andrew Kelley 7e58c56ca7 self-hosted: implement Decl lookup
* Take advantage of coercing anonymous struct literals to struct types.
 * Reworks Module to favor Zig source as the primary use case.
   Breaks ZIR compilation, which will have to be restored in a future commit.
 * Decl uses src_index rather then src, pointing to an AST Decl node
   index, or ZIR Module Decl index, rather than a byte offset.
 * ZIR instructions have an `analyzed_inst` field instead of Module
   having a hash table.
 * Module.Fn loses the `fn_type` field since it is redundant with
   its `owner_decl` `TypedValue` type.
 * Implement Type and Value copying. A ZIR Const instruction's TypedValue
   is copied to the Decl arena during analysis, which allows freeing the
   ZIR text instructions post-analysis.
 * Don't flush the ELF file if there are compilation errors.
 * Function return types allow arbitrarily complex expressions.
 * AST->ZIR for function calls and return statements.
2020-06-18 17:12:56 -04:00
Vexu a5379aa3ee implement @src 2020-06-18 21:11:09 +03:00
Jakub Konka 8ffa8ed9a8 Expose full llvm intrinsic 2020-06-09 00:22:34 -04:00
Jakub Konka 601e831f1d Add builtin for llvm.wasm.memory.grow.i32 intrinsic
This will allow the developer to request additional memory pages
from the runtime to be allocated for the Wasm app. Typical usage:

```zig
var wasm_pages = @wasmMemorySize();
@wasmMemoryGrow(1);
@import("std").debug.assert((wasm_pages + 1) == @wasmMemorySize());
```
2020-06-09 00:22:17 -04:00
Jakub Konka ce3f0077cf Add builtin for llvm.wasm.memory.size.i32 instrinsic
This will allow the developer to poll the runtime for currently
allocated memory in the number of Wasm pages. Typical usage:

```zig
var wasm_pages = @wasmMemorySize();
@import("std").debug.assert(wasm_pages > 0);
```
2020-06-09 00:22:17 -04:00
Timon Kruiper 6e89692d81 C ABI: Add C support for passing structs of floats to an extern function
Currently this does not handle returning these structs yet.

Related: #1481
2020-05-28 22:56:33 -04:00
foobles cb6bc5bdb5 Add caller location tracking for asserts (ir_assert, src_assert, ir_assert_gen) (#5393) 2020-05-26 12:55:31 -04:00
Andrew Kelley 69a5f0d797 Merge remote-tracking branch 'origin/master' into self-hosted-incremental-compilation 2020-05-16 01:26:18 -04:00
Andrew Kelley fda0eef9fb clear progress indicator before printing errors 2020-05-12 16:43:50 -04:00
Tadeo Kondrak b957dc29a4 Rename noasync to nosuspend in C++ compiler 2020-05-05 05:17:34 -06:00
George Roman a17eb15e11 Add missing state to C object cache 2020-04-27 12:21:48 -04:00
Andrew Kelley 6aeceec1f2 add CLI option -Bsymbolic for binding global references locally 2020-04-26 15:30:52 -04:00
George Roman 0c037a8561 Pass each target feature flag separately 2020-04-25 15:54:02 -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
LemonBoy 395b530387 stage1: Another hack for the C ABI compatibility
Applying the wrong ABI is slightly better than using the Zig ABI, the
whole thing is so wrong it should be burned to the ground.
2020-04-22 12:52:24 +02:00
LemonBoy 5eaf948e62 stage1: Fix wrong union access
Thanks to @frett27 on irc for reporting the compiler would segfault when
run on ARM.
2020-04-20 13:43:14 -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
LemonBoy ce21a784a4 stage1: More fixes for BE targets
* Fix packed struct alignment
* Adjust some tests
2020-04-13 17:35:14 -04:00
Michael Dusan 20b2457388 only use -nostdinc++ on c++ files
This is a follow-up to d27ef1aaef
and avoids compiler warnings:

    warning: argument unused during compilation: '-nostdinc++'
2020-04-12 01:03:27 -04:00
Andrew Kelley d27ef1aaef Zig treats -lstdc++ identically to -lc++
Thanks to Michael Dusan for figuring out what was happening here.

closes #5012
2020-04-12 00:50:16 -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
LemonBoy cc0fca9d83 stage1: Respect the specified name for extern var
Extend the logic used for function definitions to variables.

Closes #4947
2020-04-07 14:48:37 -04:00
Andrew Kelley 64d0960244 zig cc: recognize a few more linker options
* `--major-image-version`
 * `--minor-image-version`
 * `--stack`
2020-04-06 19:13:36 -04:00
LemonBoy f6cdc94a50 ir: Fix error checking for vector ops
The extra logic that's needed was lost during a refactoring, now it
should be fine.
2020-04-05 18:34:31 -04:00
LemonBoy fe77c38247 ir: Remove unused and commented out code 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 54ffcf95a8 ir: Support div/mod/rem on vector types
Closes #4050
2020-04-05 18:34:31 -04:00
Michaël Larouche c4a5f519f2 Do not parse native_libc.txt anymore when linking on native target, always run detection of libc.
Fixes #4772
2020-04-05 11:01:35 -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
LemonBoy 855edd2949 ir: Rewrite the bound checks in slice operator
Closes #4777
2020-04-03 10:58:39 +02:00
Andrew Kelley 5314641e11 zig cc: support more linker args 2020-04-02 17:29:22 -04:00
Andrew Kelley e4edc6d118 zig cc: respect -MF -MV -MD options
Zig disables its caching and forwards these args when any are provided.

see #4784
2020-04-02 15:47:27 -04:00
Andrew Kelley 783f73c7e3 zig cc properly handles -S flag and .ll, .bc extensions 2020-04-01 16:01:06 -04:00
Michael Dusan 212e2354b8 stage1: make C++ switch fallthrough an error
Make fallthrough an error when compiler supports it. This requires a new
macro that is defined with such compilers to be used as a statement, at
all fallthrough sites:

    switch (...) {
        case 0:
            ...
            ZIG_FALLTHROUGH;
        case 1:
            ...
            break;
        default:
            ...
            break;
    }

If we ever move to C++17 as minimal requirement, then the macro can be
replaced with `[[fallthrough]];` at statement sites.
2020-04-01 15:56:00 -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 d33766e6c7 Make sure that ZigTypeVector and ZigTypeArray have the same memory layout
Throughout the stage1 code it is assumed that these have the same layout,
but that was not the case. This caused an issue on 32-bit hardware.
2020-04-01 20:50:13 +02:00
Andrew Kelley 553f0e0546 fixups and revert a few things 2020-04-01 11:56:39 -04:00
daurnimator 7eb938c909 Use length field as passed in stage2 libc_installation instead of relying on zero termination 2020-04-01 10:36:38 -04:00
Andrew Kelley cfedd3aca2 revert detection of rtti and exceptions
This caused link errors in c++ code because it was not correct to pass
these flags to child codegens. And that was the only reason to detect
these flags. Otherwise we can safely rely on non-explicitly-detected
flag forwarding.
2020-03-30 17:42:30 -04:00