17579 Commits

Author SHA1 Message Date
Luuk de Gram
79679be50d sema: Fix memory leak
When a generic call evaluates to a generic type, the call will be re-generated.
However, the old function was not freed before being re-generated, causing a memory leak.
So rather than only returning an error, we first free the old value.
2022-03-17 18:20:03 -07:00
Steven Fackler
9dc9219b2f Don't strip by default in cc or c++ 2022-03-17 18:16:24 -07:00
Andrew Kelley
ff21cb42a0
Merge pull request #11206 from schmee/vector-byteswap
Implement `@byteSwap` for vectors
2022-03-17 18:04:46 -07:00
Andrew Kelley
4fa5060633 Sema: take advantage of checkIntOrVectorAllowComptime 2022-03-17 18:04:06 -07:00
John Schmidt
d7d2ccb7af Avoid index out of bounds for one-valued types in zirValidateArrayInit
Previously, the code assumed that `ptr_elem_ptr` was always followed by
a `store`, but this is not true for types with one value (such as `u0`).
2022-03-17 18:00:48 -07:00
John Schmidt
adfcc8851b Implement @byteSwap for vectors
Make the behavior tests for this a little more primitive to exercise as
little extra functionality as possible.
2022-03-17 18:00:48 -07:00
Andrew Kelley
7233a3324a stage2: implement @reduce
Notably, Value.eql and Value.hash are improved to treat NaN as equal to
itself, so that Type/Value can be hash map keys. Likewise float hashing
normalizes the float value before computing the hash.
2022-03-17 17:24:35 -07:00
Andrew Kelley
76e103057e zig_llvm.h: fix some declarations not being C compatible 2022-03-17 17:24:11 -07:00
Andrew Kelley
9ed3eb9cde std.testing: fix incorrect docs that mentioned aborting
At some point we changed these functions to return errors instead of
aborting.
2022-03-17 17:23:22 -07:00
Andrew Kelley
73e51133c3 langref: small clarification of @reduce 2022-03-17 17:22:57 -07:00
Andrew Kelley
291f5055f4 disable x86_64 behavior test that does not run valgrind clean 2022-03-17 11:48:50 -07:00
Andrew Kelley
1ee7a81627 Revert "link.Elf: swap order of GOT and text program headers"
This reverts commit 8e7b1a74ac4568a2b806026f210ae59e52d2768d.

Sorry, I should have put up a PR and ran that one by Jakub and done some
more inspection.

This causes problems with gdb:

BFD: /home/andy/dev/zig/build-release/test: invalid string offset 3254779904 >= 153524 for section `.shstrtab'
2022-03-17 11:41:17 -07:00
Daniele Cocca
00ed8d9c50 CBE: enable more tests that are currently passing 2022-03-17 11:39:56 -07:00
Andrew Kelley
8e7b1a74ac link.Elf: swap order of GOT and text program headers
This makes Valgrind happier because it results in the program headers
being sorted by VirtAddr in the ELF file.
2022-03-17 11:36:17 -07:00
Jakub Konka
fdee7dd60d debug: msync only current page when validation frame pointer
This fixes lack of stack traces on arm64 macOS which were regressed
and not getting generated at all after this addition to write
current stack traces. Prior to this, function `isValidMemory` would
sync two subsequent pages if the aligned (base) address was different
than the frame pointer. I fail to see what the logic for such assumption
here is as the manual of `msync` clearly states it will fail with error
if the passed in memory region length contains unmapped regions.

This was the very reason why there were no stack traces print on
arm64 macOS as the second page was unmapped thus incorrectly flagging
the frame pointer as invalid.
2022-03-17 18:21:04 +01:00
Jakub Konka
4012fcb0a3 macho: do not allocate new GOT atom when target atom has grown
That's the entire point of our GOT so that we don't have to do that;
simply overwrite the address in the GOT.
2022-03-17 12:48:02 +01:00
Jakub Konka
d53e0234a3 macho: fix snapshot generation 2022-03-17 11:41:08 +01:00
Jakub Konka
648afbc839 macos: update Mach routines for accessing page info 2022-03-17 10:42:11 +01:00
Joachim Schmidt
3c3826bf93
Merge pull request #11192 from joachimschmidt557/stage2-arm
stage2 ARM: misc improvements
2022-03-17 09:40:41 +01:00
Andrew Kelley
87779cfd93 stage2: prevent UB in the LLVM backend
* Sema: fix `zirTypeInfo` allocating with the wrong arenas for some
   stuff.
 * LLVM: split `airDbgInline` into two functions, one for each AIR tag.
   - remove the redundant copy to type_map_arena. This is the first
     thing that lowerDebugType does so this hack was probably just
     accidentally avoiding UB (which is still present prior to this
     commit).
   - don't store an inline fn inst into the di_map for the generic
     decl.
   - use a dummy function type for the debug info to avoid whatever UB
     is happening.
   - we are now ignoring the function type passed in with the
     dbg_inline_begin and dbg_inline_end.
 * behavior tests: prepare the vector tests to be enabled one at a time.

Mitigates #11199.
2022-03-17 00:00:41 -07:00
Mitchell Hashimoto
79d3780fbd stage2: bit_not on u0 is always 0 2022-03-16 23:18:35 -07:00
Andrew Kelley
1af51a0833
Merge pull request #11196 from schmee/vector-muladd
Implement `@mulAdd` for vectors
2022-03-16 20:37:42 -07:00
Andrew Kelley
80642b5984 remove unnecessary TODO comment
`testing.expect` is better than `testing.expectEqual` for behavior
tests. Better for behavior tests to stick to only testing the limited
behavior they are meant to test and avoid functions such as
`expectEqual` that drag in too much of the standard library (in this
case to print helpful diffs about why a value is not equal to another).
2022-03-16 20:35:41 -07:00
John Schmidt
c8ed813097 Implement @mulAdd for vectors 2022-03-16 20:11:05 -07:00
Daniele Cocca
312536540b CBE: better handling of sentineled slices/arrays
Adds the sentinel element to the type name to avoid ambiguous
declarations, and outputs the sentinel element (if needed) even in what
would otherwise be empty arrays.
2022-03-16 19:58:45 -07:00
Andrew Kelley
d78b8c10b9 LLVM: fix slice debug info and functions
with return types that have no runtime bits
2022-03-16 17:22:16 -07:00
Andrew Kelley
942f8d07d1
Merge pull request #11193 from mitchellh/b-elem-ptr
stage2: elem_ptr needs to know if slice or direct access
2022-03-16 19:36:54 -04:00
Andrew Kelley
cdeb1fb881 Sema: different solution to elemVal
I think that reusing the ComptimePtrLoad infrastructure is ultimately
less logic and more robust than adding a `direct` flag to elem_ptr.

 * Some code in zirTypeInfo needed to be fixed to create proper
   Type/Value encodings.
 * comptime elemVal works by constructing an elem_ptr Value and then
   using the already existing pointerDeref function.

There are some remaining calls to Value.elemValue which should be
considered code smells at this point.
2022-03-16 16:29:08 -07:00
Mitchell Hashimoto
418197b6c5 stage2: elem_ptr needs to know if slice or direct access
This fixes one of the major issues plaguing the `std.sort` comptime tests.
The high level issue is that at comptime, we need to know whether `elem_ptr` is
being used to subslice an array-like pointer or access a child value. High-level
example:

    var x: [2][2]i32 = undefined;
    var a = &x[0]; // elem_ptr, type *[2]i32

    var y: [5]i32 = undefined;
    var b = y[1..3]; // elem_ptr, type *[2]i32

`a` is pointing directly to the 0th element of `x`. But `b` is
subslicing the 1st and 2nd element of `y`. At runtime with a well
defined memory layout, this is an inconsequential detail. At comptime,
the values aren't laid out exactly in-memory so we need to know the
difference.

This becomes an issue specifically in this case:

    var c: []i32 = a;
    var d: []i32 = b;

When converting the `*[N]T` to `[]T` we need to know what array to point
to. For runtime, its all the same. For comptime, we need to know if its
the parent array or the child value.

See the behavior tests for more details.

This commit fixes this by adding a boolean to track this on the
`elem_ptr`. We can't just immediately deref the child for `&x[0]`
because it is legal to ptrCast it to a many-pointer, do arithmetic, and
then cast it back (see behavior test) so we need to retain access to the
"parent" indexable.
2022-03-16 16:26:54 -07:00
Andrew Kelley
94672dfb19 stage2: fully resolve fn types after analyzing its body 2022-03-16 13:31:53 -07:00
Andrew Kelley
92a09eb1e4 std.heap.GeneralPurposeAllocator: use var for mutable locals
Required to be compatible with new language semantics.
2022-03-16 13:31:16 -07:00
joachimschmidt557
dcc1de12b0
stage2 ARM: implement addwrap, subwrap, mulwrap 2022-03-16 20:20:07 +01:00
joachimschmidt557
2412ac2c5f
stage2 ARM: fix shl for ints with bits < 32 2022-03-16 20:20:07 +01:00
joachimschmidt557
0eebdfcad3
stage2 ARM: fix bitwise negation of ints with bits < 32 2022-03-16 20:20:07 +01:00
joachimschmidt557
ca1ffb0951
stage2 ARM: genSetStack for stack_argument_offset 2022-03-16 20:19:58 +01:00
Andrew Kelley
1f313b3d7c LLVM: make the load function copy isByRef=true types 2022-03-16 11:52:22 -07:00
Jakub Konka
dd55b72949 std: introduce posix_spawn as an alt to fork-exec
Currently, the new API will only be available on macOS with
the intention of adding more POSIX systems to it incrementally
(such as Linux, etc.).

Changes:
* add `posix_spawn` wrappers in a separate container in
  `os/posix_spawn.zig`
* rewrite `ChildProcess.spawnPosix` using `posix_spawn` targeting macOS
  as `ChildProcess.spawnMacos`
* introduce a `posix_spawn` specific `std.c.waitpid` wrapper which
  does return an error in case the child process failed to exec - this
  is required for any process that was spawned using `posix_spawn`
  mechanism as, by definition, the errors returned by `posix_spawn`
  routine cover only the `fork`-equivalent; `pre-exec()` and `exec()`
  steps are covered by a catch-all error `ECHILD` returned by `waitpid`
  on unsuccessful execution, e.g., no such file error, etc.
2022-03-16 19:40:44 +01:00
Veikka Tuominen
49c0bb1f33
Merge pull request #11177 from Vexu/dbg_func
Add debug info for inlined calls
2022-03-16 20:40:16 +02:00
Andrew Kelley
d4a7a9ac4c
Merge pull request #11191 from Snektron/zig-gdb-improvements
Zig gdb improvements
2022-03-16 14:08:06 -04:00
Robin Voetter
4ff7553d6b gdb: restructure pretty printers into different files 2022-03-16 18:13:10 +01:00
Robin Voetter
0bd84e03b9 gdb: add printer for selfhosted Value 2022-03-16 17:57:31 +01:00
Robin Voetter
6830bcbb0a gdb: add printer for selfhosted Type 2022-03-16 17:40:21 +01:00
Robin Voetter
feb8981a95 gdb: add slice, multi array list, and array hash map printers 2022-03-16 15:50:03 +01:00
Robin Voetter
e18c29af5b gdb: add arraylist and hashmap printer 2022-03-16 12:40:08 +01:00
Veikka Tuominen
d83a26f068 stage2 llvm: keep track of inlined functions 2022-03-16 10:53:41 +02:00
Veikka Tuominen
0343811836 Sema: emit dbg_func around inline calls 2022-03-16 09:34:26 +02:00
Veikka Tuominen
0f112b9f6d AstGen: emit dbg_stmt before function calls and branch conditions 2022-03-16 09:27:31 +02:00
Veikka Tuominen
af2b03de83 Type: implement ptrInfo for optional pointers 2022-03-16 09:26:10 +02:00
Andrew Kelley
8a43d67c3b LLVM: fix LLVM assertion when slicing 2022-03-16 00:09:00 -07:00
Andrew Kelley
c3663f2617 LLVM: implement debug info for structs
This involved some significant reworking in order to introduce the
concept of "forward declarations" to the system to break dependency
loops.

The `lowerDebugType` function now takes an `enum { full, fwd }` and is moved
from `DeclGen` to `Object` so that it can be called from `flushModule`.

`DITypeMap` is now an `ArrayHashMap` instead of a `HashMap` so that we can
iterate over the entries in `flushModule` and finalize the forward decl
DITypes into full DITypes.

`DITypeMap` now stores `AnnotatedDITypePtr` values instead of
`*DIType` values. This is an abstraction around a `usize` which assumes
the pointers will be at least 2 bytes aligned and uses the least
significant bit to store whether it is forward decl or a fully resolved
debug info type.

`lowerDebugTypeImpl` is extracted out from `lowerDebugType` and it has a
mechanism for completing a forward decl DIType to a fully resolved one.
The function now contains lowering for struct types. Closes #11095.

There is a workaround for struct types which have not had
`resolveFieldTypes` called in Sema, even by the time `flushModule` is
called. This is a deficiency of Sema that should be addressed, and the
workaround removed. I think Sema needs a new mechanism to queue up type
resolution work instead of doing it in-line, so that it does not cause
false dependency loops. We already have one failing behavior test
because of a false dependency loop.
2022-03-16 00:09:00 -07:00