about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
AgeCommit message (Collapse)AuthorLines
2024-06-04Rollup merge of #125750 - compiler-errors:expect, r=lcnr许杰友 Jieyou Xu (Joe)-1/+1
Align `Term` methods with `GenericArg` methods, add `Term::expect_*` * `Term::ty` -> `Term::as_type`. * `Term::ct` -> `Term::as_const`. * Adds `Term::expect_type` and `Term::expect_const`, and uses them in favor of `.ty().unwrap()`, etc. I could also shorten these to `as_ty` and then do `GenericArg::as_ty` as well, but I do think the `as_` is important to signal that this is a conversion method, and not a getter, like `Const::ty` is. r? types
2024-06-03Align Term methods with GenericArg methodsMichael Goulet-1/+1
2024-06-04Auto merge of #122597 - pacak:master, r=bjorn3bors-0/+41
Show files produced by `--emit foo` in json artifact notifications Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`. Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477 Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: https://github.com/hintron/computer-enhance/issues/35 This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files. Most users won't notice this behavior, to be affected by it all of the following must hold: - user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything) - user must specify both `--emit xxx` and `--json artifacts` - user must refuse to handle unknown artifact types - user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit #88829 / #89149
2024-05-29Rollup merge of #124251 - scottmcm:unop-ptr-metadata, r=oli-obk许杰友 Jieyou Xu (Joe)-8/+36
Add an intrinsic for `ptr::metadata` The follow-up to #123840, so we can remove `PtrComponents` and `PtrRepr` from libcore entirely (well, after a bootstrap update). As discussed in <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/.60ptr_metadata.60.20in.20MIR/near/435637808>, this introduces `UnOp::PtrMetadata` taking a raw pointer and returning the associated metadata value. By no longer going through a `union`, this should also help future PRs better optimize pointer operations. r? ``@oli-obk``
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-8/+36
2024-05-27Omit non-needs_drop drop_in_place in vtablesMark Rousskov-90/+137
This replaces the drop_in_place reference with null in vtables. On librustc_driver.so, this drops about ~17k dynamic relocations from the output, since many vtables can now be placed in read-only memory, rather than having a relocated pointer included. This makes a tradeoff by adding a null check at vtable call sites. That's hard to avoid without changing the vtable format (e.g., to use a pc-relative relocation instead of an absolute address, and avoid the dynamic relocation that way). But it seems likely that the check is cheap at runtime.
2024-05-27Rollup merge of #125148 - RalfJung:codegen-sh, r=scottmcmGuillaume Gomez-4/+13
codegen: tweak/extend shift comments r? `@scottmcm`
2024-05-27Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercotebors-1/+1
[perf] Delay the construction of early lint diag structs Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666. See individual commits for details. The first three commits are not strictly necessary. However, the 2nd one (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement. It's also pretty sweet on its own if I may say so myself.
2024-05-26Rollup merge of #125046 - bjorn3:no_mutable_static_linkage, r=cjgillotJubilee-0/+12
Only allow immutable statics with #[linkage]
2024-05-24Rollup merge of #125477 - nnethercote:missed-rustfmt, r=compiler-errorsMatthias Krüger-1/+1
Run rustfmt on files that need it. Somehow these files aren't properly formatted. By default `x fmt` and `x tidy` only check files that have changed against master, so if an ill-formatted file somehow slips in it can stay that way as long as it doesn't get modified(?) I found these when I ran `x fmt` explicitly on every `.rs` file in the repo, while working on https://github.com/rust-lang/compiler-team/issues/750.
2024-05-24Run rustfmt on files that need it.Nicholas Nethercote-1/+1
Somehow these files aren't properly formatted. By default `x fmt` and `x tidy` only check files that have changed against master, so if an ill-formatted file somehow slips in it can stay that way as long as it doesn't get modified(?) I found these when I ran `x fmt` explicitly on every `.rs` file in the repo, while working on https://github.com/rust-lang/compiler-team/issues/750.
2024-05-24Auto merge of #125463 - GuillaumeGomez:rollup-287wx4y, r=GuillaumeGomezbors-3/+28
Rollup of 6 pull requests Successful merges: - #125263 (rust-lld: fallback to rustc's sysroot if there's no path to the linker in the target sysroot) - #125345 (rustc_codegen_llvm: add support for writing summary bitcode) - #125362 (Actually use TAIT instead of emulating it) - #125412 (Don't suggest adding the unexpected cfgs to the build-script it-self) - #125445 (Migrate `run-make/rustdoc-with-short-out-dir-option` to `rmake.rs`) - #125452 (Cleanup check-cfg handling in core and std) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-23Rollup merge of #125345 - durin42:thin-link-bitcode, r=bjorn3Guillaume Gomez-2/+15
rustc_codegen_llvm: add support for writing summary bitcode Typical uses of ThinLTO don't have any use for this as a standalone file, but distributed ThinLTO uses this to make the linker phase more efficient. With clang you'd do something like `clang -flto=thin -fthin-link-bitcode=foo.indexing.o -c foo.c` and then get both foo.o (full of bitcode) and foo.indexing.o (just the summary or index part of the bitcode). That's then usable by a two-stage linking process that's more friendly to distributed build systems like bazel, which is why I'm working on this area. I talked some to `@teresajohnson` about naming in this area, as things seem to be a little confused between various blog posts and build systems. "bitcode index" and "bitcode summary" tend to be a little too ambiguous, and she tends to use "thin link bitcode" and "minimized bitcode" (which matches the descriptions in LLVM). Since the clang option is thin-link-bitcode, I went with that to try and not add a new spelling in the world. Per `@dtolnay,` you can work around the lack of this by using `lld --thinlto-index-only` to do the indexing on regular .o files of bitcode, but that is a bit wasteful on actions when we already have all the information in rustc and could just write out the matching minimized bitcode. I didn't test that at all in our infrastructure, because by the time I learned that I already had this patch largely written.
2024-05-23Rollup merge of #125263 - lqd:lld-fallback, r=petrochenkovGuillaume Gomez-1/+13
rust-lld: fallback to rustc's sysroot if there's no path to the linker in the target sysroot As seen in #125246, some sysroots don't expect to contain `rust-lld` and want to keep it that way, so we fallback to the default rustc sysroot if there is no path to the linker in any of the sysroot tools search paths. This is how we locate codegen-backends' dylibs already. People also have requested an error if none of these search paths contain the self-contained linker directory, so there's also an error in that case. r? `@petrochenkov` cc `@ehuss` `@RalfJung` I'm not sure where we check for `rust-lld`'s existence on the targets where we use it by default, and if we just ignore it when missing or emit a warning (as I assume we don't emit an error), so I just checked for the existence of `gcc-ld`, where `cc` will look for the lld-wrapper binaries. <sub>*Feel free to point out better ways to do this, it's the middle of the night here.*</sub> Fixes #125246
2024-05-23Auto merge of #125434 - nnethercote:rm-more-extern-tracing, r=jackh726bors-8/+24
Remove more `#[macro_use] extern crate tracing` Because explicit importing of macros via use items is nicer (more standard and readable) than implicit importing via `#[macro_use]`. Continuing the work from #124511 and #124914. r? `@jackh726`
2024-05-23cleanup: run rustfmtAugie Fackler-1/+4
2024-05-23cleanup: standardize on summary over index in namesAugie Fackler-3/+3
I did this in the user-facing logic, but I noticed while fixing a minor defect that I had missed it in a few places in the internal details.
2024-05-23thinlto: only build summary file if neededAugie Fackler-2/+2
If we don't do this, some versions of LLVM (at least 17, experimentally) will double-emit some error messages, which is how I noticed this. Given that it seems to be costing some extra work, let's only request the summary bitcode production if we'll actually bother writing it down, otherwise skip it.
2024-05-23emit an error if we can't find a path to the self-contained linkerRémy Rakic-3/+7
2024-05-23rust-lld: fallback to the default default sysroot where rustc is currently ↵Rémy Rakic-1/+9
located
2024-05-23Rollup merge of #125438 - tbu-:pr_rm_to_string_lossy, r=jieyouxuMatthias Krüger-4/+4
Remove unneeded string conversion
2024-05-23Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obkMatthias Krüger-3/+3
rustc: Use `tcx.used_crates(())` more And explain when it should be used. Addresses comments from https://github.com/rust-lang/rust/pull/121167.
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_codegen_ssa`.Nicholas Nethercote-8/+24
2024-05-23Remove unneeded string conversionTobias Bucher-4/+4
2024-05-23Rollup merge of #125417 - lqd:lld-retry, r=petrochenkovMatthias Krüger-0/+21
self-contained linker: retry linking without `-fuse-ld=lld` on CCs that don't support it For the self-contained linker, this PR applies [the strategy](https://github.com/rust-lang/rust/issues/125330#issuecomment-2125119838) of retrying the linking step when the driver doesn't support `-fuse-ld=lld`, but with the option removed. This is the same strategy we already use of retrying when e.g. `-no-pie` is not supported. Fixes #125330 r? `@petrochenkov` I have no idea how we could add a test here, much like we don't have one for `-no-pie` or `-static-pie` -- let me know if you have ideas -- but I tested on a CentOS7 image: ```console [root@d25b38376ede tmp]# ../build/host/stage1/bin/rustc helloworld.rs WARN rustc_codegen_ssa::back::link The linker driver does not support `-fuse-ld=lld`. Retrying without it. [root@d25b38376ede tmp]# readelf -p .comment helloworld String dump of section '.comment': [ 0] GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-44) [ 2d] rustc version 1.80.0-dev ``` I wasn't able to test with `cross` as the issue describes: I wasn't able to reproduce that behavior locally.
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-1/+1
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
2024-05-22Rollup merge of #125399 - scottmcm:less-hir-in-cg_ssa, r=compiler-errorsLeón Orell Valerian Liehr-23/+22
Stop using `to_hir_binop` in codegen This came up in https://github.com/rust-lang/rust/pull/125359#discussion_r1609401311 , and looking into it we can just use the `mir::BinOp`s directly instead of `hir::BinOpKind`s. (AKA rather than going `mir::BinOp` → `hir::BinOpKind` → `IntPredicate`, just go `mir::BinOp` → `IntPredicate`.)
2024-05-22rustc_codegen_llvm: add support for writing summary bitcodeAugie Fackler-0/+10
Typical uses of ThinLTO don't have any use for this as a standalone file, but distributed ThinLTO uses this to make the linker phase more efficient. With clang you'd do something like `clang -flto=thin -fthin-link-bitcode=foo.indexing.o -c foo.c` and then get both foo.o (full of bitcode) and foo.indexing.o (just the summary or index part of the bitcode). That's then usable by a two-stage linking process that's more friendly to distributed build systems like bazel, which is why I'm working on this area. I talked some to @teresajohnson about naming in this area, as things seem to be a little confused between various blog posts and build systems. "bitcode index" and "bitcode summary" tend to be a little too ambiguous, and she tends to use "thin link bitcode" and "minimized bitcode" (which matches the descriptions in LLVM). Since the clang option is thin-link-bitcode, I went with that to try and not add a new spelling in the world. Per @dtolnay, you can work around the lack of this by using `lld --thinlto-index-only` to do the indexing on regular .o files of bitcode, but that is a bit wasteful on actions when we already have all the information in rustc and could just write out the matching minimized bitcode. I didn't test that at all in our infrastructure, because by the time I learned that I already had this patch largely written.
2024-05-22self-contained linker: retry without -fuse-ld=lld on older GCCsRémy Rakic-0/+21
2024-05-22rustc: Use `tcx.used_crates(())` moreVadim Petrochenkov-3/+3
And explain when it should be used.
2024-05-22Stop using `to_hir_binop` in codegenScott McMurray-23/+22
2024-05-21PR feedbackBen Kimock-1/+1
2024-05-21Add a footer in FileEncoder and check for it in MemDecoderBen Kimock-1/+4
2024-05-21Auto merge of #124676 - djkoloski:relax_multiple_sanitizers, r=cuviper,rcvallebors-1/+4
Relax restrictions on multiple sanitizers Most combinations of LLVM sanitizers are legal-enough to enable simultaneously. This change will allow simultaneously enabling ASAN and shadow call stacks on supported platforms. I used this python script to generate the mutually-exclusive sanitizer combinations: ```python #!/usr/bin/python3 import subprocess flags = [ ["-fsanitize=address"], ["-fsanitize=leak"], ["-fsanitize=memory"], ["-fsanitize=thread"], ["-fsanitize=hwaddress"], ["-fsanitize=cfi", "-flto", "-fvisibility=hidden"], ["-fsanitize=memtag", "--target=aarch64-linux-android", "-march=armv8a+memtag"], ["-fsanitize=shadow-call-stack"], ["-fsanitize=kcfi", "-flto", "-fvisibility=hidden"], ["-fsanitize=kernel-address"], ["-fsanitize=safe-stack"], ["-fsanitize=dataflow"], ] for i in range(len(flags)): for j in range(i): command = ["clang++"] + flags[i] + flags[j] + ["-o", "main.o", "-c", "main.cpp"] completed = subprocess.run(command, stderr=subprocess.DEVNULL) if completed.returncode != 0: first = flags[i][0][11:].replace('-', '').upper() second = flags[j][0][11:].replace('-', '').upper() print(f"(SanitizerSet::{first}, SanitizerSet::{second}),") ```
2024-05-20Rollup merge of #125173 - scottmcm:never-checked, r=davidtwcoMatthias Krüger-15/+21
Remove `Rvalue::CheckedBinaryOp` Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/intrinsics.20vs.20binop.2Funop/near/438729996> cc `@RalfJung` While it's a draft, r? ghost
2024-05-18Auto merge of #125077 - spastorino:add-new-fnsafety-enum2, r=jackh726bors-2/+2
Rename Unsafe to Safety Alternative to #124455, which is to just have one Safety enum to use everywhere, this opens the posibility of adding `ast::Safety::Safe` that's useful for unsafe extern blocks. This leaves us today with: ```rust enum ast::Safety { Unsafe(Span), Default, // Safe (going to be added for unsafe extern blocks) } enum hir::Safety { Unsafe, Safe, } ``` We would convert from `ast::Safety::Default` into the right Safety level according the context.
2024-05-18Rollup merge of #125184 - scottmcm:fix-thin-ptr-ice, r=jieyouxuMatthias Krüger-1/+5
Fix ICE in non-operand `aggregate_raw_ptr` intrinsic codegen Introduced in #123840 Found in #121571, cc `@clarfonthey`
2024-05-17Remove `Rvalue::CheckedBinaryOp`Scott McMurray-15/+21
2024-05-17Rename Unsafe to SafetySantiago Pastorino-2/+2
2024-05-16Fix ICE in non-operand `aggregate_raw_ptr` instrinsic codegenScott McMurray-1/+5
2024-05-16Fix assertion when attempting to convert `f16` and `f128` with `as`Trevor Gross-1/+4
These types are currently rejected for `as` casts by the compiler. Remove this incorrect check and add codegen tests for all conversions involving these types.
2024-05-15Don't link lsan rt if asan or hwasan are enabledDavid Koloski-1/+4
2024-05-15codegen: tweak/extend shift commentsRalf Jung-4/+13
2024-05-13Only allow immutable statics with #[linkage]bjorn3-0/+12
2024-05-11Make `index_by_increasing_offset` return one item for primitivesScott McMurray-11/+2
2024-05-11Unify `Rvalue::Aggregate` paths in cg_ssaScott McMurray-21/+29
2024-05-10Refactoring after the `PlaceValue` additionScott McMurray-127/+152
I added `PlaceValue` in 123775, but kept that one line-by-line simple because it touched so many places. This goes through to add more helpers & docs, and change some `PlaceRef` to `PlaceValue` where the type didn't need to be included. No behaviour changes.
2024-05-10Auto merge of #123886 - scottmcm:more-rvalue-operands, r=matthewjasperbors-13/+103
Avoid `alloca`s in codegen for simple `mir::Aggregate` statements The core idea here is to remove the abstraction penalty of simple newtypes in codegen. Even something simple like constructing a ```rust #[repr(transparent)] struct Foo(u32); ``` forces an `alloca` to be generated in nightly right now. Certainly LLVM can optimize that away, but it would be nice if it didn't have to. Quick example: ```rust #[repr(transparent)] pub struct Transparent32(u32); #[no_mangle] pub fn make_transparent(x: u32) -> Transparent32 { let a = Transparent32(x); a } ``` on nightly we produce <https://rust.godbolt.org/z/zcvoM79ae> ```llvm define noundef i32 `@make_transparent(i32` noundef %x) unnamed_addr #0 { %a = alloca i32, align 4 store i32 %x, ptr %a, align 4 %0 = load i32, ptr %a, align 4, !noundef !3 ret i32 %0 } ``` but after this PR we produce ```llvm define noundef i32 `@make_transparent(i32` noundef %x) unnamed_addr #0 { start: ret i32 %x } ``` (even before the optimizer runs).
2024-05-10Rollup merge of #124957 - compiler-errors:builtin-deref, r=michaelwoeristerMatthias Krüger-8/+5
Make `Ty::builtin_deref` just return a `Ty` Nowhere in the compiler are we using the mutability part of the `TyAndMut` that we used to return.
2024-05-10Rollup merge of #124797 - beetrees:primitive-float, r=davidtwcoMatthias Krüger-6/+14
Refactor float `Primitive`s to a separate `Float` type Now there are 4 of them, it makes sense to refactor `F16`, `F32`, `F64` and `F128` out of `Primitive` and into a separate `Float` type (like integers already are). This allows patterns like `F16 | F32 | F64 | F128` to be simplified into `Float(_)`, and is consistent with `ty::FloatTy`. As a side effect, this PR also makes the `Ty::primitive_size` method work with `f16` and `f128`. Tracking issue: #116909 `@rustbot` label +F-f16_and_f128