4282 Commits

Author SHA1 Message Date
Jakub Konka
e9bee08f88 Try audodetecting sysroot when building Darwin on Darwin
This is now no longer limited to targeting macOS natively but also
tries to detect the sysroot when targeting different Apple platforms
from macOS; for instance targeting iPhone Simulator from macOS. In
this case, Zig will try detecting the SDK path by invoking
`xcrun --sdk iphonesimulator --show-sdk-path`, and if the command
fails because the SDK doesn't exist (case when having CLT installed only)
or not having either Xcode or CLT installed, we simply return null
signaling that the user has to provide the sysroot themselves.
2021-08-10 13:41:10 +02:00
Jakub Konka
7007684984 macho: swap out VERSION_MIN for BUILD_VERSION
this makes the app successfully run on the iOS simluator!
2021-08-10 13:41:10 +02:00
Jakub Konka
049ff45430 macho: add basic support for building iOS binaries
* ensure we correctly transfer `-iwithsysroot` and
  `-iframeworkwithsysroot` flags with values from `build.zig` and that
  they are correctly transferred forward to `zig cc`
* try to look for `libSystem.tbd` in the provided syslibroot - one
  caveat that the user will have to specify library search paths too
2021-08-10 13:40:39 +02:00
Frank Denis
2ccd023c6a
Ip4Address parser: reject 0-prefixed components (#9538)
Some parsers interpret these as octal, some don't, and the confusion can lead to vulnerabilities.

Return error.NonCanonical when parsing IPv4 addresses with 0 prefixes.
2021-08-09 22:44:23 +02:00
Andrew Kelley
d94252496e
Merge pull request #9531 from squeek502/split-tokenize-generic
Make mem.split and mem.tokenize generic instead of assuming u8
2021-08-07 11:14:45 -07:00
Klecko
5789036b86 linux: add missing FUTEX definitions 2021-08-07 15:35:27 +03:00
Ryan Liptak
d31352ee85 Update all usages of mem.split/mem.tokenize for generic version 2021-08-06 02:01:47 -07:00
Ryan Liptak
05fd20dc10 Make mem.split and mem.tokenize generic instead of assuming u8
This allows these functions to work on slices of u16, etc
2021-08-06 01:53:07 -07:00
Andrew Kelley
ea7bdeb67d
Merge pull request #9517 from ziglang/generic-functions
stage2 generic functions
2021-08-05 23:32:42 -07:00
Andrew Kelley
47f2463b5c std.HashMap: fix getPtrAdapted. AstGen: fix fn param iteration
There was a bug in stage2 regarding iteration of function parameter AST.
This resulted in a false negative "unused parameter" compile error,
which, when fixed, revealed a bug in the std lib HashMap implementation.
2021-08-05 23:17:29 -07:00
Evan Haas
9fd3aeb808 translate-c: handle macros that cast to cv void
Fixes #9507
2021-08-06 09:10:50 +03:00
Chris Gregory
fdd97244fd Make DynamicBitSet.iterator take self as const 2021-08-06 09:09:02 +03:00
Jakub Konka
ee6f7fee29 libstd: add ArrayHashMap.popOrNull function
which internally calls `ArrayHashMap.pop`, however, returns `?KV`
instead and performs the bounds checking automatically.

This function correponds to `ArrayList.popOrNull` and is meant
to fill the gap for situations where we want the quick lookup offered
by the hash map with elegant ability to iterate and pop of the
container with automatic bound checking that plugs in well with
a `while`-loop such as

```zig
var map = std.ArrayHashMap(K, V).init(allocator);
map.deinit();
while (map.popOrNull()) |entry| {
  // ... do something
}
assert(map.count() == 0);
```
2021-08-04 09:47:42 +02:00
Jakub Konka
68e26a2cee std: check for overflow in writeCurrentStackTrace
On arm64 macOS, the address of the last frame is 0x0 rather than
a positive value like 0x1 on x86_64 macOS, therefore, we overflow
an integer trying to subtract 1 when printing the stack trace. This
patch fixes it by first checking for this condition before trying
to subtract 1.

Note that we do not need to signal the `SignalIterator` about this
as it will correctly detect this condition on the subsequent iteration
and return `null`, thus terminating the loop.
2021-08-02 13:40:53 -04:00
N00byEdge
871f6343f4 Move iovec and log levels to bits/posix.zig
This lets only the OSes that uses them to import them, and removes
dependencies on bits.zig for the os/<os>/<arch>.zig files
2021-08-02 11:05:05 +00:00
N00byEdge
934df5bd44 Make linux syscalls accessible with non-Linux target OS 2021-08-02 11:05:05 +00:00
Luuk de Gram
5667ab7dcd
wasm: Implement wrapping operands, add opcodes to wasm.zig
- Some opcodes have the incorrect value set in std.
- Some opcodes were missing and have now been added to std.
- Adding wrapping operands for add,sub and mul.
- Implement intCast which either extends or shortens the type.
2021-08-01 11:07:23 +02:00
Koakuma
7aaea20e7e Add freeAndExit() implementation for Linux/SPARCv9 2021-07-30 13:23:41 -04:00
Vincent Rischmann
df4fe87163 thread: implement setName/getName 2021-07-29 12:02:12 +02:00
Vincent Rischmann
accde7fe2d windows: add wrappers for LocalFree, SetThreadDescription and GetThreadDescription 2021-07-29 10:57:08 +02:00
Vincent Rischmann
0be1e74902 windows/kernel32: add LocalFree, SetThreadDescription and GetThreadDescription 2021-07-29 10:57:08 +02:00
Vincent Rischmann
c0f40a5fe6 std/c: add pthread_setname_np and pthread_getname_np 2021-07-29 10:57:08 +02:00
Mahdi Khanalizadeh
15bec20b00 linux: add mknod and mknodat syscalls 2021-07-28 18:15:41 -04:00
Matt Knight
2f9e498c6f add build dependency when linkerscript is a generated file 2021-07-28 18:10:53 -04:00
Zach Banks
9c028b2078 std/ArrayList: Allow ArrayList(u0) to be created
Enable creating ArrayList with zero-sized types.
This type still tracks length, but does not allocate
additional memory.
2021-07-28 18:05:40 -04:00
Ominitay
c1285a1bbe Move fs.Walker to fs.Dir.Walker
fs.Walker has been replaced with fs.Dir.Walker. Paths of entries
returned are relative to the Dir.
2021-07-28 21:39:36 +03:00
Evan Haas
d4d3a9dcc9
translate-c: handle floating point NAN and INFINITY macros 2021-07-28 08:06:22 -07:00
Austin Clements
eb010ce65d Skip empty strings in std.fs.path.join function 2021-07-28 09:51:48 +03:00
Andrew Kelley
a8e8927c49 fix old references to verbose-ir to be verbose-air 2021-07-27 18:33:49 -07:00
Lee Cannon
c234d4790e
Add option to hide build command on compilation error to build_runner (#8513)
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-07-27 21:30:53 -04:00
Jarred Sumner
ba71b96fe6 Add zld.id to list of files to skip 2021-07-27 07:54:25 +02:00
Andrew Kelley
7b8cb881df stage2: improvements towards zig test
* There is now a main_pkg in addition to root_pkg. They are usually the
   same. When using `zig test`, main_pkg is the user's source file and
   root_pkg has the test runner.
 * scanDecl no longer looks for test decls outside the package being
   tested. honoring `--test-filter` is still TODO.
 * test runner main function has a void return value rather than
   `anyerror!void`
 * Sema is improved to generate better AIR for for loops on slices.
 * Sema: fix incorrect capacity calculation in zirBoolBr
 * Sema: add compile errors for trying to use slice fields as an lvalue.
 * Sema: fix type coercion for error unions
 * Sema: fix analyzeVarRef generating garbage AIR
 * C codegen: fix renderValue for error unions with 0 bit payload
 * C codegen: implement function pointer calls
 * CLI: fix usage text

 Adds 4 new AIR instructions:

  * slice_len, slice_ptr: to get the ptr and len fields of a slice.
  * slice_elem_val, ptr_slice_elem_val: to get the element value of
    a slice, and a pointer to a slice.

AstGen gains a new functionality:

 * One of the unused flags of struct decls is now used to indicate
   structs that are known to have non-zero size based on the AST alone.
2021-07-23 22:42:31 -07:00
Veikka Tuominen
8ad23d7beb
Merge pull request #9265 from ehaas/translate-c-macro-matching
translate-c: add framework for special-casing macros
2021-07-23 09:29:25 +03:00
Andrew Kelley
e3fe3acce0
Merge pull request #9440 from ziglang/emit-bc
add -femit-llvm-bc CLI option and implement it, and improve -fcompiler-rt support
2021-07-23 02:22:23 -04:00
Andrew Kelley
a5fb28070f add -femit-llvm-bc CLI option and implement it
* Added doc comments for `std.Target.ObjectFormat` enum
 * `std.Target.oFileExt` is removed because it is incorrect for Plan-9
   targets. Instead, use `std.Target.ObjectFormat.fileExt` and pass a
   CPU architecture.
 * Added `Compilation.Directory.joinZ` for when a null byte is desired.
 * Improvements to `Compilation.create` logic for computing `use_llvm`
   and reporting errors in contradictory flags. `-femit-llvm-ir` and
   `-femit-llvm-bc` will now imply `-fLLVM`.
 * Fix compilation when passing `.bc` files on the command line.
 * Improvements to the stage2 LLVM backend:
   - cleaned up error messages and error reporting. Properly bubble up
     some errors rather than dumping to stderr; others turn into panics.
   - properly call ZigLLVMCreateTargetMachine and
     ZigLLVMTargetMachineEmitToFile and implement calculation of the
     respective parameters (cpu features, code model, abi name, lto,
     tsan, etc).
   - LLVM module verification only runs in debug builds of the compiler
   - use LLVMDumpModule rather than printToString because in the case
     that we incorrectly pass a null pointer to LLVM it may crash during
     dumping the module and having it partially printed is helpful in
     this case.
   - support -femit-asm, -fno-emit-bin, -femit-llvm-ir, -femit-llvm-bc
   - Support LLVM backend when used with Mach-O and WASM linkers.
2021-07-22 19:51:32 -07:00
Evan Haas
b33efa3739
translate-c: Handle ambiguous cast or call macro
Fixes #9425
2021-07-22 11:50:12 -07:00
Evan Haas
dc4fa83dd7
translate-c: add framework for special-casing macros
Some macros (for example any macro that uses token pasting) cannot be
directly translated to Zig, but may nevertheless still admit a Zig
implementation. This provides a mechanism for matching macros against
templates and mapping them to functions implemented in c_translation.zig.

A macro matches a template if it contains the same sequence of tokens, except
that the name and parameters may be renamed. No attempt is made to
semantically analyze the macro. For example the following two macros are
considered equivalent:

```C
```

But the following two are not:

```C
```
2021-07-22 08:09:46 -07:00
Michal Ziulek
18b8738069
Fixed compile error: 'bMenu' needs to casted. (#9426) 2021-07-22 01:28:21 +02:00
Biolunar
093e10b66e
linux stdlib: fix definition of RW flags (#9428) 2021-07-22 01:27:59 +02:00
Frank Denis
680fa880d6
std.crypto: handle the top bit in 25519.field.fromBytes64() (#9435)
The only known use case for this is the hash-to-curve operation where the top bit is always cleared.

But the function is public, so let's make it work as one would expect in the general case.

Also fix the comment by the way.
2021-07-22 01:27:42 +02:00
Andrew Kelley
36295d712f remove 'pe' object format
Portable Executable is an executable format, not an object format.
Everywhere in the entire zig codebase, we treated coff and pe as if they
were the same. Remove confusion by not including pe in the
std.Target.ObjectFormat enum.
2021-07-21 12:45:32 -07:00
Tau
8d0671157c Correct hasUniqueRepresentation for vectors
Closes #9333.
2021-07-21 15:19:57 -04:00
Andrew Kelley
f7ee3b4ca5 std.Progress: revert to the older strategy
This reverts the most recent big changes to `std.Progress` changing the
strategy for printing. Before the changes, it would leave the cursor after
the progress line, having better behavior when a stray print happened,
and supporting sub-process progress without any coordination.

After the changes, the cursor was left at the beginning of the line,
making any prints print garbage and often interfering with stack traces
or other debug information.

This commit reverts to before the changes.

Revert "std: Use more common escape sequences in Progress"
This reverts commit 8ebb18d9da0bfbe6a974636fd36e3391d1de253b.

Revert "Handle some weird edge cases of Win32 API"
This reverts commit b0724a350f07c5e2e8fab572951ffaaa92860b2c.

Revert "Fix many thinkos"
This reverts commit b5a50a26ebac6a08dacf79f5d1db9bdd94ba33a5.

Revert "Fix Progress printing on Windows systems"
This reverts commit 3010bfb08af0b47d801d492e4f2e21a988e8399a.

Revert "std: Better handling of line-wrapping in Progress"
This reverts commit 4fc2e92876d8aafd087a5f0bdb6ea7a54f195704.
2021-07-20 19:11:47 -07:00
Andrew Kelley
495e60d641 std.ArrayList: add missing assertion in appendSliceAssumeCapacity 2021-07-20 12:19:17 -07:00
Andrew Kelley
d17f492017 stage2: miscellaneous fixes for the branch
* Breaking language change: inline assembly must use string literal
   syntax. This is in preparation for inline assembly improvements that
   involve more integration with the Zig language. This means we cannot
   rely on text substitution.
 * Liveness: properly handle inline assembly and function calls with
   more than 3 operands.
   - More than 35 operands is not yet supported. This is a low priority
     to implement.
   - This required implementation in codegen.zig as well.
 * Liveness: fix bug causing incorrect tomb bits.
 * Sema: enable switch expressions that are evaluated at compile-time.
   - Runtime switch instructions still need to be reworked in this
     branch. There was a TODO left here (by me) with a suggestion to do
     some bigger changes as part of the AIR memory reworking. Now that
     time has come and I plan to honor the suggestion in a future commit
     before merging this branch.
 * AIR printing: fix missing ')' on alive instructions.

We're back to "hello world" working for the x86_64 backend.
2021-07-20 12:19:16 -07:00
charlieman
bfe2005167
std: remove dead code in std.os.read 2021-07-20 10:22:06 +02:00
Evan Haas
3e67ef5c9f translate-c: Handle underscore when used as an identifier
Use `@` syntax to escape `_` when used as an identifier.

Remove the stage1 astgen prohibition against assigning from `_`

Note: there a few stage1 bugs preventing `_` from being used as an identifier
for a local variable or function parameter; these will be fixed by stage2.
They are unlikely to arise in real C code since identifiers starting with
underscore are reserved for the implementation.
2021-07-19 12:56:23 +03:00
Tizoner
c905056562 fix style warning in json.zig 2021-07-19 12:55:05 +03:00
Adam C
95e5fac412
FIX typo in doc comment for std.math.hypot (#9413) 2021-07-18 23:53:06 +02:00
Jonathan Marler
08e5daa7d5 Add std.unicode.fmtUtf16le 2021-07-15 20:37:16 +03:00