Commit Graph

27019 Commits

Author SHA1 Message Date
mlugg
2c1acb6180
test: update translate-c tests to match new discard format 2023-11-19 09:55:07 +00:00
mlugg
51595d6b75
lib: correct unnecessary uses of 'var' 2023-11-19 09:55:07 +00:00
mlugg
baabc6013e
compiler: add error for unnecessary use of 'var'
When a local variable is never used as an lvalue, we can determine that
`const` would be sufficient for this variable, so emit an error in this
case. More sophisticated checking is unfortunately not possible with
Zig's current analysis model, since whether an lvalue is actually
mutated depends on semantic analysis, in which some code paths may not
be analyzed, so attempting to determine this would result in false
positive compile errors.

It's worth noting that an unfortunate consequence of this is that any
field call `a.b()` will allow `a` to be `var`, even if `b` does not take
a pointer as its first parameter - this is again a necessary compromise
because the parameter type is not known until semantic analysis.

Also update `translate-c` to not trigger these errors. This is done by
replacing the `_ = @TypeOf(x)` emitted with `_ = &x` - the reference
there means that the local is permitted to be `var`. A similar strategy
will be used to prevent compile errors in the behavior tests, where we
sometimes want to force a value to be runtime-known.

Resolves: #224
2023-11-19 09:55:07 +00:00
dweiller
325e0f5f0e test: check compile errors when compilation has no errors 2023-11-19 00:12:43 +02:00
Eric Joldasov
4e212f1650 std.enums: allow non-exhaustive enums in EnumIndexer and make count comptime_int instead of usize
Seems like this restriction was actual when Ziglang had extern enums,
but now it's not neccessary and can be lifted. It was present since
original PR which introduced std.enums, https://www.github.com/ziglang/zig/pull/8171.
See also: https://ziggit.dev/t/catching-invalid-enum-value-errors/2206/11

* Make `count` comptime_int instead of usize

With previous type, creating EnumIndexer for enum(usize) and enum(isize)
would cause compile error since `count` could not store maxInt(usize) + 1.
Now it can store it and reflects len field from std.builtin.Type.Array
(most common use case of count field inside std.enums functions is creating arrays).

Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-11-18 16:25:55 +02:00
Curtis Tate Wilkinson
7b99189f19
Add struct declaration location to empty root struct field member error 2023-11-18 12:03:10 +00:00
Lucas Santos
d44f822821 Faster implementation of intToEnum. 2023-11-18 11:24:13 +02:00
Jakub Konka
91329ce944 std.macho: fix LoadCommandIterator to work with underaligned data 2023-11-17 20:49:32 +01:00
Veikka Tuominen
5f86414019
Merge pull request #18006 from Vexu/aro-translate-c
Sync Aro dependency & translate-c progress
2023-11-17 09:02:11 +02:00
Veikka Tuominen
acebf05be9 aro-translate-c: update to upstream changes 2023-11-17 09:01:25 +02:00
David
673a1efa22
Sema: include sentinel in type of pointer-to-array ptr field
Resolves: #18007
2023-11-16 16:08:30 +00:00
Jakub Konka
b173088089
Merge pull request #18015 from ziglang/elf-tests
More ELF tests
2023-11-16 16:11:24 +01:00
David
941090d94f
Move duplicate field detection for struct init expressions into AstGen
Partially addresses #17916.
2023-11-16 14:38:16 +00:00
Jakub Konka
85c0485fd9 elf: test -r mode does not create unneeded .eh_frame section 2023-11-16 10:54:39 +01:00
Jakub Konka
f6bf3353b1 elf: test -r mode with archive on the linker line 2023-11-16 10:51:21 +01:00
Krzysztof Wolicki
acf9de376d
Sema: Add error for non-power of 2 field alignment when reifying Unions, Structs, Pointers 2023-11-16 10:19:54 +02:00
Jakub Konka
359842f8d5
Merge pull request #18010 from ziglang/elf-symtab-fixes
elf: actually write synthetic globals to output symtab and other misc fixes
2023-11-16 01:18:22 +01:00
Jakub Konka
6e4d7362ce elf: fix emitting start/stop synthetic symbols 2023-11-15 19:20:03 +01:00
Jakub Konka
d771c0a7a1 elf: create .got.plt unconditionally 2023-11-15 19:07:09 +01:00
Jakub Konka
6f3bbd5eaa elf: we were writing too many symbols in the symtab 2023-11-15 19:00:13 +01:00
Jakub Konka
760ce69734 elf: actually write synthetic globals to output symtab 2023-11-15 15:07:09 +01:00
Veikka Tuominen
145ddb8104 sync Aro dependency
ref: 0c8c251e336148413ceca7b345c0b6f7255b009b
2023-11-15 11:26:49 +02:00
Veikka Tuominen
c327489d21 aro-translate-c: start work on translating statements 2023-11-15 10:51:26 +02:00
Veikka Tuominen
a15feeb694 aro-translate-c: translate function types 2023-11-15 10:50:45 +02:00
Jacob Young
0c6cb8d8c8 x86_64: actually track state during @divFloor of i128
Closes #17998
2023-11-14 22:50:05 -05:00
Jakub Konka
6fd1c64f23
Merge pull request #17978 from ziglang/elf-x86-tls
x86_64+elf: TLS support
2023-11-14 22:09:15 +01:00
Jakub Konka
ea3f1d27e0 std: disable failing test 2023-11-14 16:51:38 +01:00
Jakub Konka
4adb8f786f elf: do not pointlessly store zerofill data for TLVs 2023-11-14 16:51:25 +01:00
Andrew Kelley
f8b38a174f adjust building from source without LLVM process
The idea here is that the zig2 executable is perhaps the more useful
deliverable until we implement our own optimization passes. This will
allow system packages to provide Zig, and use it to compile Zig
projects, all without LLVM!
2023-11-14 02:17:51 -05:00
Jakub Konka
e883907431 coff: revert .rdata to be read-only again 2023-11-13 23:23:06 +01:00
Jakub Konka
028bfdbca3 coff: mark dirty any reloc target at [addr,..) inclusive 2023-11-13 23:07:21 +01:00
Michael Dusan
569182dbb2 compilation: forbid PIE for dynamic libraries
but allow for { .exe, .o, .a }.

closes #17928
2023-11-13 20:30:57 +01:00
Jakub Konka
8c748d5fd7 elf: setting offset to maxInt for non-allocated non-incremental sections is bad 2023-11-13 17:57:57 +01:00
xdBronch
5de0636577 expose to build system 2023-11-13 14:57:51 +02:00
Andrew Kelley
caae40c216
Merge pull request #17892 from ziglang/bootstrap-without-llvm
Add an easy way to build from source without LLVM
2023-11-13 01:38:46 -05:00
Andrew Kelley
91b897ef58 rework memory management of Module.Namespace hash maps
The motivating problem here was a memory leak in the hash maps of
Module.Namespace.

The commit deletes more of the legacy incremental compilation
implementation. It had things like use of orderedRemove and trying to do
too much OOP-style creation and deletion of objects.

Instead, this commit iterates over all the namespaces on Module deinit
and calls deinit on the hash map fields. This logic is much simpler to
reason about.

Similarly, change global inline assembly to an array hash map since
iterating over the values is a primary use of it, and clean up the
remaining values on Module deinit, solving another memory leak.

After this there are no more memory leaks remaining when using the
x86 backend in a libc-less compiler.
2023-11-12 23:21:21 -05:00
Andrew Kelley
557cb64691 bootstrap.c: add -pthread if the compiler is gnu
otherwise we get undefined symbol errors on pthread stuff
2023-11-12 17:30:24 -07:00
Jacob Young
0dbaa8d3ae zig.h: workaround for gcc f128 miscompilations 2023-11-12 17:30:24 -07:00
Andrew Kelley
f45aac4903 CI: test building from source without LLVM 2023-11-12 17:30:24 -07:00
Andrew Kelley
3c921522b5 bootstrap.c: update aro module 2023-11-12 17:30:24 -07:00
Andrew Kelley
910143e54c README: make note of what features are missing without LLVM 2023-11-12 17:30:24 -07:00
Andrew Kelley
621e89a863 add bootstrap.c for building from source without LLVM
When a zig compiler without LLVM extensions is satisfactory, this
greatly simplified build-from-source process can be used.

This could be useful for users who only want to contribute to the
standard library, for example.
2023-11-12 17:30:24 -07:00
kcbanner
53500a5768 sema: fixup underflows during struct / ptr array init when using -fstrip 2023-11-12 18:22:57 -05:00
Jacob Young
80b73e3e8f x86_64: resolve tlv references on first use and spill to the stack
This avoids any arbitrary memory operand possibly clobbering rax and
sometime rdi with no warning.
2023-11-12 18:12:41 -05:00
Jakub Konka
3d3153c58e x86_64: use .rax for local exec as prescribed by the spec 2023-11-12 18:12:41 -05:00
Jakub Konka
c6833e6273 x86_64: remove unreachable Elf prong 2023-11-12 18:12:41 -05:00
Jakub Konka
575c29e5c4 elf: set symbol flags such as needs_zig_got in ZigObject 2023-11-12 18:12:41 -05:00
Jakub Konka
412519dd49 x86_64: seems like we will need to keep track of rax and reserve rax+rdi for TLS 2023-11-12 18:12:41 -05:00
Jakub Konka
0dab319e86 elf: dump PLT entries 2023-11-12 18:12:41 -05:00
Jakub Konka
984c598590 x86_64: emit TLS local dynamic model when PIC 2023-11-12 18:12:41 -05:00