about summary refs log tree commit diff
path: root/tests/codegen
AgeCommit message (Collapse)AuthorLines
2024-04-04Auto merge of #123052 - maurer:addr-taken, r=compiler-errorsbors-2/+2
CFI: Support function pointers for trait methods Adds support for both CFI and KCFI for function pointers to trait methods by attaching both concrete and abstract types to functions. KCFI does this through generation of a `ReifyShim` on any function pointer for a method that could go into a vtable, and keeping this separate from `ReifyShim`s that are *intended* for vtable us by setting a `ReifyReason` on them. CFI does this by setting both the concrete and abstract type on every instance. This should land after #123024 or a similar PR, as it diverges the implementation of CFI vs KCFI. r? `@compiler-errors`
2024-04-03Rollup merge of #122619 - erikdesjardins:cast, r=compiler-errorsMatthias Krüger-6/+302
Fix some unsoundness with PassMode::Cast ABI Fixes #122617 Reviewable commit-by-commit. More info in each commit message.
2024-04-03Auto merge of #122225 - DianQK:nits-120268, r=cjgillotbors-24/+43
Rename `UninhabitedEnumBranching` to `UnreachableEnumBranching` Per [#120268](https://github.com/rust-lang/rust/pull/120268#discussion_r1517492060), I rename `UninhabitedEnumBranching` to `UnreachableEnumBranching` . I solved some nits to add some comments. I adjusted the workaround restrictions. This should be useful for `a <= b` and `if let Some/Ok(v)`. For enum with few variants, `early-tailduplication` should not cause compile time overhead. r? RalfJung
2024-04-02Auto merge of #123385 - matthiaskrgr:rollup-v69vjbn, r=matthiaskrgrbors-2/+47
Rollup of 8 pull requests Successful merges: - #123198 (Add fn const BuildHasherDefault::new) - #123226 (De-LLVM the unchecked shifts [MCP#693]) - #123302 (Make sure to insert `Sized` bound first into clauses list) - #123348 (rustdoc: add a couple of regression tests) - #123362 (Check that nested statics in thread locals are duplicated per thread.) - #123368 (CFI: Support non-general coroutines) - #123375 (rustdoc: synthetic auto trait impls: accept unresolved region vars for now) - #123378 (Update sysinfo to 0.30.8) Failed merges: - #123349 (Fix capture analysis for by-move closure bodies) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-02Auto merge of #118310 - scottmcm:three-way-compare, r=davidtwcobors-0/+47
Add `Ord::cmp` for primitives as a `BinOp` in MIR Update: most of this OP was written months ago. See https://github.com/rust-lang/rust/pull/118310#issuecomment-2016940014 below for where we got to recently that made it ready for review. --- There are dozens of reasonable ways to implement `Ord::cmp` for integers using comparison, bit-ops, and branches. Those differences are irrelevant at the rust level, however, so we can make things better by adding `BinOp::Cmp` at the MIR level: 1. Exactly how to implement it is left up to the backends, so LLVM can use whatever pattern its optimizer best recognizes and cranelift can use whichever pattern codegens the fastest. 2. By not inlining those details for every use of `cmp`, we drastically reduce the amount of MIR generated for `derive`d `PartialOrd`, while also making it more amenable to MIR-level optimizations. Having extremely careful `if` ordering to μoptimize resource usage on broadwell (#63767) is great, but it really feels to me like libcore is the wrong place to put that logic. Similarly, using subtraction [tricks](https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign) (#105840) is arguably even nicer, but depends on the optimizer understanding it (https://github.com/llvm/llvm-project/issues/73417) to be practical. Or maybe [bitor is better than add](https://discourse.llvm.org/t/representing-in-ir/67369/2?u=scottmcm)? But maybe only on a future version that [has `or disjoint` support](https://discourse.llvm.org/t/rfc-add-or-disjoint-flag/75036?u=scottmcm)? And just because one of those forms happens to be good for LLVM, there's no guarantee that it'd be the same form that GCC or Cranelift would rather see -- especially given their very different optimizers. Not to mention that if LLVM gets a spaceship intrinsic -- [which it should](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Suboptimal.20inlining.20in.20std.20function.20.60binary_search.60/near/404250586) -- we'll need at least a rustc intrinsic to be able to call it. As for simplifying it in Rust, we now regularly inline `{integer}::partial_cmp`, but it's quite a large amount of IR. The best way to see that is with https://github.com/rust-lang/rust/commit/8811efa88b25b5e41d63850e6047e8257c677858#diff-d134c32d028fbe2bf835fef2df9aca9d13332dd82284ff21ee7ebf717bfa4765R113 -- I added a new pre-codegen MIR test for a simple 3-tuple struct, and this PR change it from 36 locals and 26 basic blocks down to 24 locals and 8 basic blocks. Even better, as soon as the construct-`Some`-then-match-it-in-same-BB noise is cleaned up, this'll expose the `Cmp == 0` branches clearly in MIR, so that an InstCombine (#105808) can simplify that to just a `BinOp::Eq` and thus fix some of our generated code perf issues. (Tracking that through today's `if a < b { Less } else if a == b { Equal } else { Greater }` would be *much* harder.) --- r? `@ghost` But first I should check that perf is ok with this ~~...and my true nemesis, tidy.~~
2024-04-02CFI: Switch sense of type erasure flagMatthew Maurer-2/+2
Previously, we had `NO_SELF_TYPE_ERASURE`, a negative configuration. Now we have `ERASE_SELF_TYPE`, a positive configuration.
2024-03-30De-LLVM the unchecked shifts [MCP#693]Scott McMurray-2/+47
This is just one part of the MCP, but it's the one that IMHO removes the most noise from the standard library code. Seems net simpler this way, since MIR already supported heterogeneous shifts anyway, and thus it's not more work for backends than before.
2024-03-30Auto merge of #122976 - caibear:optimize_reserve_for_push, r=cuviperbors-3/+3
Remove len argument from RawVec::reserve_for_push Removes `RawVec::reserve_for_push`'s `len` argument since it's always the same as capacity. Also makes `Vec::insert` use `RawVec::reserve_for_push`.
2024-03-29Fix test.Cai Bear-3/+3
2024-03-29Auto merge of #123071 - rcvalle:rust-cfi-fix-method-fn-ptr-cast, ↵bors-0/+22
r=compiler-errors CFI: Fix methods as function pointer cast Fix casting between methods and function pointers by assigning a secondary type id to methods with their concrete self so they can be used as function pointers. This was split off from #116404. cc `@compiler-errors` `@workingjubilee`
2024-03-29Auto merge of #122671 - Mark-Simulacrum:const-panic-msg, r=Nilstriebbors-1/+1
Codegen const panic messages as function calls This skips emitting extra arguments at every callsite (of which there can be many). For a librustc_driver build with overflow checks enabled, this cuts 0.7MB from the resulting shared library (see [perf]). A sample improvement from nightly: ``` leaq str.0(%rip), %rdi leaq .Lalloc_d6aeb8e2aa19de39a7f0e861c998af13(%rip), %rdx movl $25, %esi callq *_ZN4core9panicking5panic17h17cabb89c5bcc999E@GOTPCREL(%rip) ``` to this PR: ``` leaq .Lalloc_d6aeb8e2aa19de39a7f0e861c998af13(%rip), %rdi callq *_RNvNtNtCsduqIKoij8JB_4core9panicking11panic_const23panic_const_div_by_zero@GOTPCREL(%rip) ``` [perf]: https://perf.rust-lang.org/compare.html?start=a7e4de13c1785819f4d61da41f6704ed69d5f203&end=64fbb4f0b2d621ff46d559d1e9f5ad89a8d7789b&stat=instructions:u
2024-03-28Restore the test checks for `wider_reduce_into_iter`DianQK-3/+3
The current minimum support is for LLVM 17.
2024-03-27CFI: Fix methods as function pointer castRamon de C Valle-0/+22
Fix casting between methods and function pointers by assigning a secondary type id to methods with their concrete self so they can be used as function pointers.
2024-03-27Rollup merge of #123075 - rcvalle:rust-cfi-fix-drop-drop-in-place, ↵Matthias Krüger-0/+29
r=compiler-errors CFI: Fix drop and drop_in_place Fix drop and drop_in_place by transforming self of drop and drop_in_place methods into a Drop trait objects. This was split off from https://github.com/rust-lang/rust/pull/116404. cc `@compiler-errors` `@workingjubilee`
2024-03-27CFI: Fix drop and drop_in_placeRamon de C Valle-0/+29
Fix drop and drop_in_place by transforming self of drop and drop_in_place methods into Drop trait objects.
2024-03-25Don't emit load metadata in debug modeclubby789-9/+9
2024-03-23Add+Use `mir::BinOp::Cmp`Scott McMurray-0/+47
2024-03-23Rollup merge of #122875 - maurer:cfi-transparent-termination, r=workingjubileeJubilee-0/+16
CFI: Support self_cell-like recursion Current `transform_ty` attempts to avoid cycles when normalizing `#[repr(transparent)]` types to their interior, but runs afoul of this pattern used in `self_cell`: ``` struct X<T> { x: u8, p: PhantomData<T>, } #[repr(transparent)] struct Y(X<Y>); ``` When attempting to normalize Y, it will still cycle indefinitely. By using a types-visited list, this will instead get expanded exactly one layer deep to X<Y>, and then stop, not attempting to normalize `Y` any further. This PR was split off from #121962 as part of fixing the larger vtable compatibility issues. r? ``````@workingjubilee``````
2024-03-23Auto merge of #122582 - scottmcm:swap-intrinsic-v2, r=oli-obkbors-4/+79
Let codegen decide when to `mem::swap` with immediates Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea. Thus this PR introduces a new `typed_swap` intrinsic with a fallback body, and replaces that fallback implementation when swapping immediates or scalar pairs. r? oli-obk Replaces #111744, and means we'll never need more libs PRs like #111803 or #107140
2024-03-22CFI: Support self_cell-like recursionMatthew Maurer-0/+16
Current `transform_ty` attempts to avoid cycles when normalizing `#[repr(transparent)]` types to their interior, but runs afoul of this pattern used in `self_cell`: ``` struct X<T> { x: u8, p: PhantomData<T>, } #[repr(transparent)] struct Y(X<Y>); ``` When attempting to normalize Y, it will still cycle indefinitely. By using a types-visited list, this will instead get expanded exactly one layer deep to X<Y>, and then stop, not attempting to normalize `Y` any further.
2024-03-22Codegen const panic messages as function callsMark Rousskov-1/+1
This skips emitting extra arguments at every callsite (of which there can be many). For a librustc_driver build with overflow checks enabled, this cuts 0.7MB from the resulting binary.
2024-03-22Auto merge of #122456 - maurer:cfi-nonpassed, r=workingjubileebors-32/+32
CFI: Skip non-passed arguments Rust will occasionally rely on fn((), X) -> Y being compatible with fn(X) -> Y, since () is a non-passed argument. Relax CFI by choosing not to encode non-passed arguments. This PR was split off from #121962 as part of fixing the larger vtable compatibility issues. r? `@workingjubilee`
2024-03-21CFI: Skip non-passed argumentsMatthew Maurer-32/+32
Rust will occasionally rely on fn((), X) -> Y being compatible with fn(X) -> Y, since () is a non-passed argument. Relax CFI by choosing not to encode non-passed arguments.
2024-03-19Remove `SpecOptionPartialEq`clubby789-3/+40
2024-03-19Auto merge of #122375 - rcvalle:rust-cfi-break-tests-into-smaller-files, ↵bors-606/+759
r=compiler-errors CFI: Break tests into smaller files Break type metadata identifiers tests into smaller set of tests/files, and move CFI (and KCFI) codegen tests to a cfi (and kcfi) subdirectory,
2024-03-17Stop whining, tidyScott McMurray-0/+1
2024-03-17Let codegen decide when to `mem::swap` with immediatesScott McMurray-4/+78
Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea. So introduce a new `typed_swap` intrinsic with a fallback body, but replace that implementation for immediates and scalar pairs.
2024-03-17Remove an obsolete `ignore-llvm-version`Josh Stone-2/+0
2024-03-17disable crashing test on sparcErik Desjardins-12/+23
2024-03-17Update the minimum external LLVM to 17Josh Stone-17/+0
2024-03-17add tests for PassMode::Cast fixesErik Desjardins-6/+291
Tests added in cast-target-abi.rs, covering the single element, array, and prefix cases in `CastTarget::llvm_type`, and the Rust-is-larger/smaller cases in the Rust<->ABI copying code. ffi-out-of-bounds-loads.rs was overhauled to be runnable on any platform. Its alignment also increases due to the removal of a `min` in the previous commit; this was probably an insufficient workaround for this issue or similar. The higher alignment is fine, since the alloca is actually aligned to 8 bytes, as the test checks now confirm.
2024-03-16Auto merge of #122371 - oli-obk:visit_nested_body, r=tmiaskobors-0/+10
Stop walking the bodies of statics for reachability, and evaluate them instead cc `@saethlin` `@RalfJung` cc #119214 This reuses the `DefIdVisitor` from `rustc_privacy`, because they basically try to do the same thing. This PR's changes can probably be extended to constants, too, but let's tackle that separately, it's likely more involved.
2024-03-14Rollup merge of #122212 - erikdesjardins:byval-align2, r=wesleywiserMatthias Krüger-0/+126
Copy byval argument to alloca if alignment is insufficient Fixes #122211 "Ignore whitespace" recommended.
2024-03-14Stop walking the bodies of statics for reachability, and evaluate them insteadOli Scherer-1/+1
2024-03-14Add testOli Scherer-0/+10
2024-03-14CFI: Break tests into smaller filesRamon de C Valle-606/+759
Break type metadata identifiers tests into smaller set of tests/files, and move CFI (and KCFI) codegen tests to a cfi (and kcfi) subdirectory.
2024-03-13Auto merge of #121668 - erikdesjardins:commonprim, r=scottmcm,oli-obkbors-12/+143
Represent `Result<usize, Box<T>>` as ScalarPair(i64, ptr) This allows types like `Result<usize, std::io::Error>` (and integers of differing sign, e.g. `Result<u64, i64>`) to be passed in a pair of registers instead of through memory, like `Result<u64, u64>` or `Result<Box<T>, Box<U>>` are today. Fixes #97540. r? `@ghost`
2024-03-13Update `unreachable_enum_default_branch.rs`DianQK-24/+43
2024-03-13refine common_prim testErik Desjardins-8/+16
Co-authored-by: Scott McMurray <scottmcm@users.noreply.github.com>
2024-03-12Avoid lowering code under dead SwitchInt targetsBen Kimock-0/+68
2024-03-12Auto merge of #121282 - saethlin:gep-null-means-no-provenance, r=scottmcmbors-3/+3
Lower transmutes from int to pointer type as gep on null I thought of this while looking at https://github.com/rust-lang/rust/pull/121242. See that PR's description for why this lowering is preferable. The UI test that's being changed here crashes without changing the transmutes into casts. Based on that, this PR should not be merged without a crater build-and-test run.
2024-03-12Auto merge of #122036 - alexcrichton:test-wasm-with-wasi, r=oli-obkbors-9/+12
Test wasm32-wasip1 in CI, not wasm32-unknown-unknown This commit changes CI to no longer test the `wasm32-unknown-unknown` target and instead test the `wasm32-wasip1` target. There was some discussion of this in a [Zulip thread], and the motivations for this PR are: * Runtime failures on `wasm32-unknown-unknown` print nothing, meaning all you get is "something failed". In contrast `wasm32-wasip1` can print to stdout/stderr. * The unknown-unknown target is missing lots of pieces of libstd, and while `wasm32-wasip1` is also missing some pieces (e.g. threads) it's missing fewer pieces. This means that many more tests can be run. Overall my hope is to improve the debuggability of wasm failures on CI and ideally be a bit less of a maintenance burden. This commit specifically removes the testing of `wasm32-unknown-unknown` and replaces it with testing of `wasm32-wasip1`. Along the way there were a number of other archiectural changes made as well, including: * A new `target.*.runtool` option can now be specified in `config.toml` which is passed as `--runtool` to `compiletest`. This is used to reimplement execution of WebAssembly in a less-wasm-specific fashion. * The default value for `runtool` is an ambiently located WebAssembly runtime found on the system, if any. I've implemented logic for Wasmtime. * Existing testing support for `wasm32-unknown-unknown` and Emscripten has been removed. I'm not aware of Emscripten testing being run any time recently and otherwise `wasm32-wasip1` is in theory the focus now. * I've added a new `//@ needs-threads` directive for `compiletest` and classified a bunch of wasm-ignored tests as needing threads. In theory these tests can run on `wasm32-wasi-preview1-threads`, for example. * I've tried to audit all existing tests that are either `ignore-emscripten` or `ignore-wasm*`. Many now run on `wasm32-wasip1` due to being able to emit error messages, for example. Many are updated with comments as to why they can't run as well. * The `compiletest` output matching for `wasm32-wasip1` automatically uses "match a subset" mode implemented in `compiletest`. This is because WebAssembly runtimes often add extra information on failure, such as the `unreachable` instruction in `panic!`, which isn't able to be matched against the golden output from native platforms. * I've ported most existing `run-make` tests that use custom Node.js wrapper scripts to the new run-make-based-in-Rust infrastructure. To do this I added `wasmparser` as a dependency of `run-make-support` for the various wasm tests to use that parse wasm files. The one test that executed WebAssembly now uses `wasmtime`-the-CLI to execute the test instead. I have not ported over an exception-handling test as Wasmtime doesn't implement this yet. * I've updated the `test` crate to print out timing information for WASI targets as it can do that (gets a previously ignored test now passing). * The `test-various` image now builds a WASI sysroot for the WASI target and additionally downloads a fixed release of Wasmtime, currently the latest one at 18.0.2, and uses that for testing. [Zulip thread]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Have.20wasm.20tests.20ever.20caused.20problems.20on.20CI.3F/near/424317944
2024-03-11Lower transmutes from int to pointer type as gep on nullBen Kimock-3/+3
2024-03-11Update test directives for `wasm32-wasip1`Alex Crichton-9/+12
* The WASI targets deal with the `main` symbol a bit differently than native so some `codegen` and `assembly` tests have been ignored. * All `ignore-emscripten` directives have been updated to `ignore-wasm32` to be more clear that all wasm targets are ignored and it's not just Emscripten. * Most `ignore-wasm32-bare` directives are now gone. * Some ignore directives for wasm were switched to `needs-unwind` instead. * Many `ignore-wasm32*` directives are removed as the tests work with WASI as opposed to `wasm32-unknown-unknown`.
2024-03-11Rollup merge of #122320 - erikdesjardins:vtable, r=nikicJubilee-2/+87
Use ptradd for vtable indexing Extension of #121665. After this, the only remaining usages of GEP are [this](https://github.com/rust-lang/rust/blob/cd81f5b27ee00b49d413db50b5e6af871cebcf23/compiler/rustc_codegen_llvm/src/intrinsic.rs#L909-L920) kinda janky Emscription EH code, which I'll change in a future PR, and array indexing / pointer offsets, where there isn't yet a canonical `ptradd` form. (Out of curiosity I tried converting the latter to `ptradd(ptr, mul(size, index))`, but that causes codegen regressions right now.) r? `@nikic`
2024-03-11copy byval argument to alloca if alignment is insufficientErik Desjardins-0/+126
2024-03-11Auto merge of #122050 - erikdesjardins:sret, r=nikicbors-124/+278
Stop using LLVM struct types for byval/sret For `byval` and `sret`, the type has no semantic meaning, only the size matters\*†. Using `[N x i8]` is a more direct way to specify that we want `N` bytes, and avoids relying on LLVM's struct layout. \*: The alignment would matter, if we didn't explicitly specify it. From what I can tell, we always specified the alignment for `sret`; for `byval`, we didn't until #112157. †: For `byval`, the hidden copy may be impacted by padding in the LLVM struct type, i.e. padding bytes may not be copied. (I'm not sure if this is done today, but I think it would be legal.) But we manually pad our LLVM struct types specifically to avoid there ever being LLVM-visible padding, so that shouldn't be an issue. Split out from #121577. r? `@nikic`
2024-03-10use ptradd for vtable indexingErik Desjardins-2/+87
Like field offsets, these are always constant.
2024-03-10add -O to some tests which depend on attributes being addedErik Desjardins-5/+6
2024-03-10Rollup merge of #121642 - TimNN:test-v0, r=Mark-SimulacrumMatthias Krüger-2/+2
Update a test to support Symbol Mangling V0 Note that since this is a symbol from `std`, overriding the symbol mangling version via the `compile-flags` directive does not work.