Commit Graph

2290 Commits

Author SHA1 Message Date
Andrew Kelley
7a84fe79b9 pull request fixups 2019-02-18 13:05:26 -05:00
emekoi
9b3013d2f6 make @enumToInt work on union(enum)
closes #1711
2019-02-18 11:43:45 -05:00
LemonBoy
e280dce30f Translate parameterless C functions (#1978)
Both FunctionNoProto and FunctionProto are subclasses of FunctionType,
the only difference is that the former is parameterless.
2019-02-18 10:26:45 -05:00
LemonBoy
7d762648a4 Add align attribute for params pointers 2019-02-18 09:52:18 -05:00
Andrew Kelley
3e586264e5 Merge pull request #1972 from coypoop/netbsd
Add NetBSD support
2019-02-18 00:10:31 -05:00
Matthew McAllister
51783510b9 Deduplicate compile log statement warnings 2019-02-17 14:02:37 -08:00
LemonBoy
6cf38369d2 Silence gcc8 class-memaccess warnings
Use an explicit cast to tell gcc we know what we're doing.
2019-02-17 14:40:01 -05:00
Maya Rashish
bc10382ec1 Add NetBSD support
Mostly picking the same paths as FreeBSD.
We need a little special handling for crt files, as netbsd uses its
own (and not GCC's) for those, with slightly different names.
2019-02-17 09:17:34 +02:00
Andrew Kelley
c3c92ca8b1 translate-c: 4 more functions using C decls
See #1964
2019-02-16 19:48:39 -05:00
Andrew Kelley
2dfa76a1a7 fix regressions from previous commit when building with clang 2019-02-16 16:17:30 -05:00
Andrew Kelley
356cfa08f4 translate-c: proof of concept for transitioning to userland
See #1964
2019-02-16 15:26:44 -05:00
Andrew Kelley
f4c5bcfea5 refactor translate-c - no more using namespace clang
this is in preparation for #1964
2019-02-16 14:09:00 -05:00
Andrew Kelley
f57182456d Merge pull request #1898 from Sahnvour/translate-c-arrays
Translate c arrays
2019-02-16 14:07:41 -05:00
Andrew Kelley
ba56f365c8 bring zig fmt to stage1 2019-02-16 00:53:32 -05:00
emekoi
5736a9c6a9 removed hidden union tag in release modes 2019-02-15 20:02:09 -05:00
Andrew Kelley
a05e224150 typecheck the panic function
this adds the prototype of panic to @import("builtin")
and then uses it to do an implicit cast of the panic
function to this prototype, rather than redoing all the
implicit cast logic.

closes #1894
closes #1895
2019-02-15 19:19:28 -05:00
Andrew Kelley
7293e012d7 breaking: fix @sizeOf to be alloc size rather than store size
* Fixes breaches of the guarantee that `@sizeOf(T) >= @alignOf(T)`
 * Fixes std.mem.secureZero for integers where this guarantee previously
   was breached
 * Fixes std.mem.Allocator for integers where this guarantee previously
   was breached

Closes #1851
Closes #1864
2019-02-15 18:05:50 -05:00
Andrew Kelley
567c9b688e Merge pull request #1965 from ziglang/c-pointer-type
implement C pointers
2019-02-15 02:20:42 -05:00
Andrew Kelley
d6e0d82c32 translate-c: back to *c_void for opaque types
See #1059
2019-02-14 23:09:31 -05:00
Andrew Kelley
d5bbd74871 allow C pointers to have alignment
clang/gcc support pointer alignment attribute:
https://clang.llvm.org/docs/AttributeReference.html#align-value
2019-02-14 20:04:13 -05:00
Andrew Kelley
cc7060d0d9 compile error for C pointer with align attribute
See #1059
2019-02-14 20:02:29 -05:00
Andrew Kelley
df87044fd6 omit nonnull attribute for C pointers
See #1059
2019-02-14 16:10:12 -05:00
Andrew Kelley
6769183a9d fix implicit cast error unions with non-optional to optional pointer
and update self hosted compiler for C pointers

See #1059
2019-02-14 15:48:28 -05:00
Andrew Kelley
52c03de5c2 add missing compile error for OpaqueType inside structs/unions
closes #1862
2019-02-14 13:07:51 -05:00
Andrew Kelley
e03c770145 compile error tests for implicit C pointer casting
See #1059
2019-02-14 12:28:50 -05:00
Andrew Kelley
c58b802034 remove the "top of the comptime stack" compile error
It's still best practice to put `@setEvalBranchQuota` at the top of
the comptime stack, but as Jimmi notes in #1949, when a function
can be called at comptime and also can be the top of the comptime stack,
this compile error is fundamentally unsound.

So now it's gone.

closes #1949
2019-02-14 10:51:59 -05:00
Andrew Kelley
59de24817e runtime safety check for casting null to pointer
see #1059
2019-02-14 01:09:33 -05:00
Andrew Kelley
d4d2718bca comptime detection of casting null to pointer
See #1059
2019-02-14 00:40:39 -05:00
Matthew McAllister
0b3db784f1 Enable compileLog to display slices 2019-02-13 02:00:02 -05:00
Andrew Kelley
5699ab5e77 C pointers: errors for nested pointer casting regarding null
See #1059
2019-02-12 18:20:00 -05:00
Andrew Kelley
270933b1e9 compile error test for casting integer to c pointer
when the int has more bits than pointers

See #1059
2019-02-12 10:25:21 -05:00
Andrew Kelley
6f05e8d1be implicit casting between C pointer and optional non-C pointer
See #1059
2019-02-12 01:38:11 -05:00
Andrew Kelley
285e2f62ba disallow C pointers to non-C-ABI-compatible element types
See #1059
2019-02-12 00:51:06 -05:00
Andrew Kelley
0abe6d668e C pointers: delete dead code in ir_num_lit_fits_in_other_type 2019-02-12 00:39:08 -05:00
Andrew Kelley
069fc1a269 peer type resolution with C pointers
See #1059
2019-02-11 19:21:59 -05:00
Andrew Kelley
57a7ab0d33 comptime support for pointer arithmetic with hard coded addresses 2019-02-11 19:12:01 -05:00
Andrew Kelley
90b8cd4a45 add C pointer type to @typeInfo
See #1059
2019-02-11 16:07:40 -05:00
Andrew Kelley
342bca7f46 C pointer comparison and arithmetic
See #1059
2019-02-11 15:31:09 -05:00
Andrew Kelley
d9e01be973 translate-c: use C pointer type everywhere
See #1059
2019-02-11 14:56:59 -05:00
Andrew Kelley
661fc79fba langref: update grammar with c pointers
See #1059
2019-02-10 12:02:56 -05:00
Andrew Kelley
8e68d43ad3 avoid needlessly creating global constants
This deletes some legacy cruft, and produces leaner object files.
Example:

```
var x: i32 = 1234;

export fn entry() i32 {
    return x;
}
```

This produces:

```
@x = internal unnamed_addr global i32 1234, align 4
@0 = internal unnamed_addr constant i32* @x, align 8
```

and @0 is never even used. After this commit, @0 is not produced.

This fixes a bug: Zig was creating invalid LLVM IR when one of these
globals that shouldn't exist takes the address of a thread local
variable. In LLVM 8.0.0rc2, it would produce a linker error. But
probably after my bug report is solved it will be caught by the IR
verifier.

https://bugs.llvm.org/show_bug.cgi?id=40652
2019-02-10 10:58:00 -05:00
Andrew Kelley
73e8e46257 casting between C pointers and normal pointers
See #1059
2019-02-10 01:11:40 -05:00
Andrew Kelley
b8cbe3872e added C pointer type and implicit int-to-ptr for this type
See #1059
2019-02-10 00:14:30 -05:00
Andrew Kelley
caf672c495 @truncate: comptime 0 when target type is 0 bits
also if the dest type is a comptime_int, then treat it
as an implicit cast.

also compile error for attempting to truncate undefined

closes #1568
2019-02-09 21:38:34 -05:00
Andrew Kelley
34eb9f18ac fix not updating debug info type of optional error sets
There's an unfortunate footgun in the current design of error sets.
The debug info type for every error set is the same as the debug info
type of the global error set, which is essentially an enum forward
declaration. The problem is that when we "replace" the forward
declaration with the final value, once we know all the possible errors,
we have to update the pointers of every error set.

So the footgun is that if you ever copy the debug info type of the
global error set, you have to add the address of the pointer to a list
of pointers that need to be updated once we "replace" the forward
declaration. I activated the footgun when I introduced the optimization
that `?anyerror` types are the same size as `anyerror` types (using 0 as
the null value), because I introduced a pointer copy of the global error
set debug info type, but forgot to add it to the list.

I'm sure that there is a better way to code this, which does not have
the footgun, but this commit contains only a fix, not a reworking of the
logic.

closes #1937
2019-02-09 20:41:26 -05:00
Andrew Kelley
373e21bb56 implement vector math safety with ext and trunc 2019-02-09 16:24:29 -05:00
Andrew Kelley
0a7bdc0077 implement vector addition with safety checking
this would work if @llvm.sadd.with.overflow supported
vectors, which it does in trunk. but it does not support
them in llvm 7 or even in llvm 8 release branch.

so the next commit after this will have to do a different
strategy, but when llvm 9 comes out it may be worth coming
back to this one.
2019-02-09 14:44:33 -05:00
Andrew Kelley
46ddd5f5f4 fix compiler assertion failure when returning value from test
closes #1935
2019-02-08 19:23:46 -05:00
Andrew Kelley
c2db077574 std.debug.assert: remove special case for test builds
Previously, std.debug.assert would `@panic` in test builds,
if the assertion failed. Now, it's always `unreachable`.

This makes release mode test builds more accurately test
the actual code that will be run.

However this requires tests to call `std.testing.expect`
rather than `std.debug.assert` to make sure output is correct.

Here is the explanation of when to use either one, copied from
the assert doc comments:

Inside a test block, it is best to use the `std.testing` module
rather than assert, because assert may not detect a test failure
in ReleaseFast and ReleaseSafe mode. Outside of a test block, assert
is the correct function to use.

closes #1304
2019-02-08 18:23:38 -05:00
Andrew Kelley
f330eebe4b fix using the result of @intCast to u0
closes #1817
2019-02-07 16:02:45 -05:00