about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
AgeCommit message (Collapse)AuthorLines
2023-04-02Use `&IndexSlice` instead of `&IndexVec` where possibleScott McMurray-5/+8
All the same reasons as for `[T]`: more general, less pointer chasing, and `&mut IndexSlice` emphasizes that it doesn't change *length*.
2023-04-01Use `FieldIdx` in various things related to aggregatesScott McMurray-6/+6
Shrank `AggregateKind` by 8 bytes on x64, since the active field of a union is tracked as an `Option<FieldIdx>` instead of `Option<usize>`.
2023-03-31Auto merge of #98112 - saethlin:mir-alignment-checks, r=oli-obkbors-0/+7
Insert alignment checks for pointer dereferences when debug assertions are enabled Closes https://github.com/rust-lang/rust/issues/54915 - [x] Jake tells me this sounds like a place to use `MirPatch`, but I can't figure out how to insert a new basic block with a new terminator in the middle of an existing basic block, using `MirPatch`. (if nobody else backs up this point I'm checking this as "not actually a good idea" because the code looks pretty clean to me after rearranging it a bit) - [x] Using `CastKind::PointerExposeAddress` is definitely wrong, we don't want to expose. Calling a function to get the pointer address seems quite excessive. ~I'll see if I can add a new `CastKind`.~ `CastKind::Transmute` to the rescue! - [x] Implement a more helpful panic message like slice bounds checking. r? `@oli-obk`
2023-03-30Rollup merge of #109347 - cjgillot:issue-109305, r=WaffleLapkinMichael Goulet-69/+46
Skip no_mangle if the item has no name. Fixes https://github.com/rust-lang/rust/issues/109305
2023-03-30Auto merge of #105587 - tgross35:once-cell-min, r=m-ou-sebors-1/+0
Partial stabilization of `once_cell` This PR aims to stabilize a portion of the `once_cell` feature: - `core::cell::OnceCell` - `std::cell::OnceCell` (re-export of the above) - `std::sync::OnceLock` This will leave `LazyCell` and `LazyLock` unstabilized, which have been moved to the `lazy_cell` feature flag. Tracking issue: https://github.com/rust-lang/rust/issues/74465 (does not fully close, but it may make sense to move to a new issue) Future steps for separate PRs: - ~~Add `#[inline]` to many methods~~ #105651 - Update cranelift usage of the `once_cell` crate - Update rust-analyzer usage of the `once_cell` crate - Update error messages discussing once_cell ## To be stabilized API summary ```rust // core::cell (in core/cell/once.rs) pub struct OnceCell<T> { .. } impl<T> OnceCell<T> { pub const fn new() -> OnceCell<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceCell<T>; impl<T: Debug> Debug for OnceCell<T> impl<T> Default for OnceCell<T>; impl<T> From<T> for OnceCell<T>; impl<T: PartialEq> PartialEq for OnceCell<T>; impl<T: Eq> Eq for OnceCell<T>; ``` ```rust // std::sync (in std/sync/once_lock.rs) impl<T> OnceLock<T> { pub const fn new() -> OnceLock<T>; pub fn get(&self) -> Option<&T>; pub fn get_mut(&mut self) -> Option<&mut T>; pub fn set(&self, value: T) -> Result<(), T>; pub fn get_or_init<F>(&self, f: F) -> &T where F: FnOnce() -> T; pub fn into_inner(self) -> Option<T>; pub fn take(&mut self) -> Option<T>; } impl<T: Clone> Clone for OnceLock<T>; impl<T: Debug> Debug for OnceLock<T>; impl<T> Default for OnceLock<T>; impl<#[may_dangle] T> Drop for OnceLock<T>; impl<T> From<T> for OnceLock<T>; impl<T: PartialEq> PartialEq for OnceLock<T> impl<T: Eq> Eq for OnceLock<T>; impl<T: RefUnwindSafe + UnwindSafe> RefUnwindSafe for OnceLock<T>; unsafe impl<T: Send> Send for OnceLock<T>; unsafe impl<T: Sync + Send> Sync for OnceLock<T>; impl<T: UnwindSafe> UnwindSafe for OnceLock<T>; ``` No longer planned as part of this PR, and moved to the `rust_cell_try` feature gate: ```rust impl<T> OnceCell<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } impl<T> OnceLock<T> { pub fn get_or_try_init<F, E>(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result<T, E>; } ``` I am new to this process so would appreciate mentorship wherever needed.
2023-03-29Stabilize a portion of 'once_cell'Trevor Gross-1/+0
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
2023-03-29Rollup merge of #109716 - scottmcm:field-to-fieldidx, r=oli-obkMatthias Krüger-4/+4
Move `mir::Field` → `abi::FieldIdx` The first PR for https://github.com/rust-lang/compiler-team/issues/606 This is just the move-and-rename, because it's plenty big already. Future PRs will start using `FieldIdx` more broadly, and concomitantly removing `FieldIdx::new`s.
2023-03-29Auto merge of #108089 - Zoxc:windows-tls, r=bjorn3bors-8/+49
Support TLS access into dylibs on Windows This allows access to `#[thread_local]` in upstream dylibs on Windows by introducing a MIR shim to return the address of the thread local. Accesses that go into an upstream dylib will call the MIR shim to get the address of it. `convert_tls_rvalues` is introduced in `rustc_codegen_ssa` which rewrites MIR TLS accesses to dummy calls which are replaced with calls to the MIR shims when the dummy calls are lowered to backend calls. A new `dll_tls_export` target option enables this behavior with a `false` value which is set for Windows platforms. This fixes https://github.com/rust-lang/rust/issues/84933.
2023-03-29Support TLS access into dylibs on WindowsJohn Kåre Alsaker-8/+49
2023-03-28Move `mir::Field` → `abi::FieldIdx`Scott McMurray-4/+4
The first PR for https://github.com/rust-lang/compiler-team/issues/606 This is just the move-and-rename, because it's plenty big-and-bitrotty already. Future PRs will start using `FieldIdx` more broadly, and concomitantly removing `FieldIdx::new`s.
2023-03-28Skip no_mangle if the item has no name.Camille GILLOT-1/+16
2023-03-28Reformat codegen_fn_attrs.Camille GILLOT-71/+33
2023-03-28[fix] don't panic on failure to acquire jobserver tokenDaniil Belov-2/+2
2023-03-27Bless tidyMaybe Waffle-1/+1
2023-03-27Rollup merge of #109582 - scottmcm:local-ref-pending, r=oli-obkMatthias Krüger-20/+26
Refactor: Separate `LocalRef` variant for not-evaluated-yet operands As I was reading through this, I noticed that almost every place that was using this needed to distinguish between Some vs None in the match arm anyway, so thought that separating the cases at the variant level might be clearer instead. I like how it ended up; let me know what you think!
2023-03-27Auto merge of #109091 - Nilstrieb:match-on-attr, r=cjgillotbors-293/+326
Cleanup `codegen_fn_attrs` The `match` control flow construct has been stable since 1.0, we should use it here. Sorry for the hard to review diff, I did try to at least split it into two commits. But looking at before-after side-by-side (instead of whatever github is doing) is probably the easiest way to make sure that I didn't forget about anything. On top of #109088, you can wait for that
2023-03-25Refactor: `VariantIdx::from_u32(0)` -> `FIRST_VARIANT`Scott McMurray-5/+4
Since structs are always `VariantIdx(0)`, there's a bunch of files where the only reason they had `VariantIdx` or `vec::Idx` imported at all was to get the first variant. So this uses a constant for that, and adds some doc-comments to `VariantIdx` while I'm there, since it doesn't have any today.
2023-03-24Refactor: Separate `LocalRef` variant for not-evaluated-yet operandsScott McMurray-20/+26
2023-03-24Auto merge of #109220 - nikic:poison, r=cuviperbors-4/+5
Use poison instead of undef In cases where it is legal, we should prefer poison values over undef values. This replaces undef with poison for aggregate construction and for uninhabited types. There are more places where we can likely use poison, but I wanted to stay conservative to start with. In particular the aggregate case is important for newer LLVM versions, which are not able to handle an undef base value during early optimization due to poison-propagation concerns. r? `@cuviper`
2023-03-24Rollup merge of #109515 - bzEq:aix-linker, r=petrochenkovMatthias Krüger-0/+174
Add AixLinker to support linking on AIX AIX linker has a different cli style from other existing linkers. It is documented in https://www.ibm.com/docs/en/aix/7.1?topic=l-ld-command.
2023-03-23A MIR transform that checks pointers are alignedBen Kimock-0/+7
2023-03-23Auto merge of #109538 - matthiaskrgr:rollup-ct58npj, r=matthiaskrgrbors-0/+1
Rollup of 8 pull requests Successful merges: - #106964 (Clarify `Error::last_os_error` can be weird) - #107718 (Add `-Z time-passes-format` to allow specifying a JSON output for `-Z time-passes`) - #107880 (Lint ambiguous glob re-exports) - #108549 (Remove issue number for `link_cfg`) - #108588 (Fix the ffi_unwind_calls lint documentation) - #109231 (Add `try_canonicalize` to `rustc_fs_util` and use it over `fs::canonicalize`) - #109472 (Add parentheses properly for method calls) - #109487 (Move useless_anynous_reexport lint into unused_imports) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-23Rollup merge of #107718 - Zoxc:z-time, r=nnethercoteMatthias Krüger-0/+1
Add `-Z time-passes-format` to allow specifying a JSON output for `-Z time-passes` This adds back the `-Z time` option as that is useful for [my rustc benchmark tool](https://github.com/Zoxc/rcb), reverting https://github.com/rust-lang/rust/pull/102725. It now uses nanoseconds and bytes as the units so it is renamed to `time-precise`.
2023-03-23Auto merge of #108442 - scottmcm:mir-transmute, r=oli-obkbors-85/+60
Add `CastKind::Transmute` to MIR ~~Nothing actually produces it in this commit, so I don't know how to test it, but it also means it shouldn't be possible for it to break anything.~~ Includes lowering `transmute` calls to it, so it's used. Zulip Conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Good.20first.20isssue/near/321849610>
2023-03-23Adjust debug info strippingKai Luo-2/+3
2023-03-23Fix copy-paste errorKai Luo-1/+1
2023-03-23Add AixLinker to support linking on AIXKai Luo-0/+173
2023-03-22Add `CastKind::Transmute` to MIRScott McMurray-85/+60
Updates `interpret`, `codegen_ssa`, and `codegen_cranelift` to consume the new cast instead of the intrinsic. Includes `CastTransmute` for custom MIR building, to be able to test the extra UB.
2023-03-22Rollup merge of #109378 - MU001999:master, r=scottmcmMatthias Krüger-2/+2
Remove Ty::is_region_ptr Fixes #109372
2023-03-22rustc: Remove unused `Session` argument from some attribute functionsVadim Petrochenkov-3/+4
2023-03-21Remove `unique` and move `VerboseTimingGuard` fields into a new structJohn Kåre Alsaker-1/+0
2023-03-21Add `-Z time-passes-format` to allow specifying a JSON output for `-Z ↵John Kåre Alsaker-0/+2
time-passes`
2023-03-21LocalCrate keyMichael Goulet-2/+3
2023-03-21Use local key in providersMichael Goulet-10/+5
2023-03-20Rollup merge of #109307 - cjgillot:inline-location, r=compiler-errorsMatthias Krüger-1/+5
Ignore `Inlined` spans when computing caller location. Fixes https://github.com/rust-lang/rust/issues/105538
2023-03-20Remove Ty::is_region_ptrMu42-2/+2
2023-03-19Rollup merge of #109243 - chenyukang:yukang/fix-ice-109144, r=petrochenkovDylan DPC-12/+11
The name of NativeLib will be presented Fixes #109144 I was working on a quick fix, but found change the name from `Option<Symbol>` to `Symbol` make life a little bit easier.
2023-03-19The name of NativeLib will be presentedyukang-12/+11
2023-03-18Ignore `Inlined` spans when computing caller location.Camille GILLOT-1/+5
2023-03-18Rollup merge of #109287 - scottmcm:hash-slice-size-of-val, r=oli-obkMatthias Krüger-1/+1
Use `size_of_val` instead of manual calculation Very minor thing that I happened to notice in passing, but it's both shorter and [means it gets `mul nsw`](https://rust.godbolt.org/z/Y9KxYETv5), so why not.
2023-03-18Rollup merge of #109234 - tmiasko:overflow-checks, r=cjgillotMatthias Krüger-9/+2
Tweak implementation of overflow checking assertions Extract and reuse logic controlling behaviour of overflow checking assertions instead of duplicating it three times. r? `@cjgillot`
2023-03-17Use `size_of_val` instead of manual calculationScott McMurray-1/+1
Very minor thing that I happened to notice in passing, but it's both shorter and means it gets `mul nuw`, so why not.
2023-03-17Rollup merge of #109156 - taiki-e:linker-detection, r=petrochenkovMatthias Krüger-1/+3
Fix linker detection for clang with prefix https://github.com/rust-lang/rust/pull/106489 removed check for clang with prefix. It says: > Also remove the check for -clang, since there are no architecture specific variants of clang (to my knowledge). However, when doing cross-compilation, a wrapper script for clang with the target name as a prefix is sometimes used. https://github.com/rust-lang/rust/blob/1716932743a7b3705cbf0c34db0c4e070ed1930d/src/ci/docker/host-x86_64/dist-various-2/Dockerfile#L62 https://github.com/rust-lang/rust/blob/1716932743a7b3705cbf0c34db0c4e070ed1930d/src/ci/docker/scripts/freebsd-toolchain.sh#L76-L80 https://github.com/rust-lang/rust/blob/1716932743a7b3705cbf0c34db0c4e070ed1930d/src/ci/docker/host-x86_64/dist-various-2/Dockerfile#L40 https://github.com/rust-lang/rust/blob/1716932743a7b3705cbf0c34db0c4e070ed1930d/compiler/rustc_target/src/spec/aarch64_pc_windows_gnullvm.rs#L7 It seems the regression did not occur on the targets mentioned above because the default linker flavor is gcc, but it did occur on targets where the default linker flavor is not gcc (https://github.com/taiki-e/setup-cross-toolchain-action/commit/fd352f3ffabd00daf2759ab4a3276729e52eeb10). r? ````@petrochenkov````
2023-03-16Tweak implementation of overflow checking assertionsTomasz Miąsko-9/+2
Extract and reuse logic controlling behaviour of overflow checking assertions instead of duplicating it three times.
2023-03-16Auto merge of #108944 - cjgillot:clear-local-info, r=oli-obkbors-7/+2
Wrap the whole LocalInfo in ClearCrossCrate. MIR contains a lot of information about locals. The primary purpose of this information is the quality of borrowck diagnostics. This PR aims to drop this information after MIR analyses are finished, ie. starting from post-cleanup runtime MIR.
2023-03-16Use poison instead of undefNikita Popov-4/+5
In cases where it is legal, we should prefer poison values over undef values. This replaces undef with poison for aggregate construction and for uninhabited types. There are more places where we can likely use poison, but I wanted to stay conservative to start with. In particular the aggregate case is important for newer LLVM versions, which are not able to handle an undef base value during early optimization due to poison-propagation concerns.
2023-03-15Auto merge of #108282 - cjgillot:mir-checked-sh, r=tmiaskobors-11/+0
Implement checked Shl/Shr at MIR building. This does not require any special handling by codegen backends, as the overflow behaviour is entirely determined by the rhs (shift amount). This allows MIR ConstProp to remove the overflow check for constant shifts. ~There is an existing different behaviour between cg_llvm and cg_clif (cc `@bjorn3).` I took cg_llvm's one as reference: overflow if `rhs < 0 || rhs > number_of_bits_in_lhs_ty`.~ EDIT: `cg_llvm` and `cg_clif` implement the overflow check differently. This PR uses `cg_llvm`'s implementation based on a `BitAnd` instead of `cg_clif`'s one based on an unsigned comparison.
2023-03-15Account for debuginfo on _0 without naming it.Camille GILLOT-6/+2
2023-03-15Fix linker detection for clang with prefixTaiki Endo-1/+3
2023-03-14ICE when checking LocalInfo on runtime MIR.Camille GILLOT-2/+1