Commit Graph

1505 Commits

Author SHA1 Message Date
Jimmi Holst Christensen
6960cd156a Added regression test for #1607. fixes #1607 2019-04-07 03:18:51 +02:00
Jimmi Holst Christensen
65cf5a8e44 removed todo comment and added test 2019-04-06 11:04:55 +02:00
Andrew Kelley
846f72b57c
zig build: support single-threaded builds
and fix the zig test suite not setting the --single-threaded flag
2019-04-05 14:54:37 -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
Andrew Kelley
be0f656c21
fix @divFloor returning incorrect value and add __modti3
Closes #2152
See #1290
2019-04-04 15:45:37 -04:00
Andrew Kelley
c195d645e4
add regression test for #1025
closes #1025
2019-04-04 01:45:18 -04:00
Andrew Kelley
e4d595a8ba
fix thread local variables for non- position independent code
This fixes comes thanks to Rich Felker from the musl libc project,
who gave me this crucial information:

"to satisfy the abi, your init code has to write the same value
to that memory location as the value passed to the [arch_prctl]
syscall"

This commit also changes the rules for when to build statically
by default. When building objects and static libraries, position
independent code is disabled if no libraries will be dynamically
linked and the target does not require position independent code.

closes #2063
2019-04-04 01:08:26 -04:00
Andrew Kelley
5aee17e888
regression fixes and fix packed struct abi size 2019-04-02 18:31:19 -04:00
emekoi
b7aa289ae4 fixed broken casts in std 2019-03-31 16:47:34 -05:00
emekoi
4a64f26627 added error for implicit cast from *const T to *[1]T. credit: @kristate 2019-03-31 16:47:34 -05:00
Andrew Kelley
25ac2fe8cd
fix anon enum literal used with switch on union(enum)
closes #2141
closes #2142
2019-03-31 12:43:21 -04:00
Shawn Landden
66f13ba807 stage1: better error message when comparing against null
Closes: #2104
2019-03-28 15:54:44 -04:00
Andrew Kelley
5eaead6a56
implement allowzero pointer attribute
closes #1953

only needed for freestanding targets.

also adds safety for `@intToPtr` when the address is zero.
2019-03-25 12:55:45 -04:00
Andrew Kelley
3306e43984
add compile error test for invalid enum literal implicit cast
See #683
2019-03-24 18:51:24 -04:00
Andrew Kelley
da9d8a6ecf
implement peer type resolution for enum literals
See #683
2019-03-24 18:47:36 -04:00
Andrew Kelley
aff7b38838
make switch expressions allow enum literal types
See #683
2019-03-24 01:15:21 -04:00
Andrew Kelley
a736dfe6a1
implement implicit cast from enum literal to enum
See #683
2019-03-24 00:55:55 -04:00
Andrew Kelley
d0551db5cd
introduce the enum literal type
see #683
2019-03-24 00:44:18 -04:00
Andrew Kelley
64dddd7afe
add compile error for ignoring error
closes #772
2019-03-23 19:33:00 -04:00
Andrew Kelley
6a9c32f759
add regression tests for a bug fixed by an older commit
closes #1914
2019-03-23 19:01:51 -04:00
Andrew Kelley
4d50bc3f8d
add peer type resolution for *const T and ?*T
closes #1298
2019-03-23 18:48:12 -04:00
Andrew Kelley
89953ec83d
character literals: allow unicode escapes
also make the documentation for character literals more clear.
closes #2089

see #2097
2019-03-23 17:35:21 -04:00
Andrew Kelley
3e9697bb35
remove octal and hex floats from the language
closes #2093

This is technically a breaking change but I would be
surprised if anyone was actually using this feature.
2019-03-23 14:04:52 -04:00
Andrew Kelley
4615ed5ea0
float literals now parse using musl's 128 bit float code
fixes float literals not having 128 bit precision
2019-03-22 14:56:03 -04:00
Andrew Kelley
127bb124a0
Merge pull request #2091 from ziglang/bigint-print-fix
Fix bigint_append_buf
2019-03-22 10:23:18 -04:00
Marc Tiehuis
a3f42a5fe1 Fix compile-error test case for large integer type 2019-03-23 00:20:03 +13:00
Marc Tiehuis
e3b70fe4ba Simplify hex-float parsing code 2019-03-22 17:11:57 +13:00
Andrew Kelley
d04a1456df
hex float parsing: solve another case
this works now: 0x1.edcb34a235253948765432134674fp-1
2019-03-21 16:35:18 -04:00
Andrew Kelley
af509c68b0
fix parsing of large hex float literals
closes #2083
2019-03-21 16:17:29 -04:00
Andrew Kelley
15c316b0d8
add docs for assembly and fix global assembly parsing
Previously, global assembly was parsed expecting it to have
the template syntax. However global assembly has no inputs,
outputs, or clobbers, and thus does not have template syntax.
This is now fixed.

This commit also adds a compile error for using volatile
on global assembly, since it is meaningless.

closes #1515
2019-03-20 19:00:23 -04:00
Andrew Kelley
3c7555cb67
Merge remote-tracking branch 'origin/llvm8' 2019-03-20 13:34:07 -04:00
Andrew Kelley
2fdf69bc40
Merge pull request #2079 from Sahnvour/issue-2050
Fixes c_ABI tests on windows
2019-03-20 00:11:11 -04:00
Sahnvour
d669db7673 c_abi: activate tests on windows 2019-03-19 22:41:27 +01:00
Sahnvour
27d5e1f36c c_abi: add some tests for int and float parameter passing potentially using both registers and stack 2019-03-19 22:09:12 +01:00
Andrew Kelley
85256521ba
fix translate-c regression 2019-03-18 20:09:27 -04:00
Andrew Kelley
a581f4f0e2
Merge remote-tracking branch 'origin/master' into llvm8 2019-03-18 20:03:23 -04:00
Andrew Kelley
a17bf219c6
Merge pull request #2069 from ziglang/glibc-assert-translation
Implemented enough of translate-c to translate assert
2019-03-18 14:43:17 -04:00
Jimmi Holst Christensen
9171e7a7c1 More work on ignoring values correctly 2019-03-18 14:55:57 +01:00
Andrew Kelley
6abe6dbfe4 enable issue_339 test on macos
closes #1126
2019-03-16 01:18:46 -04:00
Andrew Kelley
6d6195424d
add regression test for invalid multiple dereferences
closes #1042
2019-03-16 00:23:18 -04:00
Andrew Kelley
c40448eb9a
add compile error for wrong type with use
closes #1557
2019-03-16 00:18:10 -04:00
Andrew Kelley
4a5cd0b895
fix while continue block not checking for ignored expression
closes #957
2019-03-15 23:52:11 -04:00
Andrew Kelley
9c13e9b7ed
breaking changes to std.mem.Allocator interface API
Before, allocator implementations had to provide `allocFn`,
`reallocFn`, and `freeFn`.

Now, they must provide only `reallocFn` and `shrinkFn`.
Reallocating from a zero length slice is allocation, and
shrinking to a zero length slice is freeing.

When the new memory size is less than or equal to the
previous allocation size, `reallocFn` now has the option
to return `error.OutOfMemory` to indicate that the allocator
would not be able to take advantage of the new size.

For more details see #1306. This commit closes #1306.

This commit paves the way to solving #2009.

This commit also introduces a memory leak to all coroutines.
There is an issue where a coroutine calls the function and it
frees its own stack frame, but then the return value of `shrinkFn`
is a slice, which is implemented as an sret struct. Writing to
the return pointer causes invalid memory write. We could work
around it by having a global helper function which has a void
return type and calling that instead. But instead this hack will
suffice until I rework coroutines to be non-allocating. Basically
coroutines are not supported right now until they are reworked as
in #1194.
2019-03-15 17:57:21 -04:00
Jimmi HC
5ae400fb39 fixed void cast and added the last tests 2019-03-15 19:11:46 +01:00
Andrew Kelley
4090fe81f6
Merge pull request #2068 from ziglang/workaround-for-2043
workaround for #2043
2019-03-15 11:19:21 -04:00
Jimmi Holst Christensen
a77b2a0810 Implemented enough of translate-c to translate assert
This required the following
* __extention__
* ({})
* Fixing if (0) ; else ;
2019-03-15 16:12:41 +01:00
Jimmi Holst Christensen
3ef9b899e4 workaround for #2043 2019-03-15 11:17:21 +01:00
Andrew Kelley
080dd27157
breaking: fix @typeInfo handling of global error set type
`builtin.TypeInfo.ErrorSet` is now `?[]Error`
instead of `struct{errors:[]Error}`.

closes #1936
2019-03-14 11:57:56 -04:00
Andrew Kelley
20c36949e1
fix target_requires_pic and reloc_mode
disable failing thread local variable test.
see #2063
2019-03-13 23:15:34 -04:00
Andrew Kelley
54edbc6815 Merge remote-tracking branch 'origin/master' into llvm8 2019-03-13 12:56:58 -04:00
LemonBoy
49838a9f3e
Fix generation of comptime slices
By erasing the global_refs field we'd trip any codepath using
const_values_equal_ptr to figure if two slices were different.
2019-03-13 11:35:05 -04:00
Andrew Kelley
761356209b
add test cases to cover switching on u0 values
closes #1563
2019-03-11 19:42:07 -04:00
Sahnvour
9b99356551 translate-c: additional test case for integer suffixes on 0 2019-03-11 16:36:27 -04:00
Andrew Kelley
f2ca2ace09
zig build: do a better job of detecting system paths
See #2041
2019-03-11 15:22:05 -04:00
Andrew Kelley
80e5af2be2
Merge pull request #2049 from ziglang/problematic-mtime-detection
stage1 caching system: detect problematic mtimes
2019-03-11 12:47:55 -04:00
Andrew Kelley
9efa18f687 enable C ABI tests on macOS 2019-03-11 12:21:30 -04:00
Andrew Kelley
e1fbb24d64
add test for spawning child process with empty environment
thanks to BenoitJGirard for pointing out the child process
implementation needs 3 extra null bytes in #2031
2019-03-11 11:56:08 -04:00
Jimmi Holst Christensen
357813b193
added tests 2019-03-11 10:55:43 -04:00
Andrew Kelley
6a5c2b249d
Revert "use unique test source names for test-gen-h"
This reverts commit 264b03d570.

This workaround is no longer necessary.
2019-03-11 10:35:39 -04:00
Andrew Kelley
4cb55d3af6 Merge remote-tracking branch 'origin/master' into llvm8 2019-03-10 18:07:28 -04:00
Sahnvour
fa9fcab620 translate-c: add support for integer suffixes on 0 (zero) litteral inside macro definitions 2019-03-10 14:56:35 -04:00
Andrew Kelley
3cdd2c0bdd Merge remote-tracking branch 'origin/master' into llvm8 2019-03-10 13:48:06 -04:00
Andrew Kelley
264b03d570 use unique test source names for test-gen-h 2019-03-09 09:52:33 -05:00
Andrew Kelley
91955dee58
breaking changes to zig build API and improved caching
* in Zig build scripts, getOutputPath() is no longer a valid function
   to call, unless setOutputDir() was used, or within a custom make()
   function. Instead there is more convenient API to use which takes
   advantage of the caching system. Search this commit diff for
   `exe.run()` for an example.
 * Zig build by default enables caching. All build artifacts will go
   into zig-cache. If you want to access build artifacts in a convenient
   location, it is recommended to add an `install` step. Otherwise
   you can use the `run()` API mentioned above to execute programs
   directly from their location in the cache. Closes #330.
   `addSystemCommand` is available for programs not built with Zig
   build.
 * Please note that Zig does no cache evicting yet. You may have to
   manually delete zig-cache directories periodically to keep disk
   usage down. It's planned for this to be a simple Least Recently
   Used eviction system eventually.
 * `--output`, `--output-lib`, and `--output-h` are removed. Instead,
   use `--output-dir` which defaults to the current working directory.
   Or take advantage of `--cache on`, which will print the main output
   path to stdout, and the other artifacts will be in the same directory
   with predictable file names. `--disable-gen-h` is available when
   one wants to prevent .h file generation.
 * `@cImport` is always independently cached now. Closes #2015.
   It always writes the generated Zig code to disk which makes debug
   info and compile errors better. No more "TODO: remember C source
   location to display here"
 * Fix .d file parsing. (Fixes the MacOS CI failure)
 * Zig no longer creates "temporary files" other than inside a
   zig-cache directory.

This breaks the CLI API that Godbolt uses. The suggested new invocation
can be found in this commit diff, in the changes to `test/cli.zig`.
2019-03-08 23:23:11 -05:00
Sahnvour
5469e3e3c1 missed change when switching TypeInfo to use comptime_int
fixes #2030
2019-03-06 15:27:56 -05:00
Andrew Kelley
0714e19598
Merge remote-tracking branch 'origin/master' into llvm8 2019-03-04 08:24:56 -05:00
Andrew Kelley
9c5852aa86
fix slice of C pointer
closes #2002
2019-03-03 13:04:04 -05:00
Andrew Kelley
e3b275fa47
fix build.zig not respecting --static
closes #2027
2019-03-03 12:35:09 -05:00
Andrew Kelley
d0d615d819
fix const initialization of optional C pointer to null 2019-03-03 10:47:06 -05:00
Andrew Kelley
e402455704
rename std lib files to new convention 2019-03-02 16:46:04 -05:00
Andrew Kelley
ea5cedced1
fix @typeName on slices
closes #2026
2019-03-02 14:31:27 -05:00
Andrew Kelley
67b4de33d2
compile error for import outside package path
closes #2024

there's a new cli option `--main-pkg-path` which you can use to choose
a different root package directory besides the one inferred from the
root source file

and a corresponding build.zig API:
foo.setMainPkgPath(path)
2019-03-02 10:38:27 -05:00
Andrew Kelley
5f7d9c5845
@typeInfo for structs and opaque types is the bare name 2019-03-01 17:15:58 -05:00
Andrew Kelley
582fdc2869
fix dependency loops, pub, tests, use decls, root source
* fix dependency loop detection
   - closes #679
   - closes #1500
 * fix `pub`
 * fix tests
 * fix use decls
 * main package file gets a special "" namespace path
2019-03-01 15:35:29 -05:00
Andrew Kelley
02f3a834b0
struct types get fully qualified names
and function symbol names become fully qualified
2019-02-28 15:40:57 -05:00
Andrew Kelley
5424b4320d
remove namespace type; files are empty structs
closes #1047
2019-02-28 10:11:32 -05:00
Andrew Kelley
2dcf1a2392
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-28 09:19:18 -05:00
Andrew Kelley
557983e502
fix handling when there are multiple externs and
an export in the same object

closes #529
2019-02-26 19:43:12 -05:00
Andrew Kelley
763357c9c3
add test coverage for type used as switch case
closes #996
2019-02-26 19:41:36 -05:00
Andrew Kelley
d5fc826437
add test coverage for binary OR on error sets
closes #1074
2019-02-26 19:34:22 -05:00
Andrew Kelley
ade10387a5
breaking changes to the way targets work in zig
* CLI: `-target [name]` instead of `--target-*` args.
   This matches clang's API.
 * `builtin.Environ` renamed to `builtin.Abi`
   - likewise `builtin.environ` renamed to `builtin.abi`
 * stop hiding the concept of sub-arch. closes #1526
 * `zig targets` only shows available targets. closes #438
 * include all targets in readme, even those that don't
   print with `zig targets` but note they are Tier 4
 * refactor target.cpp and make the naming conventions
   more consistent
 * introduce the concept of a "default C ABI" for a given
   OS/Arch combo. As a rule of thumb, if the system compiler
   is clang or gcc then the default C ABI is the gnu ABI.
2019-02-26 15:58:10 -05:00
Andrew Kelley
82fafca375 fix the libc compile error tests to only run on linux 2019-02-25 21:46:32 -05:00
Andrew Kelley
7571db05de
fix incorrectly trying to memset at comptime
closes #718
2019-02-25 20:33:40 -05:00
Andrew Kelley
4b7e285b76
add a regression test for #704
closes #704
2019-02-25 20:18:35 -05:00
Andrew Kelley
152db27146
better error message when forgetting to link against libc
closes #1698
2019-02-25 20:09:18 -05:00
Andrew Kelley
3ca861c7dd
add a compile error note when C import fails and not linking libc
closes #558
2019-02-25 19:31:30 -05:00
Andrew Kelley
7b8c5578c6
fix infinite recursion in type_has_one_possible_value
closes #2006
2019-02-25 16:28:23 -05:00
Andrew Kelley
525c2eaf5d building DLLs on Windows works better 2019-02-25 13:34:25 -05:00
Andrew Kelley
e76ce2c1d0
first class support for compiling C code
New CLI parameter: --c-source [options] [file]

It even works with `--cache on` when there are transitive dependencies.

Instead of `builder.addCExecutable`, use `builder.addExecutable` and pass
`null` for the root source file. Then use `builder.addCSourceFile`,
which takes the path to the C code, and a list of C compiler args.
Be sure to linkSystemLibrary("c") if you want libc headers to be
available.

Merge TestStep into LibExeObjStep. That was long overdue.
2019-02-25 11:45:00 -05:00
Andrew Kelley
52bb71867d
implement vector negation
also fix vector behavior tests, they weren't actually testing
runtime vectors, but now they are.

See #903
2019-02-22 13:28:57 -05:00
Andrew Kelley
2fe8a0831f
add regression test for bitcast to array
closes #421
2019-02-22 11:09:17 -05:00
Andrew Kelley
0c5f897904
fix @bitCast when src/dest types have mismatched handle_is_ptr
* separate BitCast and BitCastGen instructions
 * closes #991
 * closes #1934
 * unrelated: fix typo in docs (thanks gamester for pointing it out)
2019-02-22 08:49:27 -05:00
Andrew Kelley
cbce61a209
better field access of types which have one possible value
* When you do field access of a type which only has one possible
   value, the result is comptime-known.
 * StorePtr instructions which operate on pointers to types which
   only have one possible value, the result is a comptime no-op.

closes #1554
2019-02-21 16:09:14 -05:00
Andrew Kelley
1066004b79
better handling of arrays in packed structs
* Separate LoadPtr IR instructions into pass1 and pass2 variants.
 * Define `type_size_bits` for extern structs to be the same as
   their `@sizeOf(T) * 8` and allow them in packed structs.
 * More helpful error messages when trying to use types in
   packed structs that are not allowed.
 * Support arrays in packed structs even when they are not
   byte-aligned.
 * Add compile error for using arrays in packed structs when the
   padding bits would be problematic. This is necessary since
   we do not have packed arrays.

closes #677
2019-02-21 14:44:14 -05:00
Andrew Kelley
2bb795dc45
@sliceToBytes works at comptime
closes #262
2019-02-21 10:07:11 -05:00
Andrew Kelley
db31c2524d
extern structs support comptime bitcasting 2019-02-21 08:46:43 -05:00
Andrew Kelley
3ee9d06cbd
packed structs support comptime bitcasting
* `type_size_store` is no longer a thing. loading and storing a pointer
   to a value may dereference up to `@sizeOf(T)` bytes, even for
   integers such as `u24`.
 * fix `types_have_same_zig_comptime_repr` to not think that the
   same `ZigTypeId` means the `ConstExprValue` neccesarily has the
   same representation.
 * implement `buf_write_value_bytes` and `buf_read_value_bytes` for
   `ContainerLayoutPacked`

closes #1120
2019-02-20 22:40:41 -05:00
Andrew Kelley
079728752e
deduplicate compile errors for undeclared identifiers
closes #111
2019-02-20 08:04:46 -05:00
Andrew Kelley
1034af40f9
Merge branch 'slice-deref-failure' of https://github.com/matthew-mcallister/zig into matthew-mcallister-slice-deref-failure 2019-02-19 15:27:10 -05:00
LemonBoy
400006bbe7 Prevent crash in tagged enums rendering (#1986)
* Prevent crash in tagged enums rendering

* Add a test case
2019-02-19 15:18:57 -05:00
Andrew Kelley
ea3d9d5c53
add test for 74bdc1d1f8 2019-02-18 18:11:30 -05:00
Andrew Kelley
28bf768883 export _mh_execute_header with weak linkage
* also fix extern variables with initialiaztion values to generate runtime code
 * remove the workaround in example/shared_library/mathtest.zig
 * introduce the ability for global variables to have Weak and LinkOnce
   linkage
 * fix `@export` to work for non-functions. this code needs to be
   audited though.
 * fix comptime ptrcast not keeping bigger alignment
 * fix linker warnings when targeting darwin

closes #1903
2019-02-18 16:47:30 -05:00
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
Matthew McAllister
c70ee9177e Check for duped error messages in compile tests 2019-02-17 15:33:28 -08:00
Matthew McAllister
51783510b9 Deduplicate compile log statement warnings 2019-02-17 14:02:37 -08:00
Matthew McAllister
91989e70ba Fix lvalue dereference type checking
Previously, if a dereference instruction was an lvalue, it would fail to
typecheck that the value being dereferenced was indeed a pointer.
Although a little clunky, this change obviates the need for redundant
type checks scattered about the analysis.
2019-02-16 17:37:47 -08: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
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
ee5e196f88
add test for truncate on comptime integers
closes #703
2019-02-15 02:02:19 -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
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
Jimmi Holst Christensen
2911eb34de Added error for nesting vectors 2019-02-13 12:19:08 +01:00
Jimmi Holst Christensen
53297a1bd0 We already support vector bit operators, so let's test it 2019-02-13 11:40:32 +01:00
Jimmi Holst Christensen
c221b29c9d We already support vector on floats, so let's test it 2019-02-13 11:31:13 +01: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
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
bcbcb2e9ff
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-10 11:03:17 -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
1864acd326
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-09 18:57:39 -05:00
Andrew Kelley
373e21bb56
implement vector math safety with ext and trunc 2019-02-09 16:24:29 -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
Andrew Kelley
a94304d3e4
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-07 12:21:20 -05:00
Andrew Kelley
36bade5c56
fixups, and modify std.mem.join and std.os.path.resolve API
* zig fmt
 * std.mem.join takes a slice of slices instead of var args
 * std.mem.join takes a separator slice rather than byte,
   and always inserts it. Previously it would not insert the separator
   if there already was one, violating the documented behavior.
 * std.mem.join calculates exactly the correct amount to allocate
   and has no call to allocator.shrink()
 * bring back joinWindows and joinPosix and the corresponding tests.
   it is intended to be able to call these functions from any OS.
 * rename std.os.path.resolveSlice to resolve (now resolve takes
   a slice of slices instead of var args)
2019-02-07 00:42:41 -05:00
Andrew Kelley
c804ae2d6b
Merge branch 'zig-backport-std.os.path' of https://github.com/kristate/zig into kristate-zig-backport-std.os.path 2019-02-06 22:53:34 -05:00
Andrew Kelley
8a5d3e2eaf
Merge pull request #1924 from ziglang/tls
Implement Thread Local Variables
2019-02-06 20:21:13 -05:00
Andrew Kelley
d2602b442e
require running std lib tests coherently
this should actually improve CI times a bit too

See the description at the top of std/os/startup.zig (deleted in this
commit) for a more detailed understanding of what this commit does.
2019-02-06 14:32:20 -05:00
Andrew Kelley
b1775ca168
thread local storage working for linux x86_64 2019-02-06 13:48:04 -05:00