17384 Commits

Author SHA1 Message Date
Andrew Kelley
a91753219d
Merge pull request #11085 from ziglang/llvm-debug-info
stage2 LLVM debug info
2022-03-08 21:09:20 -05:00
Andrew Kelley
935d208ffb
Merge pull request #11090 from mitchellh/inferred-ty
stage2: correct comptime-known inferred alloc type, plus comptime array init sentinels
2022-03-08 20:56:00 -05:00
Andrew Kelley
fb4ad37e0b LLVM: fix memory leak of debug type names
This required adjusting `Type.nameAlloc` to be used with a
general-purpose allocator and added `Type.nameAllocArena` for the arena
use case (avoids allocation sometimes).
2022-03-08 15:03:03 -07:00
Andrew Kelley
874b51d8d4 LLVM: add debug info for opaque, vector, and tuples
Also fix UAF of Type memory in the di_type_map.
2022-03-08 14:58:54 -07:00
Andrew Kelley
fa57335ec6 stage2: implement Type.getOwnerDecl for opaque types 2022-03-08 14:58:54 -07:00
Andrew Kelley
1046ead0cc LLVM: no longer store args into alloca instructions
Previously, we did this so that we could insert a debug variable
declaration intrinsic on the alloca. But there is a dbg.value intrinsic
for declaring variables that are values.
2022-03-08 14:58:53 -07:00
Andrew Kelley
7cea8f063f LLVM: add debug info for parameters 2022-03-08 14:58:53 -07:00
Andrew Kelley
ba566eed76 LLVM: fix not handling dbg_stmt relative line
Also make `namespaceToDebugScope` behave correctly for file-level
structs. Instead of being inside their own scope, they use the file
scope.
2022-03-08 14:58:53 -07:00
Andrew Kelley
3654ec8770 LLVM: add debug type lowering for ptr, slice, opaque, optional
also fix issue with memoization and recursiveness.
2022-03-08 14:58:53 -07:00
Andrew Kelley
40c0bdd385 LLVM: memoize debug types and add enum debug types 2022-03-08 14:58:53 -07:00
Andrew Kelley
0d24bc7da0 LLVM: add DISubprogram and DIType lowering; handle dbg_stmt 2022-03-08 14:58:53 -07:00
Andrew Kelley
627209253c langref: fix a stray anyopaque that should be a void 2022-03-08 14:58:53 -07:00
Andrew Kelley
c6160fa3a5 LLVM: add compile unit to debug info
This commit also adds a bunch of bindings for debug info.
2022-03-08 14:58:53 -07:00
joachimschmidt557
95fc41b2b4 stage2 ARM: implement ret_load 2022-03-08 21:10:04 +01:00
Mitchell Hashimoto
ba62853d26
stage2: sentinel array init must add sentinel to array value
I didn't realize that the `array` value type has the sentinel on it.
2022-03-08 12:05:12 -08:00
Mitchell Hashimoto
cd32b11eb8
stage2: inferred alloc can use bitcast ty
The comment notes that we can't because of constness, but the recent
work by @Vexu lets us use the bitcast ty cause constness comes later.

The following tests pass from this:

```
test "A" {
    const ary = [_:0]u8{42};
    const ptr: [*:0]const u8 = &ary;
    try expect(ptr[1] == 0);
}

test "B" {
    comptime {
        const ary = [_:0]u8{42};
        const ptr: [*:0]const u8 = &ary;
        try expect(ptr[1] == 0);
    }
}
```
2022-03-08 12:04:51 -08:00
Mitchell Hashimoto
55ccf4c7a8 stage2: elem vals of many pointers need not deref pointers
By the time zirElemVal is reached for a many pointer, a load has already
happened, making sure the operand is already dereferenced.

This makes `mem.sliceTo` now work.
2022-03-08 14:10:43 -05:00
Andrew Kelley
6ffa44554e
Merge pull request #11079 from Vexu/stage2
stage2: make references to const allocs const
2022-03-08 13:49:29 -05:00
Benjamin San Souci
e3c2cc1443
std.json: correctly handle sentinel terminated slices 2022-03-08 20:43:13 +02:00
Evan Haas
4b9fd57aa8
translate-c: use nested scope for comma operator in macros
Fixes #11040
2022-03-08 20:38:51 +02:00
Jonathan Marler
d805adddd6 deprecated TypeInfo in favor of Type
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-03-08 20:38:12 +02:00
Jakub Konka
404f5d6179 x64: pass more behavior/cast.zig tests 2022-03-08 10:56:54 +01:00
joachimschmidt557
3ea603c82a stage2 ARM: implement ptr_add, ptr_sub for all element sizes
Also reduces slice_elem_val to ptr_add, simplifying the implementation
2022-03-08 10:54:08 +01:00
Veikka Tuominen
8f037db885 stage2: correct constness of allocs 2022-03-08 11:23:39 +02:00
Veikka Tuominen
1f4a097117 stage2: fix mem{set,cpy} for non comptime mutable pointers 2022-03-08 11:23:38 +02:00
Jakub Konka
ba17552b4e dwarf: move all dwarf into standalone module
Hook up Elf and MachO linkers to the new solution.
2022-03-08 09:46:27 +01:00
Andrew Kelley
38c161afab Sema: fix @hasDecl for simple enums 2022-03-07 13:54:25 -07:00
Andrew Kelley
c467f6693e stage2: fix union layout returning non-zero for zero-sized tag 2022-03-07 13:36:58 -07:00
Andrew Kelley
f59cbd89e3
Merge pull request #11077 from mitchellh/array-init-ty
stage2: sentinel-terminated array initialization
2022-03-07 13:54:09 -05:00
Mitchell Hashimoto
85b0a4a8fd
stage2: new zir array_init_sent for sentinel-terminated array inits
This uses a new ZIR inst `array_init_sent` (and a ref equivalent) to
represent array init expressions that terminate in a a sentinel value.

The sentienl value is the last value in the `MultiOp` payload. This
makes it a bit more awkward to deal with (lots of "len - 1") but makes
it so that the payload matches the fact that sentinels appear at the end
of arrays. However, this is not a hill I want to die on so if we want to
change it to index 0, I'm happy to do so.

This makes the following work properly:

    try expect(@TypeOf([_:0]u8{}) == [0:0]u8);
2022-03-07 08:26:00 -08:00
Mitchell Hashimoto
c9fac41368
stage2: resolve array type for typed array init expressions
Array types with sentinels were not being typed correctly in the
translation from ZIR to Sema (comptime). This modifies the `array_init`
ZIR to also retain the type of the init expression (note: untyped array
initialization is done via the `array_init_anon` ZIR and so is unchanged
in this commit).
2022-03-07 07:30:30 -08:00
Andrew Kelley
8c32d989c9
Merge pull request #11054 from schmee/mul-add
Implement `@mulAdd` for scalar floats
2022-03-07 04:00:45 -05:00
Andrew Kelley
6547da8f97 Sema: handle peer type resolution of optional slices 2022-03-06 21:29:07 -07:00
Andrew Kelley
76d810c568 std: disable flaky os.fcntl test
See tracking issue #11074
2022-03-06 20:49:49 -07:00
Andrew Kelley
e74382b602 ci: azure: update to newest LTS ubuntu 2022-03-06 20:03:57 -07:00
Andrew Kelley
3c1ebf9556 compiler_rt: avoid redundant exports when testing 2022-03-06 19:58:01 -07:00
Andrew Kelley
4c17b93f0a compiler_rt: additional powerpc-specific alias
Apparently LLVM lowers f128 fma to `fmaf128` instead of `fmal`.
2022-03-06 16:34:44 -07:00
Andrew Kelley
488eb8ac29 disable failing @mulAdd test 2022-03-06 16:18:51 -07:00
Andrew Kelley
c52d437224 stage1: improved implementation of target_long_double_is_f128 2022-03-06 16:11:39 -07:00
Andrew Kelley
c68d9773df compiler-rt: make __fmax and fmaq aliases of fmal
on targets where that is the case.
2022-03-06 16:11:39 -07:00
Andrew Kelley
71b8760d3b stage2: rework @mulAdd
* mul_add AIR instruction: use `pl_op` instead of `ty_pl`. The type is
   always the same as the operand; no need to waste bytes redundantly
   storing the type.
 * AstGen: use coerced_ty for all the operands except for one which we
   use to communicate the type.
 * Sema: use the correct source location for requireRuntimeBlock in
   handling of `@mulAdd`.
 * native backends: handle liveness even for the functions that are
   TODO.
 * C backend: implement `@mulAdd`. It lowers to libc calls.
 * LLVM backend: make `@mulAdd` handle all float types.
   - improved fptrunc and fpext to handle f80 with compiler-rt calls.
 * Value.mulAdd: handle all float types and use the `@mulAdd` builtin.
 * behavior tests: revert the changes to testing `@mulAdd`. These
   changes broke the test coverage, making it only tested at
   compile-time.

Improved f80 support:
 * std.math.fma handles f80
 * move fma functions from freestanding libc to compiler-rt
   - add __fmax and fmal
   - make __fmax and fmaq only exported when they don't alias fmal.
   - make their linkage weak just like the rest of compiler-rt symbols.
 * removed `longDoubleIsF128` and replaced it with `longDoubleIs` which
   takes a type as a parameter. The implementation is now more accurate
   and handles more targets. Similarly, in stage2 the function
   CTypes.sizeInBits is more accurate for long double for more targets.
2022-03-06 16:11:39 -07:00
John Schmidt
6637335981 stage2: implement @mulAdd for scalar floats 2022-03-06 15:36:56 -07:00
Luuk de Gram
c7e4c711fc wasm: Fix incremental compilation
- atoms may have relocations, so freeing them when we update the parent
atom will cause segfaults.
- Not all declarations will live in symbol_atom
2022-03-06 23:33:50 +01:00
Jakub Konka
27c084065a
Merge pull request #11070 from Luukdegram/wasm-unify
stage2: wasm - unify codegen with other backends
2022-03-06 20:44:51 +01:00
Andrew Kelley
9154a86069
Merge pull request #11065 from hexops/sg/responsefiles-2
Do not fail to build if 'zig build-lib' etc. arguments exceed OS limits (take 2)
2022-03-06 14:35:52 -05:00
Andrew Kelley
e535521619 CI: additionally test wasm32-wasi with LLVM backend 2022-03-06 12:25:33 -07:00
Luuk de Gram
6d84f22fa0 stage2: Fix wasm linker for llvm backend
This fixes 2 entrypoints within the self-hosted wasm linker that would be called
for the llvm backend, whereas we should simply call into the llvm backend to perform such action.
i.e. not allocate a decl index when we have an llvm object, and when flushing a module,
we should be calling it on llvm's object, rather than have the wasm linker perform the operation.

Also, this fixes the wasm intrinsics for wasm.memory.size and wasm.memory.grow.
Lastly, this commit ensures that when an extern function is being resolved, we tell LLVM how
to import such function.
2022-03-06 14:17:36 -05:00
Daniele Cocca
716abe3389 CBE: mark more tests as passing 2022-03-06 14:15:57 -05:00
Luuk de Gram
13fca53b92
wasm: Unify function generation
Like decl code generation, also unify the wasm backend and the wasm linker to call into
the general purpose `codegen.zig` to generate the code for a function.
2022-03-06 19:38:53 +01:00
Luuk de Gram
2faba4092a
wasm: Remove old DeclGen/genTypedValue 2022-03-06 19:38:53 +01:00