Commit Graph

17514 Commits

Author SHA1 Message Date
William Sengir
6de8b4bc3d std.dwarf: implement basic DWARF 5 parsing
DWARF 5 moves around some fields and adds a few new ones that can't be
parsed or ignored by our current DWARF 4 parser. This isn't a complete
implementation of DWARF 5, but this is enough to make stack traces
mostly work. Line numbers from C++ don't show up, but I know the info
is there. I think the answer is to iterate through .debug_line_str in
getLineNumberInfo, but I didn't want to fall into an even deeper rabbit
hole tonight.
2022-03-15 16:53:45 -04:00
Ali Chraghi
47e004d975 remove TODO 2022-03-15 13:49:41 -04:00
Tom Maenan Read Cutting
9bb19a090e std: Add elf.EM, coff.MachineType to Target.CPU.Arch conversions
target.Arch already supports finding the correct encoding for either
target, so being able to do the inverse has use cases for when parsing
files of an unknown target (i.e. for zar).
2022-03-15 13:48:42 -04:00
Andrew Kelley
c64279b15b Sema: fix shl_sat with comptime rhs 2022-03-14 23:15:01 -07:00
Andrew Kelley
1adb15098c LLVM: clean up airUnaryOp to call callFloatUnary
and make callFloatUnary support vectors. I tried to make it use
getIntrinsic, but that resulted in tripping `assert(id != 0)`.
2022-03-14 21:43:57 -07:00
Andrew Kelley
9eceba2485
Merge pull request #11128 from topolarity/comptime-memory-reinterp
stage2: Track parent type for `.elem_ptr`, `.field_ptr`, and `.*_payload_ptr`
2022-03-15 00:43:26 -04:00
Andrew Kelley
2f92d1a026 stage2: fixups for topolarity-comptime-memory-reinterp branch
* don't store `has_well_defined_layout` in memory.
 * remove struct `hasWellDefinedLayout` logic. it's just
   `layout != .Auto`. This means we only need one implementation, in
   Type.
 * fix some of the cases being wrong in `hasWellDefinedLayout`, such as
   optional pointers.
 * move `tag_ty_inferred` field into a position that makes it more
   obvious how the struct layout will be done. Also we don't have a
   compiler that intelligently moves fields around so this layout is
   better.
 * Sema: don't `resolveTypeLayout` in `zirCoerceResultPtr` unless
   necessary.
 * Rename `ComptimePtrLoadKit` `target` field to `pointee` to avoid
   confusion with `target`.
2022-03-14 21:43:03 -07:00
Cody Tapscott
50a1ca24ca Add test for issue #11139 2022-03-14 21:43:02 -07:00
Cody Tapscott
1f76b4c6b8 stage2 llvm: Respect container type when lowering parent pointers
We need to make sure that we bitcast our pointers correctly before
we use get_element_ptr to compute the offset for the parent
pointer.

This also includes a small fix-up for a problem where ptrs to const
i64/u64 were not using the correct type in >1-level decl chains
(where we call lowerParentPtr recursively)
2022-03-14 21:42:43 -07:00
Cody Tapscott
5fa057053c stage2 sema: Respect container_ty of parent ptrs
The core change here is that we no longer blindly trust that parent
pointers (.elem_ptr, .field_ptr, .eu_payload_ptr, .union_payload_ptr)
were derived from the "true" type of the underlying decl. When types
diverge, direct dereference fails and we are forced to bitcast, as
usual.

In order to maximize our chances to have a successful bitcast, this
includes several changes to the dereference procedure:
   - `root` is now `parent` and is the largest Value containing the
     dereference target, with the condition that its layout and the
     byte offset of the target within are both well-defined.
   - If the target cannot be dereferenced directly, because the
     pointers were not derived from the true type of the underlying
     decl, then it is returned as null.
   - `beginComptimePtrDeref` now accepts an optional array_ty param,
     which is used to directly dereference an array from an elem_ptr,
     if necessary. This allows us to dereference array types without
     well-defined layouts (e.g. `[N]?u8`) at an offset

The load_ty also allows us to correctly "over-read" an .elem_ptr to an
array of [N]T, if necessary. This makes direct dereference work for
array types even in the presence of an offset, which is necessary if
the array has no well-defined layout (e.g. loading from `[6]?u8`)
2022-03-14 21:42:43 -07:00
Cody Tapscott
54426bdc82 stage2: Fix assertion in struct field offset when all fields are 0-size 2022-03-14 21:42:42 -07:00
Cody Tapscott
34a6fcd88e stage2: Add hasWellDefinedLayout() to type.zig and Sema.zig
This follows the same strategy as sema.typeRequiresComptime() and
type.comptimeOnly(): Two versions of the function, one which performs
resolution just-in-time and another which asserts that resolution is
complete.

Thankfully, this doesn't cause very viral type resolution, since
auto-layout structs and unions are very common and are known to not have
a well-defined layout without resolving their fields.
2022-03-14 21:42:42 -07:00
Cody Tapscott
bbd750ff05 stage2: Add container_ty/elem_ty to elem_ptr, field_ptr, *_payload_ptr Values 2022-03-14 21:42:42 -07:00
Andrew Kelley
a2a5d3c288
Merge pull request #11167 from mitchellh/codegen-arrays
stage2: codegen of arrays should use type length, not value length
2022-03-15 00:40:32 -04:00
William Sengir
c757f19790 stage2: add debug info for globals in the LLVM backend
LLVM backend: generate DIGlobalVariable's for non-function globals and
rename linkage names when exporting functions and globals.

zig_llvm.cpp: add some wrappers to convert a handful of DI classes
into DINode's since DIGlobalVariable is not a DIScope like the others.

zig_llvm.cpp: add some wrappers to allow replacing the LinkageName of
DISubprogram and DIGlobalVariable.

zig_llvm.cpp: fix DI class mixup causing nonsense reinterpret_cast.

The end result is that GDB is now usable since you now no longer need
to manually cast every global nor fully qualify every export.
2022-03-15 00:38:20 -04:00
Andrew Kelley
f36bf8506c
Merge pull request #11164 from mitchellh/reify-union
stage2: reify unions
2022-03-15 00:21:11 -04:00
Mitchell Hashimoto
67647154c1
stage2: apply fix for #11165 to codegen.zig for native backends
Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
2022-03-14 20:00:17 -07:00
Mitchell Hashimoto
a859f94644
stage2: LLVM codegen of arrays should use type length, not value length
It is possible for the value length to be longer than the type because
we allow in-memory coercing of types such as `[5:0]u8` to `[5]u8`. In
such a case, the value length is 6 but the type length if 5.

The `.repeated` value type already got this right, so this is extending
similar logic out to `.aggregate` and `.bytes`. Both scenarios are
tested in behavior tests.

Fixes #11165
2022-03-14 17:41:12 -07:00
Andrew Kelley
84f96779c3
Merge pull request #11143 from jmc-88/cbe
CBE: Implement popCount, byteSwap, bitReverse for ints <= 128 bits
2022-03-14 18:23:00 -04:00
Curtis Tate Wilkinson
3bb4c0c789
zig fmt: Resolve #11131 loss of comment on switch cases
Correct switch cases dropping comments in certain situations by
checking for the presence of the comment before collapsing to one line.
2022-03-14 23:10:59 +01:00
Mitchell Hashimoto
53de31d62c
stage2: enum reification should use sliceLen and elemValue 2022-03-14 14:38:05 -07:00
Mitchell Hashimoto
edd07aa808
stage2: reify unions 2022-03-14 14:34:28 -07:00
Daniele Cocca
8643591c9a CBE: split {clz,ctz,mod,popCount,byteSwap,bitReverse} by type
This also surfaces the fact that clz, ctz and popCount didn't actually
support 128 bit integers, despite what was claimed by
226fcd7c70. This was partially hidden by
the fact that the test code for popCount only exercised 128 bit integers
in a comptime context. This commit duplicates that test case for runtime
ints too.
2022-03-14 19:43:31 +00:00
Andrew Kelley
5ea94e7715 stage2: rework Value storage of structs and arrays
Now they both use `Value.Tag.aggregate`.

Additionally the LLVM backend now has implemented lowering of
tuple values.
2022-03-14 12:28:52 -07:00
Mitchell Hashimoto
1ebe3bd01d
stage2: reify structs and tuples (#11144)
Implements `@Type` for structs, anon structs, and tuples. This is another place that would probably benefit from a `.reified_struct` type tag but will defer for later in the interest of getting tests passing first.
2022-03-14 13:47:35 -04:00
Andrew Kelley
5919b10048
Merge pull request #11155 from ziglang/stage2-float-fixes
stage2 float fixes
2022-03-14 12:38:56 -04:00
Andrew Kelley
b2a1b4c085 Sema: improve lowering of stores to bitcasted vector pointers
Detect if we are storing an array operand to a bitcasted vector pointer.
If so, we instead reach through the bitcasted pointer to the vector pointer,
bitcast the array operand to a vector, and then lower this as a store of
a vector value to a vector pointer. This generally results in better code,
as well as working around an LLVM bug.

See #11154
2022-03-14 00:11:46 -07:00
Andrew Kelley
eee989d2a0 Sema: Type.abiSize asserts instead of using max with alignment
ABI size is guaranteed to always be >= alignment.
2022-03-14 00:11:46 -07:00
Andrew Kelley
2a50a4629b freestanding libc: include roundl 2022-03-14 00:11:46 -07:00
Andrew Kelley
547e6f6ee1 disable failing nvptx test cases
See #10968
2022-03-14 00:11:46 -07:00
Andrew Kelley
7a477a1110 LLVM: fix int_to_float signedness detection
It was checking if the result (float) type was a signed int rather than
checking the operand (integer) type.
2022-03-14 00:11:46 -07:00
Andrew Kelley
d42d31f72f basic language features do not belong in std.meta 2022-03-14 00:11:46 -07:00
Andrew Kelley
eeaaefb925 LLVM: fix debug info for local vars
Previously we incorrectly used the pointer type as the debug info type.
2022-03-14 00:11:46 -07:00
Daniele Cocca
d912699e08 Remove signed_type from zig_{clz,ctz,popcount}
This parameter is only currently needed by zig_byte_swap() and
zig_bit_reverse(). This commit adds an option to airBuiltinCall() to
allow emitting the signedness information only when needed, removing
this unused parameter from the other builtins.
2022-03-14 01:04:24 +00:00
Daniele Cocca
5a971bbeea Review suggestion: use hasRuntimeBitsIgnoreComptime()
This should cover not only integers, as done in
87744a7ea9, but also void, enums with a
single field, etc...

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2022-03-14 00:52:20 +00:00
Koakuma
cb3b1dd6dd c/linux: Fix stat struct definition for SPARCv9
The libc interface uses `stat` instead of `stat64` struct.
This fixes, among other things, `zig fmt` accidentally setting the
formatted file's permission to 000.
2022-03-13 16:48:02 -04:00
Joachim Schmidt
bb859a0be7
Merge pull request #11150 from joachimschmidt557/stage2-aarch64
stage2 AArch64: misc improvements
2022-03-13 18:43:18 +01:00
Jakub Konka
76bceb240d std+macho: revert and fix exposing Mach wrappers in std.os and std.c 2022-03-13 17:03:04 +01:00
Jakub Konka
4a2100e820 std: more c/darwin.zig fixes 2022-03-13 15:42:40 +01:00
Jakub Konka
1af0c75d71 std: fix imports for darwin specific flags and funcs 2022-03-13 14:59:15 +01:00
Jakub Konka
68c224d6ec macho: simplify writing atoms for stage2
Also, fix premature exit in `link.File.makeWritable` in case we
are running M1 but executing binaries using Rosetta2.
2022-03-13 14:15:26 +01:00
Jakub Konka
633c4a2a60 macos: add Mach task abstraction
`std.os.darwin.MachTask` wraps `mach_port_t` and can be used to issue
kernel calls tied to the wrapped Mach kernel port/task.
2022-03-13 13:35:39 +01:00
joachimschmidt557
b74cd902c6
stage2 AArch64: enable mul for ints with <= 64 bits 2022-03-13 11:32:08 +01:00
joachimschmidt557
1f28c72c39
stage2 AArch64: implement ptr_add for all element sizes 2022-03-13 11:32:08 +01:00
joachimschmidt557
384e4ddb06
stage2 AArch64: spill compare flags when necessary 2022-03-13 11:32:08 +01:00
joachimschmidt557
12207bbbd6
stage2 AArch64: Implement bit shifting with immediate operands 2022-03-13 11:32:07 +01:00
joachimschmidt557
03dddc8d9c
stage2 AArch64: implement bit shifts with register operands 2022-03-13 11:32:04 +01:00
Daniele Cocca
d0277a3d17 CBE: implement popCount, byteSwap, bitReverse for ints <= 128 bits
This folds the airCountZeroes() code from
226fcd7c70 back into airBuiltinCall(),
since most of these builtins happen to require the same arguments and
can be unified under a common function signature.
2022-03-13 09:59:15 +00:00
Daniele Cocca
87744a7ea9 CBE: skip 0 bit integers from function signatures
This was already done for void types, and needs to be done for 0 bit
integer types as well to align the rendered function signatures with the
effective size of extra.data.args_len as seen by airCall().
2022-03-13 09:59:15 +00:00
Jakub Konka
2036af94e9 macos: add kernel return values 2022-03-13 10:49:09 +01:00