summary refs log tree commit diff
path: root/compiler/rustc_abi/src
AgeCommit message (Collapse)AuthorLines
2024-08-27ABI compat check: detect unadjusted ABI mismatchesRalf Jung-1/+3
2024-08-16Add `warn(unreachable_pub)` to several crates.Nicholas Nethercote-0/+1
It requires no additonal changes to these crates, but will prevent unnecessary `pub`s in the future.
2024-08-01interpret: simplify pointer arithmetic logicRalf Jung-3/+3
2024-07-29Reformat `use` declarations.Nicholas Nethercote-9/+7
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-16Fix unsafe_op_in_unsafe_fn in compilerMichael Goulet-2/+2
2024-07-04Rollup merge of #123043 - GoldsteinE:fix/repr-c-dead-branches, r=oli-obkMatthias Krüger-3/+3
Disable dead variant removal for `#[repr(C)]` enums. This prevents removing dead branches from a `#[repr(C)]` enum (they now get discriminants allocated as if they were inhabited). Implementation notes: ABI of something like ```rust #[repr(C)] enum Foo { Foo(!), } ``` is still `Uninhabited`, but its layout is now computed as if all the branches were inhabited. This seemed to me like a proper way to do it, especially given that ABI sanity check explicitly asserts that type-level uninhabitedness implies ABI uninhabitedness. This probably needs some sort of FCP (given that it changes `#[repr(C)]` layout, which is a stable guarantee), but I’m not sure how to call for one or which team is the most relevant. See https://github.com/rust-lang/unsafe-code-guidelines/issues/500.
2024-06-28Disable dead variant removal for `#[repr(C)]` enums.Goldstein-3/+3
See https://github.com/rust-lang/unsafe-code-guidelines/issues/500.
2024-06-25Auto merge of #126326 - eggyal:ununsafe-StableOrd, r=michaelwoeristerbors-3/+5
Un-unsafe the `StableOrd` trait Whilst incorrect implementations of this trait can cause miscompilation, they cannot cause memory unsafety in rustc. [Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Policy.20of.20.60unsafe.60.20within.20the.20compiler). cc [MCP 533](https://github.com/rust-lang/compiler-team/issues/533), #105175, `@michaelwoerister` r? `@Nilstrieb`
2024-06-22Ensure careful consideration is given by implsAlan Egerton-2/+4
Added an associated `const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED` to the `StableOrd` trait to ensure that implementors carefully consider whether the trait's contract is upheld, as incorrect implementations can cause miscompilations.
2024-06-12Un-unsafe the `StableOrd` traitAlan Egerton-2/+2
Whilst incorrect implementations of this trait can cause miscompilation, they cannot cause memory unsafety in rustc.
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-1/+3
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-05-21don't inhibit random field reordering on repr(packed(1))Ralf Jung-15/+10
2024-05-18Temporarily revert to NonZeroUsize in rustc-abi to fix building on stableLaurențiu Nicola-6/+5
2024-05-11Make `index_by_increasing_offset` return one item for primitivesScott McMurray-1/+6
2024-05-11Unify `Rvalue::Aggregate` paths in cg_ssaScott McMurray-1/+1
2024-05-10Rollup merge of #124797 - beetrees:primitive-float, r=davidtwcoMatthias Krüger-12/+38
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
2024-05-08Use generic `NonZero`.Markus Reiter-5/+6
2024-05-06Refactor float `Primitive`s to a separate `Float` typebeetrees-12/+38
2024-05-03Rollup merge of #124555 - Zalathar:init-coverage, r=nnethercoteMatthias Krüger-0/+9
coverage: Clean up creation of MC/DC condition bitmaps This PR improves the code for creating and initializing [MC/DC](https://en.wikipedia.org/wiki/Modified_condition/decision_coverage) condition bitmap variables, as introduced by #123409 and modified by #124255. - The condition bitmap variables are now created eagerly at the start of per-function codegen, via a new `init_coverage` method in `CoverageInfoBuilderMethods`. This avoids having to retroactively create the bitmaps while doing codegen for an individual coverage statement. - As a result, we can now create and initialize those bitmaps using existing safe APIs, instead of having to perform our own unsafe call to `llvm::LLVMBuildAlloca`. - This PR also tweaks the way we count the number of condition bitmaps needed, by tracking the total number of bitmaps needed (max depth + 1), instead of only tracking the maximum depth. This reduces the potential for subtle off-by-one confusion.
2024-05-01Align: add bytes_usize and bits_usizeRalf Jung-0/+10
2024-05-01coverage: Set up MC/DC bitmaps without additional unsafe codeZalathar-0/+9
Because this now always takes place at the start of the function, we can just use the normal `alloca` method and then initialize each bitmap immediately. This patch also moves bitmap setup out of the `mcdc_parameters` method, because there is no longer any particular reason for it to be there.
2024-04-28Rename `inihibit_union_abi_opt()` to `inihibits_union_abi_opt()`Gurinder Singh-2/+2
The present tense makes it read more naturally at use site i.e. "this repr _inhibits_ optimizations"
2024-04-01Use the `Align` type when parsing alignment attributesbeetrees-3/+4
2024-03-13Auto merge of #121668 - erikdesjardins:commonprim, r=scottmcm,oli-obkbors-6/+28
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-06Rollup merge of #121382 - nnethercote:rework-untranslatable_diagnostic-lint, ↵Matthias Krüger-2/+5
r=davidtwco Rework `untranslatable_diagnostic` lint Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This PR changes it to check calls to any function with an `impl Into<{D,Subd}iagnosticMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. It also lets us add `#[rustc_lint_diagnostics]` to a number of functions that don't have an `impl Into<{D,Subd}iagnosticMessage>`, such as `Diag::span`. r? ``@davidtwco``
2024-03-05only set noalias on Box with the global allocatorRalf Jung-2/+5
2024-03-05Change message type in bug functions.Nicholas Nethercote-2/+5
From `impl Into<DiagnosticMessage>` to `impl Into<Cow<'static, str>>`. Because these functions don't produce user-facing output and we don't want their strings to be translated.
2024-02-28simplify common prim computationErik Desjardins-16/+9
2024-02-28Add `f16` and `f128` to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`Trevor Gross-0/+12
Make changes necessary to support these types in the compiler.
2024-02-27allow using scalarpair with a common prim of ptr/ptr-sized-intErik Desjardins-6/+35
2024-02-26fix some references to no-longer-existing ReprOptions.layout_seedRalf Jung-2/+2
2024-01-16Fix `rustc_abi` build on stableNadrieril-1/+8
2023-12-31Avoid specialization for the Span Encodable and Decodable implsbjorn3-7/+7
2023-12-30Update to bitflags 2 in the compilerNilstrieb-6/+9
This involves lots of breaking changes. There are two big changes that force changes. The first is that the bitflag types now don't automatically implement normal derive traits, so we need to derive them manually. Additionally, bitflags now have a hidden inner type by default, which breaks our custom derives. The bitflags docs recommend using the impl form in these cases, which I did.
2023-12-16Extract fn layout_of_structJubilee Young-102/+130
2023-12-16Extract fn layout_of_enumJubilee Young-476/+496
2023-12-16Manually inline scalar_unitJubilee Young-7/+3
2023-12-16Hoist fn absentJubilee Young-12/+18
2023-12-15Annotate panic! reasons during enum layoutJubilee Young-6/+14
Add some reasons to the panics, and use more exhaustive matches.
2023-12-02Rename `LayoutCalculator::delay_bug` as `LayoutCalculator::delayed_bug`.Nicholas Nethercote-3/+3
To match with the previous commits.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-3/+3
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-15Bump cfg(bootstrap)sMark Rousskov-2/+2
2023-11-05Make the randomize feature of rustc_abi additivehkalbasi-6/+4
2023-10-27fix failure to detect a too-big-type after adding paddingRalf Jung-0/+5
2023-10-20s/generator/coroutine/Oli Scherer-1/+1
2023-10-16docs: add Rust logo to more compiler cratesMichael Howell-0/+2
c6e6ecb1afea9695a42d0f148ce153536b279eb5 added it to some of the compiler's crates, but avoided adding it to all of them to reduce bit-rot. This commit adds to more.
2023-10-15place evaluation: require the original pointer to be aligned if an access ↵Ralf Jung-0/+1
happens
2023-10-04Remove unnecessary features from rustc_abiLukas Wirth-4/+6
2023-10-02Fix incorrect inlining of RangeInclusive::size_hintLukas Wirth-1/+1
2023-10-02Add some docs regarding rustc_abi rust-analyzer compat changesLukas Wirth-0/+4