19561 Commits

Author SHA1 Message Date
Cody Tapscott
c0a1b4fa46 stage2: Fix AIR printing
Packed structs never have comptime fields, and a slice might actually be
backed by a variable, which we need to catch before iterating its
elements.
2022-07-30 12:36:11 -07:00
Evan Haas
8632e4fc7b translate-c: use correct number of initializers for vectors
Fixes #12264
2022-07-30 13:24:03 +03:00
Andrew Kelley
3cf8f283d3
Merge pull request #12085 from topolarity/dyn-link-libcpp
Dynamically link `libc++` if integrating with system LLVM
2022-07-29 14:18:32 -07:00
Cody Tapscott
4fc2acdaa4 build.zig: Emit warning if "config.h" cannot be found
We now warn the user if config.h could not be located.

This also updates the search to stop early upon encountering a
`.git` directory, so that we avoid recursing outside of the zig
source if possible.
2022-07-29 11:38:58 -07:00
Wei Fu
b3d0694fc5 stage1: remove deadcode ast_print
Fixes: 2a990d696 ("stage1: rework tokenizer to match stage2")
Fixes: b6354ddd5 ("move AST rendering code to separate file")

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2022-07-29 11:28:39 -07:00
Andrew Kelley
64dc1b05d6
Merge pull request #12286 from ziglang/division-safety
Division safety improvements
2022-07-29 11:03:27 -07:00
Andrew Kelley
932d1f785e CI: -Denable-llvm for test-cases
This requires using -Dstatic-llvm and setting the search prefix and the
target, just like it is required for building stage2 and stage3. This
prevents Zig from trying to integrate with the system, which would
trigger an error due to the `cc` command not being installed.

closes #12144
2022-07-29 11:03:12 -07:00
Andrew Kelley
a7a6f38eeb Sema: fix runtime safety for integer overflow with vectors 2022-07-29 11:03:12 -07:00
Cody Tapscott
58540f968a ELF: Scan for dylibs-as-objects when adding rpaths
Shared libraries can be provided on the command line as if they were
objects, as a path to the ".so" file. The "each-lib-rpath" functionality
was ignoring these shared libraries accidentally, causing missing rpaths
in the output executable.
2022-07-29 09:44:45 -07:00
Andrew Kelley
1b1c70ce38 disable failing incremental compilation test case
see #12288

now `zig build test-cases -Denable-llvm` passes locally for me.
2022-07-29 02:35:06 -07:00
Andrew Kelley
daac39364a fix compile error test case note column number 2022-07-29 02:35:06 -07:00
Andrew Kelley
40f8f0134f Sema: enhance div_trunc, div_exact, div_floor
* No longer emit div_exact AIR instruction that can produce a
   remainder, invoking undefined behavior.
 * div_trunc, div_exact, div_floor are extracted from analyzeArithmetic
   and directly handled similarly to div_trunc, integrating them with
   integer overflow safety checking.
 * Also they no longer emit divide-by-zero safety checking when RHS
   is comptime known to be non-zero.
2022-07-29 02:35:06 -07:00
Andrew Kelley
1fc24e8d80 Sema: enhance div instruction analysis
Concrete improvements:
 * Added safety for integer overflow (-MAX_INT/-1)
 * Omit division by zero safety check when RHS is comptime known to
   be non-zero.
 * Avoid emitting `_optimized` variants of AIR instructions for integers
   (this suffix is intended to be used for floats only).

Subjective changes: I extracted the div logic out from analyzeArithmetic
in order to reduce the amount of branches - not for performance reasons
but for code clarity. It is more lines of code however, and some logic
is duplicated.
2022-07-29 02:35:06 -07:00
Andrew Kelley
a482517357 std.debug: default signal handler also handles SIGFPE 2022-07-29 02:35:06 -07:00
Veikka Tuominen
fdaf9c40d6 stage2: handle tuple init edge cases 2022-07-29 10:12:36 +03:00
Veikka Tuominen
9e0a930ce3 stage2: add error for comptime control flow in runtime block 2022-07-29 10:08:35 +03:00
Meghan Denny
b5861193e0 std: rename std.Target.systemz to .s390x 2022-07-28 23:22:44 -07:00
Cody Tapscott
f1feb1369b Dynamically link libc++, if integrating with system LLVM
This ensures that the zigcpp clang driver and LLVM are using the
same copy of libc++. See prior commit for more details.
2022-07-28 22:21:24 -07:00
Cody Tapscott
b0525344a2 Add check to verify libc++ is shared by LLVM/Clang
This check is needed because if static/dynamic linking is mixed incorrectly,
it's possible for Clang and LLVM to end up with duplicate "copies" of libc++.

This is not benign: Static variables are not shared, so equality comparisons
that depend on pointers to static variables will fail. One such failure is
std::generic_category(), which causes POSIX error codes to compare as unequal
when passed between LLVM and Clang.

I believe this is the cause of https://github.com/ziglang/zig/issues/11168

In order to avoid affecting build times when Zig is repeatedly invoked,
we only enable this check for "zig env" and "zig version"
2022-07-28 22:21:24 -07:00
Andrew Kelley
e6b3eae490
Merge pull request #11867 from nektro/patch-2
stage2: ensure builtin packages are always available
2022-07-28 15:20:49 -07:00
Veikka Tuominen
ece1d1daf4 CLI: add error for duplicate package 2022-07-28 15:20:01 -07:00
Meghan
02acde99a1 stage2: ensure 'std', 'builtin', and 'root' is always available to @import 2022-07-28 15:19:17 -07:00
joachimschmidt557
0fc79d602b stage2 ARM: more support for switch statements 2022-07-28 20:44:32 +00:00
Loris Cro
e863292fe2 autodoc: no whitespace in json output for release builds
With this change, stdlib autodocs go from 24mb to 16mb (-8mb).
2022-07-28 15:08:58 +02:00
Andrew Kelley
c650ccfca7
Merge pull request #12265 from ziglang/stage3-run-translated-c
CI: test-run-translated-c with stage3
2022-07-27 22:04:00 -07:00
Andrew Kelley
3ccb6a0cd4 CI: run test-run-translated-c tests with stage3 2022-07-27 17:56:59 -07:00
Andrew Kelley
3ba7098a17 LLVM: fix returning extern union with C callconv 2022-07-27 17:56:15 -07:00
Andrew Kelley
6a4df2778e AstGen: fix ref instruction injection for functions
For the expressions regarding return type, alignment,
parameter type, etc.
2022-07-27 16:19:23 -07:00
Andrew Kelley
401abd793d run-translated-c: disable two failing tests
Issues reported:
 * #12263
 * #12264
2022-07-27 16:19:23 -07:00
Andrew Kelley
f880af369d LLVM: fix lowering byte-aligned packed struct field pointers 2022-07-27 16:19:23 -07:00
Andrew Kelley
dfc7493dcb
Merge pull request #12256 from Vexu/stage2
stage2 typeInfo UAF fix + more
2022-07-27 16:11:07 -07:00
Andrew Kelley
90f23e131e
Merge pull request #12252 from ziglang/stage3-test-cases
CI: run test-cases with stage3
2022-07-27 10:27:12 -07:00
Andrew Kelley
0527b441ae move zig.h to become an installation file
Now instead of zig.h being baked into the compiler binary, it is a
header file distributed along with all the other header files
distributed with Zig.

Closes #11643
2022-07-27 10:26:45 -07:00
Veikka Tuominen
793db63746 Sema: copy fn param ty in zirTypeInfo
Closes #12247
2022-07-27 18:27:17 +03:00
LordMZTE
c6f5832bb6 Module: fix inverted condition 2022-07-27 18:17:07 +03:00
LordMZTE
8c4896fb3a Module: use path.isSep
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-07-27 18:17:07 +03:00
LordMZTE
1110eafe9b Module: fix error message importing file starting with root path 2022-07-27 18:17:07 +03:00
r00ster91
baafb8a491 std.fmt: add more invalid format string errors 2022-07-27 18:07:53 +03:00
r00ster91
4ef7d85810 std.fmt: lowercase compile errors
`compileError\("([A-Z])` and `compileError\("\L\1`. It's pretty convenient.
2022-07-27 18:07:53 +03:00
Veikka Tuominen
3818d63dd8 Sema: resolve pointee type in zirReify
Closes #12223
2022-07-27 17:11:46 +03:00
Veikka Tuominen
e4a36a4cec AstGen: add dbg_stmts for unreachable and @panic
Closes #12249
2022-07-27 17:11:46 +03:00
Evan Haas
7ba1f9bfb5 translate-c: take address of functions before passing them to @ptrToInt
Fixes #12194
2022-07-27 14:03:08 +03:00
Andrew Kelley
20c230cda9 test-cases harness: annotate an optional type
Not sure why this is needed by the CI; it's not needed locally. This is
a mystery that will have to wait for another day.
2022-07-27 02:13:01 -07:00
Andrew Kelley
ffac6a1b9f CI: run test-link with stage3 2022-07-26 20:23:33 -07:00
Andrew Kelley
3de9ffa84d CI: run test-cases with stage3
See #12144 for why I did not `-Denable-llvm` yet.
2022-07-26 20:15:57 -07:00
Andrew Kelley
bdaa915a02 test-cases: remove failing test
This causes a stack overflow in a debug build of stage3 unfortunately. I
will open an issue to track this test coverage, which we absolutely
should get working - users of the compiler should get a compile error,
not a segfault if they hit the default branch quota from abusing
recursive inline functions.

Note that the problem does not occur in a release build of stage3
which has significantly reduced stack usage.

On Linux, I tried bumping up the stack size from 32 MiB to 64 MiB and it
did not solve the problem. I'm not sure why not. It seems like it should
be fine.

Note that we also have a problem of running test-cases in multi-threaded
mode which is currently the default. Currently Zig threads are spawned
with 16 MiB stack space.
2022-07-26 20:12:40 -07:00
Andrew Kelley
acf1aa10c2 test-cases harness: refresh just before update()
This makes it so that in a -Dsingle-threaded build of test-cases, if a
crash happens, the test case name will be printed just before the stderr
of the crash.
2022-07-26 20:11:52 -07:00
Andrew Kelley
4e53249d76 test-cases harness: improve stage2 compatibility
* proper skip_stage1 mechanism that doesn't get side-stepped with
   manually added test cases.
 * avoid runtime-known function pointers.
 * check for type equality more simply without checking the type name.
2022-07-26 20:09:48 -07:00
Andrew Kelley
ea3db3274d link: avoid passing bad ptrs to pwritev
At least on Linux, the pwritev syscall checks the pointer and returns
EFAULT before it checks if the length is nonzero.

Perhaps this should be fixed in the standard library, however, these are
still improvements since they make the kernel do less work within the
syscall.
2022-07-26 20:05:54 -07:00
Andrew Kelley
0bc4726e00 LLVM: add probe-stack function attribute 2022-07-26 20:05:06 -07:00