about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
AgeCommit message (Collapse)AuthorLines
2024-04-04Auto merge of #123455 - matthiaskrgr:rollup-b6nu296, r=matthiaskrgrbors-4/+4
Rollup of 9 pull requests Successful merges: - #121546 (Error out of layout calculation if a non-last struct field is unsized) - #122448 (Port hir-tree run-make test to ui test) - #123212 (CFI: Change type transformation to use TypeFolder) - #123218 (Add test for getting parent HIR for synthetic HIR node) - #123324 (match lowering: make false edges more precise) - #123389 (Avoid panicking unnecessarily on startup) - #123397 (Fix diagnostic for qualifier in extern block) - #123431 (Stabilize `proc_macro_byte_character` and `proc_macro_c_str_literals`) - #123439 (coverage: Remove useless constants) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-04Rollup merge of #123439 - Zalathar:constants, r=oli-obkMatthias Krüger-4/+4
coverage: Remove useless constants After #122972 and #123419, these constants don't serve any useful purpose, so get rid of them. `@rustbot` label +A-code-coverage
2024-04-04Auto merge of #121026 - Zalathar:version, r=oli-obkbors-9/+20
coverage: Correctly report and check LLVM's coverage mapping version I was puzzled by the fact that the LLVM 18 update (#120055) didn't need to modify this version check, despite the fact that LLVM 18 uses a newer version of the coverage mapping format. This turned out to be because we were inappropriately hard-coding a specific version (`Version6`) in the C++ wrapper, instead of using `CovMapVersion::CurrentVersion` to reflect the version actually used by LLVM on our behalf. This PR fixes that, and also changes the Rust-side version check to accept the new coverage mapping version used by LLVM 18, since the necessary compatibility work has already been done. --- ### Quick history of `LLVMRustCoverageMappingVersion`: - Originally it returned LLVM's `coverage::CovMapVersion::CurrentVersion`, as intended. The Rust-side code would verify it, and also embed it as the actual coverage version number in the output binary. - At some point it was changed to a hard-coded value, to work around a (now-irrelevant) compatibility issue. This was incorrect (but mostly benign), because the override should have been performed on the Rust side instead, after verifying LLVM's value. - Later contributors dutifully updated the hard-coded value, because they didn't have enough context to identify the problem. - With this PR, it once again returns LLVM's current coverage version number, and the Rust-side code checks it against an expected range. We don't override the result, but we do indicate where that override should occur if it ever becomes necessary.
2024-04-04Auto merge of #123052 - maurer:addr-taken, r=compiler-errorsbors-2/+4
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-04coverage: Remove useless constantsZalathar-4/+4
2024-04-03Rollup merge of #122964 - joboet:pointer_expose, r=AmanieuMatthias Krüger-1/+1
Rename `expose_addr` to `expose_provenance` `expose_addr` is a bad name, an address is just a number and cannot be exposed. The operation is actually about the provenance of the pointer. This PR thus changes the name of the method to `expose_provenance` without changing its return type. There is sufficient precedence for returning a useful value from an operation that does something else without the name indicating such, e.g. [`Option::insert`](https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.insert) and [`MaybeUninit::write`](https://doc.rust-lang.org/nightly/std/mem/union.MaybeUninit.html#method.write). Returning the address is merely convenient, not a fundamental part of the operation. This is implied by the fact that integers do not have provenance since ```rust let addr = ptr.addr(); ptr.expose_provenance(); let new = ptr::with_exposed_provenance(addr); ``` must behave exactly like ```rust let addr = ptr.expose_provenance(); let new = ptr::with_exposed_provenance(addr); ``` as the result of `ptr.expose_provenance()` and `ptr.addr()` is the same integer. Therefore, this PR removes the `#[must_use]` annotation on the function and updates the documentation to reflect the important part. ~~An alternative name would be `expose_provenance`. I'm not at all opposed to that, but it makes a stronger implication than we might want that the provenance of the pointer returned by `ptr::with_exposed_provenance`[^1] is the same as that what was exposed, which is not yet specified as such IIUC. IMHO `expose` does not make that connection.~~ A previous version of this PR suggested `expose` as name, libs-api [decided on](https://github.com/rust-lang/rust/pull/122964#issuecomment-2033194319) `expose_provenance` to keep the symmetry with `with_exposed_provenance`. CC `@RalfJung` r? libs-api [^1]: I'm using the new name for `from_exposed_addr` suggested by #122935 here.
2024-04-03Rollup merge of #122619 - erikdesjardins:cast, r=compiler-errorsMatthias Krüger-69/+51
Fix some unsoundness with PassMode::Cast ABI Fixes #122617 Reviewable commit-by-commit. More info in each commit message.
2024-04-03rename `expose_addr` to `expose_provenance`joboet-1/+1
2024-04-02Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=AmanieuJacob Pratt-1/+1
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066). The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".) The new name nicely matches `ptr::without_provenance`.
2024-04-03coverage: Correctly report and check LLVM's coverage mapping versionZalathar-9/+20
2024-04-02Auto merge of #118310 - scottmcm:three-way-compare, r=davidtwcobors-0/+4
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/+4
Previously, we had `NO_SELF_TYPE_ERASURE`, a negative configuration. Now we have `ERASE_SELF_TYPE`, a positive configuration.
2024-04-01Auto merge of #122972 - beetrees:use-align-type, r=fee1-deadbors-6/+8
Use the `Align` type when parsing alignment attributes Use the `Align` type in `rustc_attr::parse_alignment`, removing the need to call `Align::from_bytes(...).unwrap()` later in the compilation process.
2024-04-01Use the `Align` type when parsing alignment attributesbeetrees-6/+8
2024-03-29Auto merge of #122450 - Urgau:simplify-trim-paths-feature, r=michaelwoeristerbors-33/+43
Simplify trim-paths feature by merging all debuginfo options together This PR simplifies the trim-paths feature by merging all debuginfo options together, as described in https://github.com/rust-lang/rust/issues/111540#issuecomment-1994010274. And also do some correctness fixes found during the review. cc `@weihanglo` r? `@michaelwoerister`
2024-03-29Auto merge of #123071 - rcvalle:rust-cfi-fix-method-fn-ptr-cast, ↵bors-26/+26
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-28Replace Session should_remap_filepaths with filename_display_preferenceUrgau-18/+13
2024-03-28Introduce `FileNameMapping::to_real_filename` and use it everywhereUrgau-20/+16
2024-03-28Make local_crate_source_file return a RealFileNameUrgau-1/+2
so it can be remapped (or not) by callers
2024-03-28Replace `RemapFileNameExt::for_codegen` with explicit callsUrgau-9/+28
2024-03-28Simplify trim-paths feature by merging all debuginfo options togetherUrgau-4/+3
2024-03-27CFI: Fix methods as function pointer castRamon de C Valle-26/+26
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 #123021 - compiler-errors:coroutine-layout-lol, r=oli-obkGuillaume Gomez-4/+7
Make `TyCtxt::coroutine_layout` take coroutine's kind parameter For coroutines that come from coroutine-closures (i.e. async closures), we may have two kinds of bodies stored in the coroutine; one that takes the closure's captures by reference, and one that takes the captures by move. These currently have identical layouts, but if we do any optimization for these layouts that are related to the upvars, then they will diverge -- e.g. https://github.com/rust-lang/rust/pull/120168#discussion_r1536943728. This PR relaxes the assertion I added in #121122, and instead make the `TyCtxt::coroutine_layout` method take the `coroutine_kind_ty` argument from the coroutine, which will allow us to differentiate these by-move and by-ref bodies.
2024-03-27Rollup merge of #122860 - Zalathar:unused, r=cjgillotGuillaume Gomez-72/+92
coverage: Re-enable `UnreachablePropagation` for coverage builds This is a sequence of 3 related changes: - Clean up the existing code that scans for unused functions - Detect functions that were instrumented for coverage, but have had all their coverage statements removed by later MIR transforms (e.g. `UnreachablePropagation`) - Re-enable `UnreachablePropagation` in coverage builds Because we now detect functions that have lost their coverage statements, and treat them as unused, we don't need to worry about `UnreachablePropagation` removing all of those statements. This is demonstrated by `tests/coverage/unreachable.rs`. Fixes #116171.
2024-03-26Auto merge of #122849 - clubby789:no-metadata, r=petrochenkovbors-0/+11
Don't emit load metadata in debug mode r? `@ghost`
2024-03-26coverage: Detect functions that have lost all their coverage statementsZalathar-4/+18
If a function was instrumented for coverage, but all of its coverage statements have been removed by later MIR transforms, it should be treated as "unused" even if the compiler generates an unreachable stub for it.
2024-03-26coverage: Overhaul the search for unused functionsZalathar-62/+68
2024-03-26coverage: Inline creating a dummy instance for unused functionsZalathar-11/+11
2024-03-25Don't emit load metadata in debug modeclubby789-0/+11
2024-03-25Instance is CopyMichael Goulet-7/+7
2024-03-24Require coroutine kind type to be passed to TyCtxt::coroutine_layoutMichael Goulet-3/+7
2024-03-24Always use tcx.coroutine_layout over calling optimized_mir directlyMichael Goulet-3/+2
2024-03-24Rollup merge of #122937 - Zalathar:unbox, r=oli-obkMatthias Krüger-3/+1
Unbox and unwrap the contents of `StatementKind::Coverage` The payload of coverage statements was historically a structure with several fields, so it was boxed to avoid bloating `StatementKind`. Now that the payload is a single relatively-small enum, we can replace `Box<Coverage>` with just `CoverageKind`. This patch also adds a size assertion for `StatementKind`, to avoid accidentally bloating it in the future. ``@rustbot`` label +A-code-coverage
2024-03-23Add+Use `mir::BinOp::Cmp`Scott McMurray-0/+4
2024-03-23also rename the SIMD intrinsicRalf Jung-1/+1
2024-03-23CFI: Use Instance at callsitesMatthew Maurer-31/+55
We already use `Instance` at declaration sites when available to glean additional information about possible abstractions of the type in use. This does the same when possible at callsites as well. The primary purpose of this change is to allow CFI to alter how it generates type information for indirect calls through `Virtual` instances.
2024-03-23Unbox and unwrap the contents of `StatementKind::Coverage`Zalathar-3/+1
The payload of coverage statements was historically a structure with several fields, so it was boxed to avoid bloating `StatementKind`. Now that the payload is a single relatively-small enum, we can replace `Box<Coverage>` with just `CoverageKind`. This patch also adds a size assertion for `StatementKind`, to avoid accidentally bloating it in the future.
2024-03-23Auto merge of #119552 - krtab:dead_code_priv_mod_pub_field, r=cjgillot,saethlinbors-5/+1
Replace visibility test with reachability test in dead code detection Fixes https://github.com/rust-lang/rust/issues/119545 Also included is a fix for an error now flagged by the lint
2024-03-22Make RawPtr take Ty and Mutbl separatelyMichael Goulet-13/+13
2024-03-22Programmatically convert some of the pat ctorsMichael Goulet-5/+5
2024-03-22coverage: Clean up marker statements that aren't needed laterZalathar-9/+1
Some of the marker statements used by coverage are added during MIR building for use by the InstrumentCoverage pass (during analysis), and are not needed afterwards.
2024-03-20Rollup merge of #121543 - onur-ozkan:clippy-args, r=oli-obkMatthias Krüger-0/+1
various clippy fixes We need to keep the order of the given clippy lint rules before passing them. Since clap doesn't offer any useful interface for this purpose out of the box, we have to handle it manually. Additionally, this PR makes `-D` rules work as expected. Previously, lint rules were limited to `-W`. By enabling `-D`, clippy began to complain numerous lines in the tree, all of which have been resolved in this PR as well. Fixes #121481 cc `@matthiaskrgr`
2024-03-20resolve clippy errorsonur-ozkan-0/+1
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-03-18Rollup merge of #122649 - cuviper:min-llvm-17, r=nikicMatthias Krüger-11/+0
Update the minimum external LLVM to 17 With this change, we'll have stable support for LLVM 17 and 18. For reference, the previous increase to LLVM 16 was #117947.
2024-03-18Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few ↵Oli Scherer-1/+1
cases that used `None`
2024-03-17Update the minimum external LLVM to 17Josh Stone-11/+0
2024-03-17make PassMode::Cast consistently copy between Rust/ABI representationErik Desjardins-41/+27
Previously, we did this slightly incorrectly for return values, and didn't do it at all for arguments.
2024-03-17make CastTarget::size and CastTarget::llvm_type consistent, removeErik Desjardins-28/+24
special case that's not present in Clang Making the methods consistent doesn't require much justification. It's required for us to generate correct code. The special case was present near the end of `CastTarget::llvm_type`, and resulted in the final integer component of the ABI type being shrunk to the smallest integer that fits. You can see this in action here (https://godbolt.org/z/Pe73cr91d), where, for a struct with 5 u16 elements, rustc generates `{ i64, i16 }`, while Clang generates `[2 x i64]`. This special case was added a long time ago, when the function was originally written [1]. That commit consolidated logic from many backends, and in some of the code it deleted, sparc64 [2] and powerpc64 [3] had similar special cases. However, looking at Clang today, it doesn't have this special case for sparc64 (https://godbolt.org/z/YaafvYWdf) or powerpc64 (https://godbolt.org/z/5c3YePTje), so this change just removes it. [1]: https://github.com/rust-lang/rust/commit/f0636b61c7f84962a609e831760db9d77f4f5e14#diff-183c4dadf10704bd1f521b71f71d89bf755c9603a93f894d66c03bb1effc6021R231 [2]: https://github.com/rust-lang/rust/commit/f0636b61c7f84962a609e831760db9d77f4f5e14#diff-2d8f87ea6db6d7f0a6fbeb1d5549adc07e93331278d951a1e051a40f92914436L163-L166 [3]: https://github.com/rust-lang/rust/commit/f0636b61c7f84962a609e831760db9d77f4f5e14#diff-88af4a9df9ead503a5c7774a0455d270dea3ba60e9b0ec1ce550b4c53d3bce3bL172-L175
2024-03-15Register LLVM handlers for bad-alloc / OOMJosh Stone-2/+2
LLVM's default bad-alloc handler may throw if exceptions are enabled, and `operator new` isn't hooked at all by default. Now we register our own handler that prints a message similar to fatal errors, then aborts. We also call the function that registers the C++ `std::new_handler`.
2024-03-14Rollup merge of #122322 - Zalathar:branch, r=oli-obkMatthias Krüger-5/+11
coverage: Initial support for branch coverage instrumentation (This is a review-ready version of the changes that were drafted in #118305.) This PR adds support for branch coverage instrumentation, gated behind the unstable flag value `-Zcoverage-options=branch`. (Coverage instrumentation must also be enabled with `-Cinstrument-coverage`.) During THIR-to-MIR lowering (MIR building), if branch coverage is enabled, we collect additional information about branch conditions and their corresponding then/else blocks. We inject special marker statements into those blocks, so that the `InstrumentCoverage` MIR pass can reliably identify them even after the initially-built MIR has been simplified and renumbered. The rest of the changes are mostly just plumbing needed to gather up the information that was collected during MIR building, and include it in the coverage metadata that we embed in the final binary. Note that `llvm-cov show` doesn't print branch coverage information in its source views by default; that needs to be explicitly enabled with `--show-branches=count` or similar. --- The current implementation doesn't have any support for instrumenting `if let` or let-chains. I think it's still useful without that, and adding it would be non-trivial, so I'm happy to leave that for future work.