about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/builder.rs
AgeCommit message (Collapse)AuthorLines
2023-06-02Rollup merge of #111647 - klensy:cstr, r=oli-obkMatthias Krüger-12/+4
use c literals in compiler and library Use c literals #108801 in compiler and library currently blocked on: * <strike>rustfmt: don't know how to format c literals</strike> nope, nightly one works. * <strike>bootstrap</strike> r? `@ghost` `@rustbot` blocked
2023-05-31Add a distinct `OperandValue::ZeroSized` variant for ZSTsScott McMurray-1/+1
These tend to have special handling in a bunch of places anyway, so the variant helps remember that. And I think it's easier to grok than non-Scalar Aggregates sometimes being `Immediates` (like I got wrong and caused 109992). As a minor bonus, it means we don't need to generate poison LLVM values for them to pass around in `OperandValue::Immediate`s.
2023-05-31use new c literals instead of cstr! macroklensy-12/+4
2023-05-07Fix num reserved clauses for landing padGary Guo-2/+2
2023-05-07Use `landingpad filter` to encode aborting landing padGary Guo-0/+7
2023-05-03Add cross-language LLVM CFI support to the Rust compilerRamon de C Valle-30/+88
This commit adds cross-language LLVM Control Flow Integrity (CFI) support to the Rust compiler by adding the `-Zsanitizer-cfi-normalize-integers` option to be used with Clang `-fsanitize-cfi-icall-normalize-integers` for normalizing integer types (see https://reviews.llvm.org/D139395). It provides 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). For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler, see design document in the tracking issue #89653. Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and -Zsanitizer-cfi-normalize-integers, and requires proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto).
2023-04-08fixup: use Bool instead of boolklensy-2/+10
2023-04-04replaceklensy-2/+2
LLVMRustBuildIntCast -> LLVMBuildIntCast2 LLVMRustAddHandler -> LLVMAddHandler
2023-04-04Use existing llvm methods, instead of rust wrappers for:klensy-8/+7
LLVMRustBuildCleanupPad -> LLVMBuildCleanupPad LLVMRustBuildCleanupRet -> LLVMBuildCleanupRet LLVMRustBuildCatchPad -> LLVMBuildCatchPad LLVMRustBuildCatchRet -> LLVMBuildCatchRet LLVMRustBuildCatchSwitch -> LLVMBuildCatchSwitch
2023-04-01a couple clippy::complexity fixesMatthias Krüger-2/+2
map_identity filter_next option_as_ref_deref unnecessary_find_map redundant_slicing unnecessary_unwrap bool_comparison derivable_impls manual_flatten needless_borrowed_reference
2023-03-16Use poison instead of undefNikita Popov-1/+1
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-01-22abi: add `AddressSpace` field to `Primitive::Pointer`Erik Desjardins-1/+1
...and remove it from `PointeeInfo`, which isn't meant for this. There are still various places (marked with FIXMEs) that assume all pointers have the same size and alignment. Fixing this requires parsing non-default address spaces in the data layout string, which will be done in a followup.
2023-01-17Put `noundef` on all scalars that don't allow uninitNilstrieb-1/+1
Previously, it was only put on scalars with range validity invariants like bool, was uninit was obviously invalid for those. Since then, we have normatively declared all uninit primitives to be undefined behavior and can therefore put `noundef` on them. The remaining concern was the `mem::uninitialized` function, which cause quite a lot of UB in the older parts of the ecosystem. This function now doesn't return uninit values anymore, making users of it safe from this change. The only real sources of UB where people could encounter uninit primitives are `MaybeUninit::uninit().assume_init()`, which has always be clear in the docs about being UB and from heap allocations (like reading from the spare capacity of a vec. This is hopefully rare enough to not break anything.
2022-12-19clippy::complexity fixesMatthias Krüger-2/+2
filter_next needless_question_mark bind_instead_of_map manual_find derivable_impls map_identity redundant_slicing skip_while_next unnecessary_unwrap needless_bool
2022-12-12Auto merge of #105252 - bjorn3:codegen_less_pair_values, r=nagisabors-3/+8
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-08Add LLVM KCFI support to the Rust compilerRamon de C Valle-7/+43
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-03Destruct landing_pad return value before passing it to cg_ssabjorn3-3/+8
2022-11-16Use `&mut Bx` more.Nicholas Nethercote-5/+5
For the next commit, `FunctionCx::codegen_*_terminator` need to take a `&mut Bx` instead of consuming a `Bx`. This triggers a cascade of similar changes across multiple functions. The resulting code is more concise and replaces many `&mut bx` expressions with `bx`.
2022-10-20Don't use usub.with.overflow intrinsicNikita Popov-5/+8
The canonical form of a usub.with.overflow check in LLVM are separate sub + icmp instructions, rather than a usub.with.overflow intrinsic. Using usub.with.overflow will generally result in worse optimization potential. The backend will attempt to form usub.with.overflow when it comes to actual instruction selection. This is not fully reliable, but I believe this is a better tradeoff than using the intrinsic in IR. Fixes #103285.
2022-10-02Remove type argument of array_alloca and rename to byte_array_allocabjorn3-2/+3
2022-10-02Remove dynamic_alloca from BuilderMethodsbjorn3-5/+1
2022-10-01Merge apply_attrs_callsite into call and invokebjorn3-4/+15
Some codegen backends are not able to apply callsite attrs after the fact.
2022-09-18Use LLVM C-API to build atomic cmpxchg and fenceJosh Stone-10/+16
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-1/+0
by module
2022-08-16Move the cast_float_to_int fallback code to GCCJosh Stone-9/+4
Now that we require at least LLVM 13, that codegen backend is always using its intrinsic `fptosi.sat` and `fptoui.sat` conversions, so it doesn't need the manual implementation. However, the GCC backend still needs it, so we can move all of that code down there.
2022-08-14Update the minimum external LLVM to 13Josh Stone-54/+25
2022-07-23Add fine-grained LLVM CFI support to the Rust compilerRamon de C Valle-26/+0
This commit improves the LLVM Control Flow Integrity (CFI) support in the Rust compiler by providing forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. 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 CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto).
2022-07-05Prefer trace level instrumentation for the new noisy instrument attributesOli Scherer-1/+1
2022-06-29Some tracing cleanupsOli Scherer-3/+3
2022-06-22Work around llvm 12's memory ordering restrictions.Mara Bos-1/+15
Older llvm has the pre-C++17 restriction on success and failure memory ordering, requiring the former to be at least as strong as the latter. So, for llvm 12, this upgrades the success ordering to a stronger one if necessary.
2022-05-25Don't use global initializer if type does not matchNikita Popov-2/+7
This was relying on the presence of a bitcast to avoid using the constant global initializer for a load using a different type. With opaque pointers, we need to check this explicitly.
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-1/+1
2022-04-05Mark scalar layout unions so that backends that do not support partially ↵Oli Scherer-4/+4
initialized scalars can special case them.
2022-04-03Replace every `String` in Target(Options) with `Cow<'static, str>`Loïc BRANSTETT-1/+1
2022-03-04Auto merge of #94159 - erikdesjardins:align-load, r=nikicbors-8/+30
Add !align metadata on loads of &/&mut/Box Note that this refers to the alignment of what the loaded value points to, _not_ the alignment of the loaded value itself. r? `@ghost` (blocked on #94158)
2022-03-01Auto merge of #94402 - erikdesjardins:revert-coldland, r=nagisabors-14/+3
Revert "Auto merge of #92419 - erikdesjardins:coldland, r=nagisa" Should fix (untested) #94390 Reopens #46515, #87055 r? `@ehuss`
2022-02-28Add !align metadata on loads of &/&mut/BoxErik Desjardins-8/+30
Note that this refers to the alignment of what the loaded value points to, _not_ the alignment of the loaded value itself.
2022-02-27Revert "Auto merge of #92419 - erikdesjardins:coldland, r=nagisa"Erik Desjardins-14/+3
This reverts commit 4f49627c6fe2a32d1fed6310466bb0e1c535c0c0, reversing changes made to 028c6f1454787c068ff5117e9000a1de4fd98374.
2022-02-27Apply noundef metadata to loads of types that do not permit raw initErik Desjardins-0/+14
This matches the noundef attributes we apply on arguments/return types.
2022-02-26Add LLVM attributes in batches instead of individuallyErik Desjardins-2/+8
This should improve performance.
2022-02-24Introduce Bx::switch_to_blockbjorn3-0/+4
2022-02-20Remove build_sibling_blockbjorn3-13/+11
2022-01-24Merge landing_pad and set_cleanup into cleanup_landing_padbjorn3-16/+18
2022-01-24Merge add_handler into catch_switchbjorn3-8/+8
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-17Update compiler/rustc_codegen_llvm/src/builder.rsCaleb Zulawski-3/+3
Co-authored-by: Jubilee <46493976+workingjubilee@users.noreply.github.com>
2022-01-04Add simd_as intrinsicCaleb Zulawski-18/+41
2021-12-30keep noinline for system llvm < 14Erik Desjardins-1/+8
2021-12-29Mark drop calls in landing pads cold instead of noinlineErik Desjardins-2/+2
Now that deferred inlining has been disabled in LLVM, this shouldn't cause catastrophic size blowup.