Commit Graph

2656 Commits

Author SHA1 Message Date
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
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
025a1475c4
emit better debug info for enums
fixes llvm assertion when building for windows
2019-04-02 19:40:33 -04:00
Andrew Kelley
6a7b75b73c
fix LLVM assertion failures 2019-04-02 19:09:25 -04:00
Andrew Kelley
15bd4aa54f fix setting union body twice 2019-04-02 18:43:25 -04:00
Andrew Kelley
e9dc504141
avoid tripping assertion for setting struct body twice 2019-04-02 18:31:19 -04:00
Andrew Kelley
d577dde636
passing all tests 2019-04-02 18:31:19 -04:00
Andrew Kelley
9780fd59f0
put the alignment hack in for unions too. fixes std tests 2019-04-02 18:31:19 -04:00
Andrew Kelley
cb0241fe44
behavior tests passing again 2019-04-02 18:31:19 -04:00
Andrew Kelley
4c38a8cce1
more regression fixes. empty test passes again 2019-04-02 18:31:19 -04:00
Andrew Kelley
5aee17e888
regression fixes and fix packed struct abi size 2019-04-02 18:31:19 -04:00
Andrew Kelley
ddb8aa73f5
more regression fixes 2019-04-02 18:31:18 -04:00
Andrew Kelley
30b2fb2fb5
bug fixes 2019-04-02 18:31:18 -04:00
Andrew Kelley
d7bc7635c0
put the hack from master branch back in 2019-04-02 18:31:18 -04:00
Andrew Kelley
d3f2fe2cef
remove the lazy value stuff
let's try to keep this branch to solving one problem at a time
2019-04-02 18:31:18 -04:00
Andrew Kelley
3dc8448680
introduce lazy values
but I think it's a bad idea, so I'm going to back out the change
2019-04-02 18:31:18 -04:00
Andrew Kelley
ee5064c053
decouple llvm types from zig types
Not tested yet, but it builds.

This closes #761, and lays the groundwork for fixing the remaining
false positive "foo depends on itself" bugs, such as #624.

It also lays the groundwork for implementing ability to specify
alignment of fields (#1512).
2019-04-02 18:31:17 -04:00
Andrew Kelley
2f96c55095 fix cache hash regression
fixes "warning: unexpected seek failure"

fix regression introduced by 27e31f0475

the fd should be closed only if returning with an error
2019-04-02 15:29:16 -04:00
Andrew Kelley
0cccba71d4
better error message when os_file_overwrite fails 2019-04-02 15:21:08 -04:00
Shawn Landden
27e31f0475 fix fd leak in stage1 cacheing code 2019-04-02 12:27:14 -04:00
Andrew Kelley
3c27d9c25a
Merge pull request #2147 from emekoi/fix1940
added error for implicit cast from *const T to *[1]T.
2019-04-01 11:35:03 -04:00
emekoi
4a64f26627 added error for implicit cast from *const T to *[1]T. credit: @kristate 2019-03-31 16:47:34 -05:00
Michael Dusan
aa794eb621 fix zig run to accept executable args
The `--` double-hyphen is now used to end further `zig` processing
of command line options. All arguments after `--` will be passed
on to the executable. eg. `--help` will be passed on.

`zig run foo.zig -- --help`

closes #2148
2019-03-31 17:01:11 -04: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
emekoi
8fdf8b6972 fixed libc command on mingw 2019-03-29 23:16:17 -05:00
Shawn Landden
66f13ba807 stage1: better error message when comparing against null
Closes: #2104
2019-03-28 15:54:44 -04:00
Andrew Kelley
64b2cf776c
implement target_c_type_size_in_bits for WASI 2019-03-27 16:08:45 -04:00
Shawn Landden
084724c689 use __ARM_EABI__, not __arm__
This is sort of pedantic and old OABI systems are unlikely to ever run zig.
2019-03-27 01:18:58 +00:00
Shawn Landden
65e234adfd fix build on arm64 2019-03-27 01:14:29 +00: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
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
14d416f83b
parse_f128.c: fix whitespace 2019-03-23 13:46:50 -04:00
Andrew Kelley
324cbb9864
stage1: implement get_dynamic_linker for riscv 2019-03-22 17:12:41 -04:00
Andrew Kelley
e9f066acae fix macos build instructions in readme and fix warning 2019-03-22 16:57:41 -04:00
Andrew Kelley
02767690e0 get rid of restrict; it's not supported by MSVC 2019-03-22 16:08:19 -04:00
Andrew Kelley
71c78cc9cf
avoid quad float literal syntax for MSVC 2019-03-22 16:06:18 -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
6f90d2c209 Fix bigint_append_buf
All current usages use base 10 and have a limb length of 1, hence why
we weren't hitting this error in practice.
2019-03-22 22:10:51 +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
c17b1635ca c_abi: when compiling for x86_64, differenciate between system V and windows ABI 2019-03-19 22:08:19 +01:00
Andrew Kelley
9801a1df6a
disable all C warnings when building musl 2019-03-19 15:04:39 -04:00
Andrew Kelley
3c36929603
zig targets prints the available libcs 2019-03-19 15:04:29 -04:00
Jimmi Holst Christensen
e508b85746 Updated parser to newest grammar 2019-03-19 10:36:37 +01:00
Andrew Kelley
fca83876d8
workaround for Ubuntu/Debian bug
see #2076
2019-03-18 20:56:46 -04: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
1b801bdbae
pass explicit frame pointer args when compiling C code 2019-03-18 16:59:48 -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
Andrew Kelley
7dfbeca13e
libc: separate linux headers from musl/glibc 2019-03-18 13:47:59 -04:00
Jimmi Holst Christensen
9171e7a7c1 More work on ignoring values correctly 2019-03-18 14:55:57 +01:00
Andrew Kelley
6acabd6b57 when linking msvcrt, also link ntdll.lib
See #2073
2019-03-17 14:14:05 -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
e861da03f9
macho linking: always -dynamic for non-static-libs 2019-03-14 00:07:05 -04:00
Andrew Kelley
862ac42a6e
ignore -lm on darwin because it's handled by libSystem 2019-03-13 23:44:38 -04:00
Andrew Kelley
927efe5f42 force windows to link against dynamic msvcrt
See #2064
2019-03-13 23:35:58 -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
5d2edac12d
breaking: remove --static; add -dynamic
`--static` is no longer an option. Instead, Zig makes things as static
as possible by default. `-dynamic` can be used to choose a dynamic
library rather than a static one.

`--enable-pic` is a new option. Usually it will be enabled
automatically, but in the case of build-exe with no dynamic libraries
on Linux or freestanding, Zig chooses off by default.

closes #1703
closes #1828
2019-03-13 19:50:41 -04:00
Andrew Kelley
85d0f0d45b
fix @setRuntimeSafety not able to override release modes 2019-03-13 14:46:53 -04:00
Andrew Kelley
284f6baf1c remove nios2 from list of libc targets 2019-03-13 13:33:00 -04:00
Andrew Kelley
54edbc6815 Merge remote-tracking branch 'origin/master' into llvm8 2019-03-13 12:56:58 -04:00
Andrew Kelley
d495dcc3c9
zig test respects --output-dir parameter 2019-03-13 12:35:10 -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
emekoi
1ed38a682e added z3 and fixed dynamic linker on mingw 2019-03-13 10:37:53 -04:00
Andrew Kelley
cf699ee068
don't resolve dynamic linker for static executables 2019-03-12 18:28:32 -04:00
Andrew Kelley
9741b2aab4
avoid a string that is too long for msvc 2019-03-12 18:09:40 -04:00
Andrew Kelley
62486c35a4
ability to build musl from source
bundles musl 1.1.21

See #514
2019-03-12 17:32:32 -04:00
Andrew Kelley
5734b7a37a
building musl start files from source 2019-03-12 13:18:52 -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
1d5e349a52
ir: fix handling of OnePossibleValueInvalid
this is the poison value which means a compile error has
already been reported
2019-03-11 11:09:15 -04:00
Jimmi HC
bcbb2650c5
check for type_has_one_possible_value and added correct caching to TypeInfo 2019-03-11 10:55:43 -04:00
Jimmi Holst Christensen
2d7f0ca387
fixed enum to union code 2019-03-11 10:55:10 -04:00
Jimmi Holst Christensen
5a52613caf
use cached const_void_val 2019-03-11 10:55:10 -04:00
Jimmi Holst Christensen
29accac74c
removed wild tab 2019-03-11 10:55:10 -04:00
Jimmi Holst Christensen
8eedec4f93
fixed #1600 2019-03-11 10:55:04 -04:00
Andrew Kelley
895fab156a fix build on windows 2019-03-11 10:35:04 -04:00
Andrew Kelley
3a6f19de48
stage1 caching system: detect problematic mtimes
closes #2045
2019-03-11 10:26:08 -04:00
Andrew Kelley
4cb55d3af6 Merge remote-tracking branch 'origin/master' into llvm8 2019-03-10 18:07:28 -04:00
Andrew Kelley
fec4555476
fix inconsistent type information of optional C pointers
solves an assertion failure in LLVM
2019-03-10 18:02:59 -04:00
Matt Whiteside
b63b3dc756 Add elf riscv32 and elf riscv64 as options in getLDMOption during construction of link job. 2019-03-10 15:06:17 -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
8624379c71
Merge pull request #2038 from ziglang/caching
breaking changes to zig build API and improved caching
2019-03-09 01:17:36 -05:00
Andrew Kelley
94e52dba85
fix docgen and fix unnecessarily adding .root suffix to objects 2019-03-09 01:00:45 -05:00
Andrew Kelley
85d23e68ee fix .d file parsing and string literal ast rendering 2019-03-08 23:40:39 -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
Jay Weisskopf
cddc77dd97 Remove glibc compat shim with restrictive license
Unlike the other glibc source code checked into the repo, `csu/init.c`
did not have a license clause that allowed linking without restrictions.

`_IO_stdin_used` is the only symbol in the file and appears to be a 20
year old compatibility shim for the glibc 2.0 ABI. Obsolete in 2.1.
2019-03-08 08:46:06 -05:00
Andrew Kelley
1e634a384c
Merge branch 'glibc'
See #514
2019-03-07 16:55:31 -05:00
Andrew Kelley
2bb6825baa
fix passing invalid argument -NDEBUG 2019-03-07 16:53:44 -05:00
Andrew Kelley
46242c4d38
fix -mllvm command line option regression 2019-03-07 16:08:25 -05:00
Andrew Kelley
bbbcf16ef9
fix linking glibc: caching static libs and
handle linking pthread, rt, dl, m better
2019-03-07 15:50:49 -05:00
Andrew Kelley
2caf39c961 fix .d file processing and use -MV to quote spaces 2019-03-07 14:30:50 -05:00
Andrew Kelley
431b3b2459 fix windows build 2019-03-07 13:32:43 -05:00
Andrew Kelley
197311d7dd windows and uefi don't have dynamic linkers 2019-03-07 13:25:17 -05:00
Andrew Kelley
4d8467fafc better behavior when cache dir unavailable
and choose different manifest dir for local cache to avoid
conflict with zig build
2019-03-07 13:16:52 -05:00
Andrew Kelley
e2ce00f272 fix regressions on macos 2019-03-07 13:04:10 -05:00
Andrew Kelley
ffaa4f0a87
dynamic_linker_path can be null on some targets 2019-03-07 12:21:27 -05:00
Andrew Kelley
ce76de35f1
multi-arch glibc headers 2019-03-07 12:16:10 -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
ccdef8c0fb
cross compile glibc startup files 2019-03-06 13:22:36 -05:00
Andrew Kelley
697b1233f0
support other architectures for glibc startup files 2019-03-06 12:10:03 -05:00
Andrew Kelley
ba144b366c
build libunwind.a from source and link it 2019-03-05 22:45:41 -05:00
Andrew Kelley
4c386436ea
support glibc dl, m, pthread, rt 2019-03-05 18:17:22 -05:00
Andrew Kelley
e06da10838
fix translate-c 2019-03-05 16:12:19 -05:00
Andrew Kelley
55a0016221
dynamic linker path is independent from libc installation 2019-03-05 16:00:28 -05:00
Andrew Kelley
0d10ab0680
stop linking against gcc files 2019-03-05 14:37:32 -05:00
Andrew Kelley
dd263eccb7
support crtbegin.o and crtend.o when using explicit libc 2019-03-05 14:12:46 -05:00
Andrew Kelley
c5fdea59d3
building glibc from source 2019-03-05 13:26:59 -05:00
Andrew Kelley
aeb16010f3
initial glibc support 2019-03-04 22:15:53 -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
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
f7835000b6
@returnAddress and @frameAddress return usize now 2019-03-02 15:34:58 -05:00
Andrew Kelley
ea5cedced1
fix @typeName on slices
closes #2026
2019-03-02 14:31:27 -05:00
Sahnvour
4bac22e888 all integers returned by @typeInfo are now comptime_int 2019-03-02 14:27:37 -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
764205ac13
better error message for -target windows CLI
closes #1169
2019-03-01 18:42:09 -05:00
Andrew Kelley
bed81089e1
Merge pull request #2020 from ziglang/kill-namespace-type
remove the (namespace) type and make every file an empty struct
2019-03-01 18:07:46 -05:00
Andrew Kelley
9c47bf68fa
gen-h: respect @export 2019-03-01 17:52:17 -05:00
Andrew Kelley
fc17b8ee8b remove unused function 2019-03-01 17:36:43 -05:00
Andrew Kelley
26128396f3
gen-h: use the bare type names for now 2019-03-01 17:36:08 -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
a7ddcabb50
fix type names 2019-03-01 15:49:52 -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
Marc Tiehuis
c4887d7f54 Use bitwise-and instead of modulo in __zig_return_error
Avoids emitting compiler-rt div calls on some targets.
2019-03-01 08:23:11 -05:00
Andrew Kelley
faf76032f1
fix "use" decls 2019-02-28 15:54:09 -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
6bc19b437c
updates to build with llvm 8.0.0rc3 2019-02-28 09:55:27 -05:00
Andrew Kelley
ea73b8e2b8
update clang driver code to 8.0.0rc3 2019-02-28 09:27:07 -05:00
Andrew Kelley
2dcf1a2392
Merge remote-tracking branch 'origin/master' into llvm8 2019-02-28 09:19:18 -05:00
Andrew Kelley
9753e87545 fix incorrect use of printf in previous commit 2019-02-27 20:09:07 -05:00
Andrew Kelley
3bfacf071e
print the command that failed when C source code fails to build
also respect the --color arg when building C code
2019-02-27 16:02:07 -05:00
Andrew Kelley
14ca0fd493
uefi os: better auto detection of subsystem 2019-02-27 09:30:48 -05:00
Andrew Kelley
d093f51f16
stage1: fix unused function error on freebsd and netbsd
closes #2012
closes #2013
2019-02-27 08:40:54 -05:00
Andrew Kelley
c59ce046a0 windows returns EINVAL for fopen when there is an asterisk in the name
closes #508
2019-02-26 23:02:57 -05:00
Andrew Kelley
0d48011f5e fix stage1 zig fmt on macos 2019-02-26 21:33:46 -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
6365f5a9f3 introduce sys_include_dir for when sys/* files are not with stdlib.h 2019-02-26 17:26:34 -05:00
Andrew Kelley
33174f11ef fix regressions on Windows 2019-02-26 16:24:32 -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
1ec1097bd3
use -nostdinc and sometimes -nolibc when compiling C code 2019-02-26 14:59:36 -05:00
Andrew Kelley
6fd2816431
use -nostdinc++ when compiling C code 2019-02-26 10:15:48 -05:00
Andrew Kelley
3932b6474e
use -nobuiltininc when compiling c code 2019-02-26 08:16:03 -05:00
Andrew Kelley
7571db05de
fix incorrectly trying to memset at comptime
closes #718
2019-02-25 20:33:40 -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
0f54728cf0
fix not finding libgcc_s when looking for native libc
closes #2011
2019-02-25 19:10:48 -05:00
Andrew Kelley
39605a7965
delete incorrect TODO comment
The code path is tested by behavior tests.

Thanks to various contributors, but mostly Marc Tiehuis,
bigint.cpp now has full coverage.

closes #405
2019-02-25 16:36:18 -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
0d4db8828a
@cImport works with --cache on
We pass -MD -MF args to clang when doing `@cImport`, which
gives us a complete list of files that the C code read from.
Then we add these to the cache. So even when using `@cImport`
Zig's caching system remains perfect. This is a proof of concept
for the mechanism that the self-hosted compiler will use to
watch and rebuild files.
2019-02-25 14:03:36 -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
e5d4862e14
Merge pull request #2003 from ziglang/zig-cc
add `zig cc` command to act like a C compiler
2019-02-24 16:28:49 -05:00
Andrew Kelley
8c2c6368f9
zig cc: work around clang calling GetCommandLine on Windows 2019-02-24 15:31:02 -05:00
Andrew Kelley
bcca76b3c4 zig cc: remove "polly" which was an undefined symbol on macos 2019-02-24 13:37:41 -05:00
Andrew Kelley
a77a17e2c2
add zig cc command to act like a C compiler
closes #490
2019-02-24 12:53:28 -05:00
Andrew Kelley
98869edb8b
fix zig fmt arg0 handled incorrectly 2019-02-23 20:25:33 -05:00
Andrew Kelley
6fd8d455bc
better libc detection (#1996)
* better libc detection

This introduces a new command `zig libc` which prints
the various paths of libc files. It outputs them to stdout
in a simple text file format that it is capable of parsing.
You can use `zig libc libc.txt` to validate a file.

These arguments are gone:
--libc-lib-dir [path]        directory where libc crt1.o resides
--libc-static-lib-dir [path] directory where libc crtbegin.o resides
--msvc-lib-dir [path]        (windows) directory where vcruntime.lib resides
--kernel32-lib-dir [path]    (windows) directory where kernel32.lib resides

Instead we have this argument:
--libc [file]                Provide a file which specifies libc paths

This is used to pass a libc text file (which can be generated with
`zig libc`). So it is easier to manage multiple cross compilation
environments.

`--cache on` now works when linking against libc.

`ZigTarget` now has a bool field `is_native`

Better error messaging when you try to link against libc or use
`@cImport` but the various paths cannot be found. It should also be
faster.

* save native_libc.txt in zig-cache

This avoids having to detect libc at runtime on every invocation.
2019-02-23 09:35:56 -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
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
c8ce351ec9
pull request fixups 2019-02-19 15:34:44 -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
db74832e40
valgrind client requests for undefined values
with this change, when you assign undefined, zig emits a few
assembly instructions to tell valgrind that the memory is undefined

it's on by default for debug builds, and disabled otherwise. only
support for linux, darwin, solaris, mingw on x86_64 is currently
implemented.

--disable-valgrind turns it off even in debug mode.
--enable-valgrind turns it on even in release modes.

It's always disabled for compiler_rt.a and builtin.a.

Adds `@import("builtin").valgrind_support` which lets code know
at comptime whether valgrind client requests are enabled.

See #1989
2019-02-19 12:07:56 -05:00
Andrew Kelley
c9fb5240d6
remove --no-rosegment workaround now that valgrind bug is fixed
See #896

Zig 0.3.0+ and Valgrind 3.14+ do not need the workaround.
2019-02-19 08:39:36 -05:00
kristopher tate
74bdc1d1f8
src/analyze.cpp: default to using param_node upon callconv error; 2019-02-18 17:57:24 -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
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