about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa
AgeCommit message (Collapse)AuthorLines
2022-12-18Auto merge of #105446 - erikdesjardins:vt-size, r=nikicbors-3/+12
Add 0..=isize::MAX range metadata to size loads from vtables This is the (much belated) size counterpart to #91569. Inspired by https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Range.20metadata.20for.20.60size_of_val.60.20and.20other.20isize.3A.3AMAX.20limits. This could help optimize layout computations based on the size of a dyn trait. Though, admittedly, adding this to vtables wouldn't be as beneficial as adding it to slice len, which is used much more often. Miri detects this UB already: https://github.com/rust-lang/rust/blob/b7cc99142ad0cfe47e2fe9f7a82eaf5b672c0573/compiler/rustc_const_eval/src/interpret/traits.rs#L119-L121 (In fact Miri goes further, [assuming a 48-bit address space on 64-bit platforms](https://github.com/rust-lang/rust/blob/9db224fc908059986c179fc6ec433944e9cfce50/compiler/rustc_abi/src/lib.rs#L312-L331), but I don't think we can assume that in an optimization.)
2022-12-18don't restuct references just to reborrowMatthias Krüger-2/+2
2022-12-16don't copy symbols from dylibs with -Zdylib-ltoRémy Rakic-1/+1
2022-12-15Check `fn_sig` in more situations per reviewinquisitivecrystal-1/+1
2022-12-14Rollup merge of #105578 - erikdesjardins:addrspacecast, r=bjorn3Matthias Krüger-4/+9
Fix transmutes between pointers in different address spaces (e.g. fn ptrs on AVR) Currently, this causes a verifier error (https://godbolt.org/z/YYohed4bj), since it uses `bitcast`, which can't convert between address spaces. Uncovered due to https://github.com/rust-lang/rust/pull/105545#discussion_r1045269309 r? `@bjorn3`
2022-12-13Don't perform invalid checks in `codegen_attrs`inquisitivecrystal-2/+23
Some attributes are only valid on function items. When checking these attributes, codegen_attrs previously sometimes called `fn_sig` on the item they were attached to without first ensuring that the item was a function. This led to an ICE (#105594), since `fn_sig` can only be called on functions. After this change, we skip calling `fn_sig` if the item the attribute is attached to must be a function but invalidly isn't, because `check_attr` will reject such cases without codegen_attrs's intervention.
2022-12-14Auto merge of #105221 - alex:fat-archive-cleanup, r=bjorn3bors-36/+34
Avoid a temporary file when processing macOS fat archives r? `@bjorn3`
2022-12-14Auto merge of #104986 - compiler-errors:opaques, r=oli-obkbors-3/+2
Combine `ty::Projection` and `ty::Opaque` into `ty::Alias` Implements https://github.com/rust-lang/types-team/issues/79. This PR consolidates `ty::Projection` and `ty::Opaque` into a single `ty::Alias`, with an `AliasKind` and `AliasTy` type (renamed from `ty::ProjectionTy`, which is the inner data of `ty::Projection`) defined as so: ``` enum AliasKind { Projection, Opaque, } struct AliasTy<'tcx> { def_id: DefId, substs: SubstsRef<'tcx>, } ``` Since we don't have access to `TyCtxt` in type flags computation, and because repeatedly calling `DefKind` on the def-id is expensive, these two types are distinguished with `ty::AliasKind`, conveniently glob-imported into `ty::{Projection, Opaque}`. For example: ```diff match ty.kind() { - ty::Opaque(..) => + ty::Alias(ty::Opaque, ..) => {} _ => {} } ``` This PR also consolidates match arms that treated `ty::Opaque` and `ty::Projection` identically. r? `@ghost`
2022-12-13Combine identical alias armsMichael Goulet-2/+1
2022-12-13Combine projection and opaque into aliasMichael Goulet-2/+2
2022-12-13ProjectionTy.item_def_id -> ProjectionTy.def_idMichael Goulet-1/+1
2022-12-13Rename `assert_uninit_valid` intrinsicNilstrieb-3/+3
It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that.
2022-12-13Move some codegen-y methods from rustc_hir_analysis::collect -> ↵Michael Goulet-10/+851
rustc_codegen_ssa
2022-12-12Auto merge of #105252 - bjorn3:codegen_less_pair_values, r=nagisabors-24/+12
Use struct types during codegen in less places This makes it easier to use cg_ssa from a backend like Cranelift that doesn't have any struct types at all. After this PR struct types are still used for function arguments and return values. Removing those usages is harder but should still be doable.
2022-12-11fix transmutes between pointers in different address spacesErik Desjardins-4/+9
2022-12-11bug! with a better error message for failing Instance::resolveMichael Goulet-4/+7
2022-12-11Rollup merge of #105537 - kadiwa4:remove_some_imports, r=fee1-deadMatthias Krüger-1/+0
compiler: remove unnecessary imports and qualified paths Some of these imports were necessary before Edition 2021, others were already in the prelude. I hope it's fine that this PR is so spread-out across files :/
2022-12-10compiler: remove unnecessary imports and qualified pathsKaDiWa-1/+0
2022-12-10Rollup merge of #105482 - wesleywiser:fix_debuginfo_ub, r=tmiaskoMatthias Krüger-29/+107
Fix invalid codegen during debuginfo lowering In order for LLVM to correctly generate debuginfo for msvc, we sometimes need to spill arguments to the stack and perform some direct & indirect offsets into the value. Previously, this code always performed those actions, even when not required as LLVM would clean it up during optimization. However, when MIR inlining is enabled, this can cause problems as the operations occur prior to the spilled value being initialized. To solve this, we first calculate the necessary offsets using just the type which is side-effect free and does not alter the LLVM IR. Then, if we are in a situation which requires us to generate the LLVM IR (and this situation only occurs for arguments, not local variables) then we perform the same calculation again, this time generating the appropriate LLVM IR as we go. r? `@tmiasko` but feel free to reassign if you want 🙂 Fixes #105386
2022-12-10Rollup merge of #105234 - JakobDegen:unneeded-field, r=oli-obkMatthias Krüger-5/+3
Remove unneeded field from `SwitchTargets` This had a fixme already. The only change in behavior is that the mir dumps now no longer contains labels for the types of the integers on the edges of a switchint: Before: ![image](https://user-images.githubusercontent.com/51179609/205467622-34401a68-dca6-43eb-915e-b9fda1988860.png) After: ![image](https://user-images.githubusercontent.com/51179609/205467634-b5b2a259-9cb4-4843-845c-592c500f0f9c.png) I don't think that's a problem though. The information is still available to a user that really cares by checking the type of `_2`, so it honestly feels like a bit of an improvement to me. r? mir
2022-12-10Rollup merge of #105109 - rcvalle:rust-kcfi, r=bjorn3Matthias Krüger-0/+1
Add LLVM KCFI support to the Rust compiler This PR adds LLVM Kernel Control Flow Integrity (KCFI) support to the Rust compiler. It initially provides forward-edge control flow protection for operating systems kernels for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. (See llvm/llvm-project@cff5bef.) Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653). LLVM KCFI can be enabled with -Zsanitizer=kcfi. Thank you again, `@bjorn3,` `@eddyb,` `@nagisa,` and `@ojeda,` for all the help!
2022-12-09Remove unneeded field from `SwitchTargets`Jakob Degen-5/+3
2022-12-08Don't generate pointer loads to spills unless necessaryWesley Wiser-2/+27
In order for LLVM to correctly generate debuginfo for msvc, we sometimes need to spill arguments to the stack and perform some direct & indirect offsets into the value. Previously, this code always performed those actions, even when not required as LLVM would clean it up during optimization. However, when MIR inlining is enabled, this can cause problems as the operations occur prior to the spilled value being initialized. To solve this, we first calculate the necessary offsets using just the type which is side-effect free and does not alter the LLVM IR. Then, if we are in a situation which requires us to generate the LLVM IR (and this situation only occurs for arguments, not local variables) then we perform the same calculation again, this time generating the appropriate LLVM IR as we go.
2022-12-08Make `debuginfo_offset_calcuation` generic so we can resuse the logicWesley Wiser-10/+41
This will allow us to separate the act of calculating the offsets from creating LLVM IR that performs the actions.
2022-12-08Factor out debuginfo offset calculationWesley Wiser-27/+49
2022-12-08Add LLVM KCFI support to the Rust compilerRamon de C Valle-0/+1
This commit adds LLVM Kernel Control Flow Integrity (KCFI) support to the Rust compiler. It initially provides forward-edge control flow protection for operating systems kernels for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. (See llvm/llvm-project@cff5bef.) Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653). LLVM KCFI can be enabled with -Zsanitizer=kcfi. Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2022-12-08Rollup merge of #105423 - oli-obk:symbols, r=jackh726Matthias Krüger-1/+1
Use `Symbol` for the crate name instead of `String`/`str` It always got converted to a symbol anyway
2022-12-08Add 0..=isize::MAX range metadata to size loads from vtablesErik Desjardins-3/+12
2022-12-07Use `Symbol` for the crate name instead of `String`/`str`Oli Scherer-1/+1
2022-12-07fix: remove hack from link.rs (moved to libc)Daniil Belov-9/+0
2022-12-04Auto merge of #104535 - mikebenfield:discr-fix, r=pnkfelixbors-9/+18
rustc_codegen_ssa: Fix for codegen_get_discr When doing the optimized implementation of getting the discriminant, the arithmetic needs to be done in the tag type so wrapping behavior works correctly. Fixes #104519
2022-12-04Avoid from_immediate_or_packed_pair in ThreadLocalRef codegenbjorn3-1/+1
2022-12-03Avoid a temporary file when processing macOS fat archivesAlex Gaynor-36/+34
2022-12-03Directly return loaded value from type_checked_loadbjorn3-2/+1
2022-12-03Destruct landing_pad return value before passing it to cg_ssabjorn3-21/+10
2022-12-03Auto merge of #97485 - bjorn3:new_archive_writer, r=wesleywiserbors-2/+244
Rewrite LLVM's archive writer in Rust This allows it to be used by other codegen backends. Fixes https://github.com/bjorn3/rustc_codegen_cranelift/issues/1155
2022-12-03Make sure all input archives are unmapped before persisting the output archivebjorn3-1/+7
2022-12-02Write to temp file before renaming to the final namebjorn3-4/+22
2022-11-28Rollup merge of #104360 - petrochenkov:stabverb, r=TaKO8KiDylan DPC-13/+9
Stabilize native library modifier `verbatim` Stabilization report - https://github.com/rust-lang/rust/pull/104360#issuecomment-1312724787. cc https://github.com/rust-lang/rust/issues/81490 Closes https://github.com/rust-lang/rust/issues/99425
2022-11-27Stabilize native library modifier `verbatim`Vadim Petrochenkov-13/+9
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-52/+52
2022-11-26Rewrite LLVM's archive writer in Rustbjorn3-2/+220
This allows it to be used by other codegen backends
2022-11-25Rollup merge of #104797 - weihanglo:stream-write-dwp, r=jackh726Matthias Krüger-4/+5
rustc_codegen_ssa: write `.dwp` in a streaming fashion When writing a `.dwp` file, rustc writes to a Vec first then to a BufWriter-wrapped file. It seems very likely that we can write in a streaming fashion to avoid double buffering in an intermediate Vec. On my Linux machine, `.dwp` from the latest rust-lang/cargo is 113MiB. It may worth a stream writer, though I didn't do any benchmark 🙇🏾‍♂️.
2022-11-24Rollup merge of #104704 - ecnelises:p10vec, r=jackh726Matthias Krüger-0/+1
Allow power10-vector feature in PowerPC Note that we don't have `power10-altivec`: https://github.com/llvm/llvm-project/blob/57fd7ffefffae313de800fecdd9f095a17bfd4ea/llvm/lib/Target/PowerPC/PPC.td#L277-L280
2022-11-24Properly handle `Pin<&mut dyn* Trait>` receiver in codegenMichael Goulet-6/+24
2022-11-24rustc_codegen_ssa: write `.dwp` in a streaming fashionWeihang Lo-4/+5
2022-11-22Allow power10-vector feature in PowerPCQiu Chaofan-0/+1
2022-11-21Rollup merge of #104605 - RalfJung:clf_consts, r=bjorn3Matthias Krüger-1/+8
deduplicate constant evaluation in cranelift backend The cranelift backend had two matches on `ConstantKind`, which can be avoided, and used this `eval_for_mir` that nothing else uses... this makes things more consistent with the (better-tested) LLVM backend. I noticed this because cranelift was the only user of `eval_for_mir`. However `try_eval_for_mir` still has one other user in `eval`... the odd thing is that the interpreter has its own `eval_mir_constant` which seems to duplicate the same functionality and does not use `try_eval_for_mir`. No idea what is happening here. r? ``@bjorn3`` Cc ``@lcnr``
2022-11-19deduplicate constant evaluation in cranelift backendRalf Jung-1/+8
also sync LLVM and cranelift structure a bit
2022-11-19Rollup merge of #104001 - Ayush1325:custom-entry, r=bjorn3Dylan DPC-1/+2
Improve generating Custom entry function This commit is aimed at making compiler-generated entry functions (Basically just C `main` right now) more generic so other targets can do similar things for custom entry. This was initially implemented as part of https://github.com/rust-lang/rust/pull/100316. Currently, this moves the entry function name and Call convention to the target spec. Signed-off-by: Ayush Singh <ayushsingh1325@gmail.com>