about summary refs log tree commit diff
path: root/src/test/codegen
AgeCommit message (Collapse)AuthorLines
2022-07-27Make CFI tests opaque pointers compatibleNikita Popov-7/+6
2022-07-27Remove outdated rustc_allocator testNikita Popov-7/+0
This attribute now does more than just place noalias on the return, and has specific requirements for the signature. Drop the test entirely, as we already check __rust_alloc attributes in other codegen tests.
2022-07-27Update codegen test for opaque pointersNikita Popov-8/+8
2022-07-26codegen: use new {re,de,}allocator annotations in llvmAugie Fackler-0/+183
This obviates the patch that teaches LLVM internals about _rust_{re,de}alloc functions by putting annotations directly in the IR for the optimizer. The sole test change is required to anchor FileCheck to the body of the `box_uninitialized` method, so it doesn't see the `allocalign` on `__rust_alloc` and get mad about the string `alloca` showing up. Since I was there anyway, I added some checks on the attributes to prove the right attributes got set. While we're here, we also emit allocator attributes on __rust_alloc_zeroed. This should allow LLVM to perform more optimizations for zeroed blocks, and probably fixes #90032. [This comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157) mentions "weird UB-like behaviour with bitvec iterators in rustc_data_structures" so we may need to back this change out if things go wrong. The new test cases require LLVM 15, so we copy them into LLVM 14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-25Auto merge of #97581 - ↵bors-12/+124
AngelicosPhosphoros:improve_calloc_check_in_vec_macro_for_tuples, r=Mark-Simulacrum Support vec zero-alloc optimization for tuples and byte arrays * Implement IsZero trait for tuples up to 8 IsZero elements; * Implement IsZero for u8/i8, leading to implementation of it for arrays of them too; * Add more codegen tests for this optimization. * Lower size of array for IsZero trait because it fails to inline checks
2022-07-24Support vec zero-alloc optimization for tuples and byte arraysAngelicosPhosphoros-12/+124
* Implement IsZero trait for tuples up to 8 IsZero elements; * Implement IsZero for u8/i8, leading to implementation of it for arrays of them too; * Add more codegen tests for this optimization. * Lower size of array for IsZero trait because it fails to inline checks
2022-07-24Auto merge of #99409 - tmiasko:atomic-tests, r=m-ou-sebors-1/+109
Test codegen of atomic compare-exchange with additional memory orderings * Add a test for atomic operations introduced in #97423 & #98383. * Add a test for fallback code generation strategy used on LLVM 12 introduced in #98385. Use a separate test case instead of a revision system since test will be gone once LLVM 12 is no longer supported.
2022-07-24Auto merge of #95548 - rcvalle:rust-cfi-2, r=nagisabors-39/+608
Add fine-grained LLVM CFI support to the Rust compiler This PR 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 https://github.com/rust-lang/rust/issues/89653). LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto). Thank you again, `@eddyb,` `@nagisa,` `@pcc,` and `@tmiasko` for all the help!
2022-07-23Auto merge of #98208 - ivanloz:master, r=nagisabors-0/+17
Add support for LLVM ShadowCallStack. LLVMs ShadowCallStack provides backward edge control flow integrity protection by using a separate shadow stack to store and retrieve a function's return address. LLVM currently only supports this for AArch64 targets. The x18 register is used to hold the pointer to the shadow stack, and therefore this only works on ABIs which reserve x18. Further details are available in the [LLVM ShadowCallStack](https://clang.llvm.org/docs/ShadowCallStack.html) docs. # Usage `-Zsanitizer=shadow-call-stack` # Comments/Caveats * Currently only enabled for the aarch64-linux-android target * Requires the platform to define a runtime to initialize the shadow stack, see the [LLVM docs](https://clang.llvm.org/docs/ShadowCallStack.html) for more detail.
2022-07-23Add fine-grained LLVM CFI support to the Rust compilerRamon de C Valle-39/+608
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-22do not mark interior mutable shared refs as dereferenceableRalf Jung-1/+19
2022-07-22Auto merge of #99491 - workingjubilee:sync-psimd, r=workingjubileebors-1/+1
Sync in portable-simd subtree r? `@ghost`
2022-07-20Introduce core::simd trait imports in testsJubilee Young-1/+1
2022-07-20Test codegen of atomic compare-exchange with additional memory orderingsTomasz Miąsko-1/+109
* Add a test for atomic operations introduced in #97423 & #98383. * Add a test for fallback code generation strategy used on LLVM 12 introduced in #98385. Use a separate test case instead of a revision system since test will be gone once LLVM 12 is no longer supported.
2022-07-20Add ShadowCallStack SupportIvan Lozano-0/+17
Adds support for the LLVM ShadowCallStack sanitizer.
2022-07-20Rollup merge of #99436 - Nilstrieb:toggle-box-noalias, r=fee1-deadDylan DPC-0/+16
Add flag to configure `noalias` on `Box<T>` The aliasing rules of `Box<T>` are still not decided, but currently, `Box<T>` is unique and gets `noalias`. To aid making an informed decision about the future of `Box<T>`, this PR adds a flag `-Zbox-noalias` to configure `noalias` for `Box<T>` (for example, for benchmarking). The same flag already exists for `&mut T` `noalias`, where it was added because it was the problem of various miscompilations in LLVM. For more information, see rust-lang/unsafe-code-guidelines#326
2022-07-19Add flag to configure `noalias` on `Box<T>`nils-0/+16
To aid making an informed decision about the aliasing rules of box, give users an option to remove `noalias` from box.
2022-07-18Rollup merge of #98998 - ↵Dylan DPC-1/+1
workingjubilee:naked-means-no-clothes-enforcement-technology, r=Amanieu Remove branch target prologues from `#[naked] fn` This patch hacks around rust-lang/rust#98768 for now via injecting appropriate attributes into the LLVMIR we emit for naked functions. I intend to pursue this upstream so that these attributes can be removed in general, but it's slow going wading through C++ for me.
2022-07-08Support unstable moves via stable in unstable itemsJane Lusby-0/+1
2022-07-08Auto merge of #98758 - nnethercote:more-derive-output-improvements, ↵bors-1/+1
r=Mark-Simulacrum More derive output improvements This PR includes: - Some test improvements. - Some cosmetic changes to derive output that make the code look more like what a human would write. - Some more fundamental improvements to `cmp` and `partial_cmp` generation. r? `@Mark-Simulacrum`
2022-07-07Bless MSVC debuginfo.Camille GILLOT-2/+2
2022-07-07Bless codegen test.Camille GILLOT-2/+2
2022-07-06Stop emitting CET prologues for naked functionsJubilee Young-1/+1
We can apply nocf_check as a hack for now.
2022-07-05Rollup merge of #98920 - krasimirgg:llvm-15-issue-37945, r=nikicMatthias Krüger-2/+6
adapt issue-37945 codegen test to accept any order of ops Adapt this test to accept `icmp` operands in any order as a follow-up to https://github.com/rust-lang/rust/commit/cbbf06b0cd39dc93033568f1e65f5363cbbdebcd#commitcomment-77670922.
2022-07-05adapt issue-37945 codegen test to accept any order of opsKrasimir Georgiev-2/+6
2022-07-05Auto merge of #96862 - oli-obk:enum_cast_mir, r=RalfJungbors-7/+14
Change enum->int casts to not go through MIR casts. follow-up to https://github.com/rust-lang/rust/pull/96814 this simplifies all backends and even gives LLVM more information about the return value of `Rvalue::Discriminant`, enabling optimizations in more cases.
2022-07-04Avoid unnecessary 1-tuples in derived code.Nicholas Nethercote-1/+1
2022-07-01Amend codegen test.Camille GILLOT-22/+24
2022-06-30Auto merge of #98377 - davidv1992:add-lifetimes-to-argument-temporaries, ↵bors-0/+27
r=oli-obk Added llvm lifetime annotations to function call argument temporaries. The goal of this change is to ensure that llvm will do stack slot optimization on these temporaries. This ensures that in code like: ```rust const A: [u8; 1024] = [0; 1024]; fn copy_const() { f(A); f(A); } ``` we only use 1024 bytes of stack space, instead of 2048 bytes. I am new to developing for the rust compiler, and as such not entirely sure, but I believe this should be sufficient to close #98156. Also, this does not contain a test case to ensure this keeps working, primarily because I am not sure how to go about testing this. I would love some suggestions as to how that could be approached.
2022-06-30Change enum->int casts to not go through MIR casts.Oli Scherer-7/+14
Instead we generate a discriminant rvalue and cast the result of that.
2022-06-25Added test for const arg lifetimes suggested by erikdesjardins.David Venhoek-0/+27
2022-06-25Auto merge of #96820 - r-raymond:master, r=cuviperbors-0/+14
Make RwLockReadGuard covariant Hi, first time contributor here, if anything is not as expected, please let me know. `RwLockReadGoard`'s type constructor is invariant. Since it behaves like a smart pointer to an immutable reference, there is no reason that it should not be covariant. Take e.g. ``` fn test_read_guard_covariance() { fn do_stuff<'a>(_: RwLockReadGuard<'_, &'a i32>, _: &'a i32) {} let j: i32 = 5; let lock = RwLock::new(&j); { let i = 6; do_stuff(lock.read().unwrap(), &i); } drop(lock); } ``` where the compiler complains that &i doesn't live long enough. If `RwLockReadGuard` is covariant, then the above code is accepted because the lifetime can be shorter than `'a`. In order for `RwLockReadGuard` to be covariant, it can't contain a full reference to the `RwLock`, which can never be covariant (because it exposes a mutable reference to the underlying data structure). By reducing the data structure to the required pieces of `RwLock`, the rest falls in place. If there is a better way to do a test that tests successful compilation, please let me know. Fixes #80392
2022-06-21Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obkbors-20/+20
Remove dereferencing of Box from codegen Through #94043, #94414, #94873, and #95328, I've been fixing issues caused by Box being treated like a pointer when it is not a pointer. However, these PRs just introduced special cases for Box. This PR removes those special cases and instead transforms a deref of Box into a deref of the pointer it contains. Hopefully, this is the end of the Box<T, A> ICEs.
2022-06-20UnsafeCell -> RwLockRobin Raymond-4/+3
2022-06-19Make sure we don't match noalias in later linesRobin Raymond-0/+1
2022-06-19Add test to verify noalias is not being addedRobin Raymond-0/+14
2022-06-15remove box derefs from codgenDrMeepster-20/+20
2022-06-15Rollup merge of #98078 - erikdesjardins:uncheckedsize, r=petrochenkovYuki Okushi-0/+29
Use unchecked mul to compute slice sizes This allows LLVM to realize that `slice.len() > 0` iff `slice.len() * size_of::<T>() > 0`, allowing a branch on the latter to be folded into the former when dropping vecs and boxed slices, in some cases. Fixes (partially) #96497
2022-06-14use unchecked mul to compute slice sizesErik Desjardins-0/+29
...since slice sizes can't signed wrap see https://doc.rust-lang.org/std/slice/fn.from_raw_parts.html > The total size len * mem::size_of::<T>() of the slice must be no larger than isize::MAX.
2022-06-14Add VFE test for 32 bitflip1995-0/+36
The offset in the llvm.type.checked.load intrinsic differs on 32 bit platforms
2022-06-14Add test for VFE optimizationflip1995-0/+99
2022-06-08Rollup merge of #97846 - pcwalton:align-bits, r=michaelwoeristerDylan DPC-0/+8
Specify DWARF alignment in bits, not bytes. In DWARF, alignment of types is specified in bits, as is made clear by the parameter name `AlignInBits`. However, `rustc` was incorrectly passing a byte alignment. This commit fixes that. This was noticed in upstream LLVM when I tried to check in a test consisting of LLVM IR generated from `rustc` and it triggered assertions [1]. [1]: https://reviews.llvm.org/D126835
2022-06-07Specify DWARF alignment in bits, not bytes.Patrick Walton-0/+8
In DWARF, alignment of types is specified in bits, as is made clear by the parameter name `AlignInBits`. However, `rustc` was incorrectly passing a byte alignment. This commit fixes that. This was noticed in upstream LLVM when I tried to check in a test consisting of LLVM IR generated from `rustc` and it triggered assertions [1]. [1]: https://reviews.llvm.org/D126835
2022-06-07Auto merge of #97512 - scottmcm:add-coldcc, r=nagisa,lcnrbors-0/+18
Add support for emitting functions with `coldcc` to LLVM The eventual goal is to try using this for things like the internal panicking stuff, to see whether it helps.
2022-06-05Fix the coldcc codegen test on wasm32Scott McMurray-1/+3
2022-05-30Add support for emitting functions with `coldcc` in LLVMScott McMurray-0/+16
The eventual goal is to try using this for things like the internal panicking stuff, to see whether it helps.
2022-05-25Update some codegen tests for opaque pointersNikita Popov-276/+243
2022-05-23Refactor call terminator to always hold a destination placeJakob Degen-1/+1
2022-05-20Auto merge of #97027 - cuviper:yesalias-refcell, r=thomccbors-0/+14
Use pointers in `cell::{Ref,RefMut}` to avoid `noalias` When `Ref` and `RefMut` were based on references, they would get LLVM `noalias` attributes that were incorrect, because that alias guarantee is only true until the guard drops. A `&RefCell` on the same value can get a new borrow that aliases the previous guard, possibly leading to miscompilation. Using `NonNull` pointers in `Ref` and `RefCell` avoids `noalias`. Fixes the library side of #63787, but we still might want to explore language solutions there.
2022-05-18Properly apply path prefix remapping paths emitted into debuginfo.Michael Woerister-1/+1