about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm
AgeCommit message (Collapse)AuthorLines
2022-02-16MemTagSanitizer SupportIvan Lozano-0/+14
Adds support for the LLVM MemTagSanitizer.
2022-02-16debuginfo: Support fat pointers to unsized tuples.Michael Woerister-9/+4
2022-02-15fix assumption that ScalarPair Box is always a fat pointerDrMeepster-1/+1
2022-02-15Auto merge of #93439 - abrown:cf-protection, r=nagisabors-1/+20
Add support for control-flow protection This change adds a flag for configuring control-flow protection in the LLVM backend. In Clang, this flag is exposed as `-fcf-protection` with options `none|branch|return|full`. This convention is followed for `rustc`, though as a codegen option: `rustc -Z cf-protection=<none|branch|return|full>`. Tracking issue for future work is #93754.
2022-02-15Rollup merge of #94001 - durin42:llvm-15-uwtable, r=nikicMatthias Krüger-5/+13
llvm: migrate to new parameter-bearing uwtable attr In https://reviews.llvm.org/D114543 the uwtable attribute gained a flag so that we can ask for sync uwtables instead of async, as the former are much cheaper. The default is async, so that's what I've done here, but I left a TODO that we might be able to do better. While in here I went ahead and dropped support for removing uwtable attributes in rustc: we never did it, so I didn't write the extra C++ bridge code to make it work. Maybe I should have done the same thing with the `sync|async` parameter but we'll see.
2022-02-15Overhaul `TyS` and `Ty`.Nicholas Nethercote-10/+10
Specifically, change `Ty` from this: ``` pub type Ty<'tcx> = &'tcx TyS<'tcx>; ``` to this ``` pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>); ``` There are two benefits to this. - It's now a first class type, so we can define methods on it. This means we can move a lot of methods away from `TyS`, leaving `TyS` as a barely-used type, which is appropriate given that it's not meant to be used directly. - The uniqueness requirement is now explicit, via the `Interned` type. E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather than via `TyS`, which wasn't obvious at all. Much of this commit is boring churn. The interesting changes are in these files: - compiler/rustc_middle/src/arena.rs - compiler/rustc_middle/src/mir/visit.rs - compiler/rustc_middle/src/ty/context.rs - compiler/rustc_middle/src/ty/mod.rs Specifically: - Most mentions of `TyS` are removed. It's very much a dumb struct now; `Ty` has all the smarts. - `TyS` now has `crate` visibility instead of `pub`. - `TyS::make_for_test` is removed in favour of the static `BOOL_TY`, which just works better with the new structure. - The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned` (pointer-based, for the `Equal` case) and partly on `TyS` (contents-based, for the other cases). - There are many tedious sigil adjustments, i.e. adding or removing `*` or `&`. They seem to be unavoidable.
2022-02-14llvm: migrate to new parameter-bearing uwtable attrAugie Fackler-5/+13
In https://reviews.llvm.org/D114543 the uwtable attribute gained a flag so that we can ask for sync uwtables instead of async, as the former are much cheaper. The default is async, so that's what I've done here, but I left a TODO that we might be able to do better. While in here I went ahead and dropped support for removing uwtable attributes in rustc: we never did it, so I didn't write the extra C++ bridge code to make it work. Maybe I should have done the same thing with the `sync|async` parameter but we'll see.
2022-02-14Add support for control-flow protectionAndrew Brown-1/+20
This change adds a flag for configuring control-flow protection in the LLVM backend. In Clang, this flag is exposed as `-fcf-protection` with options `none|branch|return|full`. This convention is followed for `rustc`, though as a codegen option: `rustc -Z cf-protection=<none|branch|return|full>`. Co-authored-by: BlackHoleFox <blackholefoxdev@gmail.com>
2022-02-13Auto merge of #93670 - erikdesjardins:noundef, r=nikicbors-1/+2
Apply noundef attribute to &T, &mut T, Box<T>, bool This doesn't handle `char` because it's a bit awkward to distinguish it from `u32` at this point in codegen. Note that this _does not_ change whether or not it is UB for `&`, `&mut`, or `Box` to point to undef. It only applies to the pointer itself, not the pointed-to memory. Fixes (partially) #74378. r? `@nikic` cc `@RalfJung`
2022-02-11Rollup merge of #93782 - adamgemmell:dev/adagem01/split-pauth, r=AmanieuMatthias Krüger-13/+67
Split `pauth` target feature Per discussion on https://github.com/rust-lang/rust/issues/86941 we'd like to split `pauth` into `paca` and `pacg` in order to better support possible future environments that only have the keys available for address or generic authentication. At the moment LLVM has the one `pauth` target_feature while Linux presents separate `paca` and `pacg` flags for feature detection. Because the use of [target_feature](https://rust-lang.github.io/rfcs/2045-target-feature.html) will "allow the compiler to generate code under the assumption that this code will only be reached in hosts that support the feature", it does not make sense to simply translate `paca` into the LLVM feature `pauth`, as it will generate code as if `pacg` is available. To accommodate this we error if only one of the two features is present. If LLVM splits them in the future we can remove this restriction without making a breaking change. r? ```@Amanieu```
2022-02-10Unconditionally update symbolsbjorn3-10/+1
All paths to an ArchiveBuilder::build call update_symbols first.
2022-02-10Split PAuth target featureAdam Gemmell-13/+67
2022-02-09Rollup merge of #93503 - ↵Matthias Krüger-35/+146
michaelwoerister:fix-vtable-holder-debuginfo-regression, r=wesleywiser debuginfo: Fix DW_AT_containing_type vtable debuginfo regression This PR brings back the `DW_AT_containing_type` attribute for vtables after it has accidentally been removed in #89597. It also implements a more accurate description of vtables. Instead of describing them as an array of void pointers, the compiler will now emit a struct type description with a field for each entry of the vtable. r? ``@wesleywiser`` This PR should fix issue https://github.com/rust-lang/rust/issues/93164. ~~The PR is blocked on https://github.com/rust-lang/rust/pull/93154 because both of them modify the `codegen/debug-vtable.rs` test case.~~
2022-02-08debuginfo: Bring back DW_AT_containing_type for vtables -- address review ↵Michael Woerister-1/+3
comments
2022-02-06apply noundef explicitly in all cases instead of relying on dereferenceable ↵Erik Desjardins-4/+0
implying it
2022-02-06`#[used(linker)]` attribute (https://github.com/dtolnay/linkme/issues/41)cynecx-0/+9
2022-02-05Apply noundef attribute to &T, &mut T, Box<T>, boolErik Desjardins-1/+6
This doesn't handle `char` because it's a bit awkward to distinguish it from u32 at this point in codegen. Note that for some types (like `&Struct` and `&mut Struct`), we already apply `dereferenceable`, which implies `noundef`, so the IR does not change.
2022-02-04Rollup merge of #90132 - joshtriplett:stabilize-instrument-coverage, ↵Matthias Krüger-2/+2
r=wesleywiser Stabilize `-Z instrument-coverage` as `-C instrument-coverage` (Tracking issue for `instrument-coverage`: https://github.com/rust-lang/rust/issues/79121) This PR stabilizes support for instrumentation-based code coverage, previously provided via the `-Z instrument-coverage` option. (Continue supporting `-Z instrument-coverage` for compatibility for now, but show a deprecation warning for it.) Many, many people have tested this support, and there are numerous reports of it working as expected. Move the documentation from the unstable book to stable rustc documentation. Update uses and documentation to use the `-C` option. Addressing questions raised in the tracking issue: > If/when stabilized, will the compiler flag be updated to -C instrument-coverage? (If so, the -Z variant could also be supported for some time, to ease migrations for existing users and scripts.) This stabilization PR updates the option to `-C` and keeps the `-Z` variant to ease migration. > The Rust coverage implementation depends on (and automatically turns on) -Z symbol-mangling-version=v0. Will stabilizing this feature depend on stabilizing v0 symbol-mangling first? If so, what is the current status and timeline? This stabilization PR depends on https://github.com/rust-lang/rust/pull/90128 , which stabilizes `-C symbol-mangling-version=v0` (but does not change the default symbol-mangling-version). > The Rust coverage implementation implements the latest version of LLVM's Coverage Mapping Format (version 4), which forces a dependency on LLVM 11 or later. A compiler error is generated if attempting to compile with coverage, and using an older version of LLVM. Given that LLVM 13 has now been released, requiring LLVM 11 for coverage support seems like a reasonable requirement. If people don't have at least LLVM 11, nothing else breaks; they just can't use coverage support. Given that coverage support currently requires a nightly compiler and LLVM 11 or newer, allowing it on a stable compiler built with LLVM 11 or newer seems like an improvement. The [tracking issue](https://github.com/rust-lang/rust/issues/79121) and the [issue label A-code-coverage](https://github.com/rust-lang/rust/labels/A-code-coverage) link to a few open issues related to `instrument-coverage`, but none of them seem like showstoppers. All of them seem like improvements and refinements we can make after stabilization. The original `-Z instrument-coverage` support went through a compiler-team MCP at https://github.com/rust-lang/compiler-team/issues/278 . Based on that, `@pnkfelix` suggested that this needed a stabilization PR and a compiler-team FCP.
2022-02-04Rollup merge of #93630 - matthiaskrgr:clipperf, r=oli-obkMatthias Krüger-1/+1
clippy::perf fixes single_char_pattern and to_string_in_format_args
2022-02-04Rollup merge of #93402 - ehuss:llvm-dialog, r=michaelwoeristerMatthias Krüger-0/+7
Windows: Disable LLVM crash dialog boxes. This disables the crash dialog box on Windows. When LLVM hits an assertion, it will open a dialog box with Abort/Retry/Ignore. This is annoying on CI because CI will just hang until it times out (which can take hours). Instead of opening a dialog box, it will print a message like this: ``` Assertion failed: isa<X>(Val) && "cast<Ty>() argument of incompatible type!", file D:\Proj\rust\rust\src\llvm-project\llvm\include\llvm/Support/Casting.h, line 255 ``` Closes #92829
2022-02-03compiler: clippy::complexity fixesMatthias Krüger-1/+1
useless_format map_flatten useless_conversion needless_bool filter_next clone_on_copy needless_option_as_deref
2022-02-03clippy::perf fixesMatthias Krüger-1/+1
single_char_pattern and to_string_in_format_args
2022-02-03Only disable dialogs on CI.Eric Huss-1/+6
The "CI" environment var isn't universal (for example, I think Azure uses TF_BUILD). However, we are mostly concerned with rust-lang/rust's own CI which currently is GitHub Actions which does set "CI". And I think most other providers use "CI" as well.
2022-02-03debuginfo: Bring back DW_AT_containing_type for vtables after it has ↵Michael Woerister-11/+90
accidentally been removed in https://github.com/rust-lang/rust/pull/89597. Also describe vtables as structs with a field for each entry.
2022-02-03debuginfo: Make some helper functions in ↵Michael Woerister-24/+54
rustc_codegen_llvm::debuginfo::metadata more generally applicable.
2022-02-02Auto merge of #93154 - ↵bors-17/+20
michaelwoerister:fix-generic-closure-and-generator-debuginfo, r=wesleywiser debuginfo: Make sure that type names for closure and generator environments are unique in debuginfo. Before this change, closure/generator environments coming from different instantiations of the same generic function were all assigned the same name even though they were distinct types with potentially different data layout. Now we append the generic arguments of the originating function to the type name. This commit also emits `{closure_env#0}` as the name of these types in order to disambiguate them from the accompanying closure function (which keeps being called `{closure#0}`). Previously both were assigned the same name. NOTE: Changing debuginfo names like this can break pretty printers and other debugger plugins. I think it's OK in this particular case because the names we are changing were ambiguous anyway. In general though it would be great to have a process for doing changes like these.
2022-02-01debuginfo: Make sure that type names for closure and generator environments ↵Michael Woerister-17/+20
are unique in debuginfo. Before this change, closure/generator environments coming from different instantiations of the same generic function were all assigned the same name even though they were distinct types with potentially different data layout. Now we append the generic arguments of the originating function to the type name. This commit also emits '{closure_env#0}' as the name of these types in order to disambiguate them from the accompanying closure function '{closure#0}'. Previously both were assigned the same name.
2022-02-01add a rustc::query_stability lintlcnr-0/+1
2022-01-28Auto merge of #93427 - matthiaskrgr:rollup-esd3ixl, r=matthiaskrgrbors-39/+39
Rollup of 10 pull requests Successful merges: - #92611 (Add links to the reference and rust by example for asm! docs and lints) - #93158 (wasi: implement `sock_accept` and enable networking) - #93239 (Add os::unix::net::SocketAddr::from_path) - #93261 (Some unwinding related cg_ssa cleanups) - #93295 (Avoid double panics when using `TempDir` in tests) - #93353 (Unimpl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}<$t> for Saturating<$t>) - #93356 (Edit docs introduction for `std::cmp::PartialOrd`) - #93375 (fix typo `documenation`) - #93399 (rustbuild: Fix compiletest warning when building outside of root.) - #93404 (Fix a typo from #92899) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-01-28Rollup merge of #93261 - bjorn3:cg_ssa_refactor6, r=cjgillotMatthias Krüger-39/+39
Some unwinding related cg_ssa cleanups These should make it a bit easier for alternative codegen backends to implement unwinding.
2022-01-28Auto merge of #93006 - michaelwoerister:fix-unsized-ptr-debuginfo, ↵bors-174/+238
r=davidtwco,oli-obk Fix debuginfo for pointers/references to unsized types This PR makes the compiler emit fat pointer debuginfo in all cases. Before, we sometimes got thin-pointer debuginfo, making it impossible to fully interpret the pointed to memory in debuggers. The code is actually cleaner now, especially around generation of trait object pointer debuginfo. Fixes https://github.com/rust-lang/rust/issues/92718 ~~Blocked on https://github.com/rust-lang/rust/pull/92729.~~
2022-01-28[debuginfo] Fix and unify handling of fat pointers in debuginfo: Don't mark ↵Michael Woerister-2/+2
fat pointer fields as artificial. LLDB does not seem to see fields if they are marked with DW_AT_artificial which breaks pretty printers that use these fields for decoding fat pointers.
2022-01-27Windows: Disable LLVM crash dialog boxes.Eric Huss-0/+2
2022-01-27[debuginfo] Fix and unify handling of fat pointers in debuginfo: Change doc ↵Michael Woerister-13/+13
comment so it is not interpreted as doc-test.
2022-01-25Rollup merge of #93269 - jacobbramley:dev/pauth-option-1, r=petrochenkovMatthias Krüger-10/+67
Use error-on-mismatch policy for PAuth module flags. This agrees with Clang, and avoids an error when using LTO with mixed C/Rust. LLVM considers different behaviour flags to be a mismatch, even when the flag value itself is the same. This also makes the flag setting explicit for all uses of LLVMRustAddModuleFlag. ---- I believe that this fixes #92885, but have only reproduced it locally on Linux hosts so cannot confirm that it fixes the issue as reported. I have not included a test for this because it is covered by an existing test (`src/test/run-make-fulldeps/cross-lang-lto-clang`). It is not without its problems, though: * The test requires Clang and `--run-clang-based-tests-with=...` to run, and this is not the case on the CI. * Any test I add would have a similar requirement. * With this patch applied, the test gets further, but it still fails (for other reasons). I don't think that affects #92885.
2022-01-25Rollup merge of #93144 - wesleywiser:uninhabited_type_code_cov2, r=tmandryMatthias Krüger-4/+13
Work around missing code coverage data causing llvm-cov failures If we do not add code coverage instrumentation to the `Body` of a function, then when we go to generate the function record for it, we won't write any data and this later causes llvm-cov to fail when processing data for the entire coverage report. I've identified two main cases where we do not currently add code coverage instrumentation to the `Body` of a function: 1. If the function has a single `BasicBlock` and it ends with a `TerminatorKind::Unreachable`. 2. If the function is created using a proc macro of some kind. For case 1, this is typically not important as this most often occurs as a result of function definitions that take or return uninhabited types. These kinds of functions, by definition, cannot even be called so they logically should not be counted in code coverage statistics. For case 2, I haven't looked into this very much but I've noticed while testing this patch that (other than functions which are covered by case 1) the skipped function coverage debug message is occasionally triggered in large crate graphs by functions generated from a proc macro. This may have something to do with weird spans being generated by the proc macro but this is just a guess. I think it's reasonable to land this change since currently, we fail to generate *any* results from llvm-cov when a function has no coverage instrumentation applied to it. With this change, we get coverage data for all functions other than the two cases discussed above. Fixes #93054 which occurs because of uncallable functions which shouldn't have code coverage anyway. I will open an issue for missing code coverage of proc macro generated functions and leave a link here once I have a more minimal repro. r? ``@tmandry`` cc ``@richkadel``
2022-01-24Use error-on-mismatch policy for PAuth module flags.Jacob Bramley-10/+67
This agrees with Clang, and avoids an error when using LTO with mixed C/Rust. LLVM considers different behaviour flags to be a mismatch, even when the flag value itself is the same. This also makes the flag setting explicit for all uses of LLVMRustAddModuleFlag.
2022-01-24Merge landing_pad and set_cleanup into cleanup_landing_padbjorn3-16/+18
2022-01-24Merge add_handler into catch_switchbjorn3-11/+10
Some codegen backends may require all handlers to be immediately known
2022-01-24Remove unused return values from resume and cleanup_retbjorn3-10/+9
Given that these instructions are diverging, not every codegen backend may be able to produce a return value for them.
2022-01-24Reorder unwinding related builder methods to differentiate between dwarf and ↵bjorn3-6/+6
msvc instructions
2022-01-24[debuginfo] Fix and unify handling of fat pointers in debuginfo: address ↵Michael Woerister-20/+19
review comments.
2022-01-24[debuginfo] Fix and unify handling of fat pointers in debuginfo.Michael Woerister-174/+239
2022-01-22Add preliminary support for inline assembly for msp430.William D. Jones-0/+6
2022-01-21Rollup merge of #93046 - est31:let_else, r=davidtwcoMatthias Krüger-1/+2
Use let_else in even more places Followup of #89933, #91018, #91481.
2022-01-21Work around missing code coverage data causing llvm-cov failuresWesley Wiser-4/+13
If we do not add code coverage instrumentation to the `Body` of a function, then when we go to generate the function record for it, we won't write any data and this later causes llvm-cov to fail when processing data for the entire coverage report. I've identified two main cases where we do not currently add code coverage instrumentation to the `Body` of a function: 1. If the function has a single `BasicBlock` and it ends with a `TerminatorKind::Unreachable`. 2. If the function is created using a proc macro of some kind. For case 1, this typically not important as this most often occurs as the result of function definitions that take or return uninhabited types. These kinds of functions, by definition, cannot even be called so they logically should not be counted in code coverage statistics. For case 2, I haven't looked into this very much but I've noticed while testing this patch that (other than functions which are covered by case 1) the skipped function coverage debug message is occasionally triggered in large crate graphs by functions generated from a proc macro. This may have something to do with weird spans being generated by the proc macro but this is just a guess. I think it's reasonable to land this change since currently, we fail to generate *any* results from llvm-cov when a function has no coverage instrumentation applied to it. With this change, we get coverage data for all functions other than the two cases discussed above.
2022-01-18Rollup merge of #92425 - calebzulawski:simd-cast, r=workingjubileeMatthias Krüger-27/+62
Improve SIMD casts * Allows `simd_cast` intrinsic to take `usize` and `isize` * Adds `simd_as` intrinsic, which is the same as `simd_cast` except for saturating float-to-int conversions (matching the behavior of `as`). cc `@workingjubilee`
2022-01-18Rollup merge of #90782 - ricobbe:binutils-dlltool, r=michaelwoeristerMatthias Krüger-46/+159
Implement raw-dylib support for windows-gnu Add support for `#[link(kind = "raw-dylib")]` on windows-gnu targets. Work around binutils's linker's inability to read import libraries produced by LLVM by calling out to the binutils `dlltool` utility to create an import library from a temporary .DEF file; this approach is effectively a slightly refined version of `@mati865's` earlier attempt at this strategy in PR #88801. (In particular, this attempt at this strategy adds support for `#[link_ordinal(...)]` as well.) In support of #58713.
2022-01-18Use let_else in even more placesest31-1/+2
2022-01-18Auto merge of #92731 - bjorn3:asm_support_changes, r=nagisabors-4/+3
Avoid unnecessary monomorphization of inline asm related functions This should reduce build time for codegen backends by avoiding duplicated monomorphization of certain inline asm related functions for each passed in closure type.