Commit Graph

15293 Commits

Author SHA1 Message Date
Andrew Kelley
be71195bba stage2: enable f16 math
There was panic that said TODO add __trunctfhf2 to compiler-rt, but I
checked and that function has been in compiler-rt since April.
2021-09-21 23:21:07 -07:00
Vincent Rischmann
01f20c7f48 io_uring: implement read_fixed/write_fixed 2021-09-22 00:47:45 -04:00
Isaac Freund
8c86043178 std.build: fix handling of -Dcpu
Currently -Dcpu is completely ignored if -Dtarget isn't passed as well.
Further, -Dcpu=baseline is ignored even if -Dtarget=native is passed.

This patch fixes these 2 issues, always respecting the -Dcpu option if
present.
2021-09-22 00:46:37 -04:00
Andrew Kelley
5913140b6b stage2: free Sema's arena after generating machine code
Previously, linker backends or machine code backends were able to hold
on to references to inside Sema's temporary arena. However there can
be large objects stored there that we want to free after machine code is
generated.

The primary change in this commit is to use a temporary arena for Sema
of function bodies that gets freed after machine code backend finishes
handling `updateFunc` (at the same time that Air and Liveness get freed).

The other changes in this commit are fixing issues that fell out from
the primary change.

 * The C linker backend is rewritten to handle updateDecl and updateFunc
   separately. Also, all Decl updates get access to typedefs and
   fwd_decls, not only functions.
 * The C linker backend is updated to the new API that does not depend
   on allocateDeclIndexes and does not have to handle garbage collected
   decls.
 * The C linker backend uses an arena for Type/Value objects that
   `typedefs` references. These can be garbage collected every so often
   after flush(), however that garbage collection code is not
   implemented at this time. It will be pretty simple, just allocate a
   new arena, copy all the Type objects to it, update the keys of the
   hash map, free the old arena.
 * Sema: fix a handful of instances of not copying Type/Value objects
   from the temporary arena into the appropriate Decl arena.
 * Type: fix some function types not reporting hasCodeGenBits()
   correctly.
2021-09-21 15:23:29 -07:00
Jakub Konka
affd8f8b59 macho: fix incorrect segment/section growth calculation
Otherwise, for last sections in segments it could happen we would
not expand the segment when actually required thus exceeding the
segment's size and causing data clobbering and dyld runtime errors.
2021-09-21 20:22:52 +02:00
Veikka Tuominen
a2dd0c387d
Merge pull request #9652 from g-w1/p9d
plan9: emit debug info
2021-09-21 19:38:12 +03:00
Jakub Konka
d722f0cc62 macho: do not write temp and noname symbols to symtab
Remove currently obsolete AtomParser from Object.
2021-09-21 11:05:22 +02:00
Andrew Kelley
5269cbea20
Merge pull request #9797 from Vexu/stage2
stage2: implement cImport
2021-09-21 00:01:30 -04:00
Andrew Kelley
0c74ce1156 Sema: fix double-free of @cImport error message 2021-09-20 20:56:30 -07:00
Veikka Tuominen
55e7c099ca stage2: various fixes to cImport, sizeOf and types to get tests passing 2021-09-20 20:51:31 -07:00
Veikka Tuominen
d64d5cfc0a stage2: implement typeInfo for more types 2021-09-20 20:50:55 -07:00
Veikka Tuominen
9a54ff72df stage2: implement cImport 2021-09-20 20:50:55 -07:00
Andrew Kelley
1ad905c71e
Merge pull request #9649 from Snektron/address-space
Address Spaces
2021-09-20 20:37:04 -04:00
Andrew Kelley
f8b914fcf3 Merge branch 'address-space' of Snektron/zig into Snektron-address-space
There were two things to resolve here:
 * Snektron's branch edited Zir printing, but in master branch
   I moved the printing code from Zir.zig to print_zir.zig. So that
   just had to be moved over.
 * In master branch I fleshed out coerceInMemory a bit more, which
   caused one of Snektron's test cases to fail, so I had to add
   addrspace awareness to that. Once I did that the tests passed again.
2021-09-20 17:32:52 -07:00
Ryan Liptak
2a728f6e5f tokenizer: Fix index-out-of-bounds on string_literal_backslash right before EOF 2021-09-20 20:16:14 -04:00
Mr. Paul
380ca26855 docgen: re-enable syntax checking for code blocks
In a previous commit (f4d3d29), syntax checking for code blocks with the
`syntax` type was disabled due to a change in astgen now checking the existence of
identifiers. The change in astgen caused some code samples in the language
reference to cause compilation errors.

This commit updates the code samples in the language reference and
re-enables syntax checking. Some code samples have been changed to unchecked
syntax blocks using `{#syntax_block#}` when suitable.
2021-09-20 19:54:57 -04:00
Andrew Kelley
abc30f7948 stage2: improve handling of 0 bit types
* Sema: zirAtomicLoad handles 0-bit types correctly
 * LLVM backend: when lowering function types, elide parameters
   with 0-bit types.
 * Type: abiSize handles u0/i0 correctly
2021-09-20 16:48:42 -07:00
Andrew Kelley
4b2d7a9c67 stage2: implement comptime bitwise nand 2021-09-20 15:44:09 -07:00
Andrew Kelley
f3147de7a2 stage2: extract ZIR printing code into print_zir.zig
also implement textual printing of the ZIR instruction `atomic_rmw`.
2021-09-20 14:45:40 -07:00
Andrew Kelley
b9d3527e0e stage2: implement comptime @atomicRmw
* introduce float_to_int and int_to_float AIR instructionts and
   implement for the LLVM backend and C backend.
 * Sema: implement `zirIntToFloat`.
 * Sema: implement `@atomicRmw` comptime evaluation
   - introduce `storePtrVal` for when one needs to store a Value to a
     pointer which is a Value, and assert it happens at comptime.
 * Value: introduce new functionality:
   - intToFloat
   - numberAddWrap
   - numberSubWrap
   - numberMax
   - numberMin
   - bitwiseAnd
   - bitwiseNand (not implemented yet)
   - bitwiseOr
   - bitwiseXor
 * Sema: hook up `zirBitwise` to the new Value bitwise implementations
 * Type: rename `isFloat` to `isRuntimeFloat` because it returns `false`
   for `comptime_float`.
2021-09-20 14:24:43 -07:00
Jacob G-W
f697e0a326 plan9 linker: link lineinfo and filenames 2021-09-20 16:37:56 -04:00
Travis Martin
5dc251747b Fix compile error in WindowsCondition.wait() 2021-09-20 02:06:10 -04:00
HugoFlorentino
806aeab2a7 adding support for UTF-8 output 2021-09-20 02:05:52 -04:00
Rory O’Kane
b3ae69d80b langref: define the inferred error set syntax more explicitly
This edit allows the reader to understand the syntax this section is talking about more quickly – they don’t have to read the whole code block and understand which part of it demonstrates the feature being described.

Affects https://ziglang.org/documentation/master/#Inferred-Error-Sets
2021-09-20 02:04:31 -04:00
Ali Chraghi
db181b173f
Update hash & crypto benchmarks run comment (#9790)
* sync function arguments name with other same functions
2021-09-19 23:03:18 -07:00
Martin Wickham
cfd5b81850 Fix compiler builds with tracy on the mingw target 2021-09-20 01:59:25 -04:00
Malcolm Still
1f61076ffb I'm working on a WebAssembly interpreter in zig. WebAssembly uses LEB128 encoding throughout its specification.
The WebAssembly spec requires signed LEB128 to be encoded up to a maximum number of bytes (max 5 bytes for i32, max 10 bytes for i64) and that "unused" bits are all 0 if the number is positive and all 1 if the number is negative. The Zig LEB128 implementation already enforces the max number of bytes and does check the unused bytes https://github.com/ziglang/zig/blob/master/lib/std/leb128.zig#L70-L79.

However, the WebAssembly test suite has a number of tests that were failing validation (expecting the wasm module to fail validation, but when running the tests, those examples were actually passing validation):

    https://github.com/malcolmstill/foxwren/blob/master/test/testsuite/binary-leb128.wast#L893-L902
    https://github.com/malcolmstill/foxwren/blob/master/test/testsuite/binary-leb128.wast#L934-L943

Notably the failures are both cases of negative numbers and the top 4 bits of the last byte are zero. And I believe this is the issue: we're only currently checking the "unused" / remaining_bits if we overflow, but in the case of 0x0_ no overflow happens and so the bits go unchecked.

In other words:

    \xff\xff\xff\xff\7f rightly successfully decodes (because it overflows and the remaining bits are 0b1111)
    \xff\xff\xff\xff\6f rightly errors with overflow (because it overflows and the remaining bits are 0b1110)
    \xff\xff\xff\xff\0f incorrectly decodes when it should error (because the top 4 bits are all 0, and so no overflow occurs and no check that the unused bits are 1 happens)

This PR adds a the remaining_bits check in an else branch of the @shlWithOverflow when we're looking at the last byte and the number being decoded is negative.

Note: this means a couple of the test cases in leb128.zig that are down as decoding shouldn't actually decode so I added the appropriate 1 bits.
2021-09-20 01:58:18 -04:00
Robin Voetter
619260d94d Address Spaces: Fix comments in Ast.zig 2021-09-20 02:34:53 +02:00
Robin Voetter
95e83afa98 Address Spaces: Yeet address space on function prototypes
This is a property which solely belongs to pointers to functions,
not to the functions themselves. This cannot be properly represented by
stage 2 at the moment, as type with zigTypeTag() == .Fn is overloaded for
for function pointers and function prototypes.
2021-09-20 02:29:04 +02:00
Robin Voetter
5a142dfa56 Address Spaces: LLVM F segment address space test 2021-09-20 02:29:04 +02:00
Robin Voetter
e4ac063297 Address Spaces: Restructure llvmAddressSpace a bit 2021-09-20 02:29:04 +02:00
Robin Voetter
13b917148e Address Spaces: basic system to check for validity.
Validity checks are also based on context; whether the entity being validated
is a mutable/constant value, a pointer (that is ascripted with an addrspace
attribute) or a function with an addrspace attribute. Error messages are
relatively simple for now.
2021-09-20 02:29:04 +02:00
Robin Voetter
90a945b38c Address Spaces: Split out stage2 address llvm tests to individual cases
This previously caused a test case to crash due to lingering llvm state.
2021-09-20 02:29:04 +02:00
Robin Voetter
7956eee1ab Address Spaces: Adapt compile error test cases to @Type with address spaces 2021-09-20 02:29:04 +02:00
Robin Voetter
c5945467ac Address Spaces: Pointer and function info in @Type 2021-09-20 02:29:04 +02:00
Robin Voetter
7a5d0cdf45 Address Spaces: Render addrspace token in docgen 2021-09-20 02:29:04 +02:00
Robin Voetter
0492b71319 Address Spaces: Smol fixup 2021-09-20 02:29:04 +02:00
Robin Voetter
68fcbb5c0d Address Spaces: fmt a bunch of stuff 2021-09-20 02:29:04 +02:00
Robin Voetter
ea393b2bca Address Spaces: Implement in LLVM codegen 2021-09-20 02:29:04 +02:00
Robin Voetter
e09465fc49 Address Spaces: Chaining tests 2021-09-20 02:29:04 +02:00
Robin Voetter
2f43749c2b Address Spaces: Move stage 2 tests to stage2/llvm.zig 2021-09-20 02:29:04 +02:00
Robin Voetter
8f28c58759 Address Spaces: compiles() test cases 2021-09-20 02:29:04 +02:00
Robin Voetter
7686165c82 Address Spaces: Pointer coercion errors tests 2021-09-20 02:29:04 +02:00
Robin Voetter
6336f08c21 Address Spaces: Address space on local variable test 2021-09-20 02:29:04 +02:00
Robin Voetter
e77fcf1730 Address Spaces: Implement right address space for slicing 2021-09-20 02:29:04 +02:00
Robin Voetter
8672f2696f Address Spaces: zig fmt + tests 2021-09-20 02:29:04 +02:00
Robin Voetter
538f1bbcb3 Address Spaces: Return proper address space for &x.y 2021-09-20 02:29:03 +02:00
Robin Voetter
497c0d3783 Allow x.y when x is a pointer 2021-09-20 02:29:03 +02:00
Robin Voetter
64c328a717 Address Spaces: Default align, linksection & addrspace for anon decls 2021-09-20 02:29:03 +02:00
Robin Voetter
e182c17187 Address Spaces: Disallow coercing pointers to different address spaces 2021-09-20 02:29:03 +02:00