Commit graph

1145 commits

Author SHA1 Message Date
Chris Denton
1ca5e4f1c1
Rollup merge of #134213 - folkertdev:stabilize-naked-functions, r=tgross35,Amanieu,traviscross
Stabilize `naked_functions`

tracking issue: https://github.com/rust-lang/rust/issues/90957
request for stabilization on tracking issue: https://github.com/rust-lang/rust/issues/90957#issuecomment-2539270352
reference PR: https://github.com/rust-lang/reference/pull/1689

# Request for Stabilization

Two years later, we're ready to try this again. Even though this issue is already marked as having passed FCP, given the amount of time that has passed and the changes in implementation strategy, we should follow the process again.

## Summary

The `naked_functions` feature has two main parts: the `#[naked]` function attribute, and the `naked_asm!` macro.

An example of a naked function:

```rust
const THREE: usize = 3;

#[naked]
pub extern "sysv64" fn add_n(number: usize) -> usize {
    // SAFETY: the validity of the used registers
    // is guaranteed according to the "sysv64" ABI
    unsafe {
        core::arch::naked_asm!(
            "add rdi, {}",
            "mov rax, rdi",
            "ret",
            const THREE,
        )
    }
}
```

When the `#[naked]` attribute is applied to a function, the compiler won't emit a [function prologue](https://en.wikipedia.org/wiki/Function_prologue_and_epilogue) or epilogue when generating code for this function. This attribute is analogous to [`__attribute__((naked))`](https://developer.arm.com/documentation/100067/0608/Compiler-specific-Function--Variable--and-Type-Attributes/--attribute----naked---function-attribute) in C. The use of this feature allows the programmer to have precise control over the assembly that is generated for a given function.

The body of a naked function must consist of a single `naked_asm!` invocation, a heavily restricted variant of the `asm!` macro: the only legal operands are `const` and `sym`, and the only legal options are `raw` and `att_syntax`. In lieu of specifying operands, the `naked_asm!` within a naked function relies on the function's calling convention to determine the validity of registers.

## Documentation

The Rust Reference: https://github.com/rust-lang/reference/pull/1689
(Previous PR: https://github.com/rust-lang/reference/pull/1153)

## Tests

* [tests/run-make/naked-symbol-visiblity](https://github.com/rust-lang/rust/tree/master/tests/codegen/naked-fn) verifies that `pub`, `#[no_mangle]` and `#[linkage = "..."]` work correctly for naked functions
* [tests/codegen/naked-fn](https://github.com/rust-lang/rust/tree/master/tests/codegen/naked-fn) has tests for function alignment, use of generics, and validates the exact assembly output on linux, macos, windows and thumb
* [tests/ui/asm/naked-*](https://github.com/rust-lang/rust/tree/master/tests/ui/asm) tests for incompatible attributes, generating errors around incorrect use of `naked_asm!`, etc

## Interaction with other (unstable) features

### [fn_align](https://github.com/rust-lang/rust/issues/82232)

Combining `#[naked]` with `#[repr(align(N))]` works well, and is tested e.g. here

- https://github.com/rust-lang/rust/blob/master/tests/codegen/naked-fn/aligned.rs
- https://github.com/rust-lang/rust/blob/master/tests/codegen/naked-fn/min-function-alignment.rs

It's tested extensively because we do need to explicitly support the `repr(align)` attribute (and make sure we e.g. don't mistake powers of two for number of bytes).

## History

This feature was originally proposed in [RFC 1201](https://github.com/rust-lang/rfcs/pull/1201), filed on 2015-07-10 and accepted on 2016-03-21. Support for this feature was added in [#32410](https://github.com/rust-lang/rust/pull/32410), landing on 2016-03-23. Development languished for several years as it was realized that the semantics given in RFC 1201 were insufficiently specific. To address this, a minimal subset of naked functions was specified by [RFC 2972](https://github.com/rust-lang/rfcs/pull/2972), filed on 2020-08-07 and accepted on 2021-11-16. Prior to the acceptance of RFC 2972, all of the stricter behavior specified by RFC 2972 was implemented as a series of warn-by-default lints that would trigger on existing uses of the `naked` attribute; these lints became hard errors in [#93153](https://github.com/rust-lang/rust/pull/93153) on 2022-01-22. As a result, today RFC 2972 has completely superseded RFC 1201 in describing the semantics of the `naked` attribute.

More recently, the `naked_asm!` macro was added to replace the earlier use of a heavily restricted `asm!` invocation. The `naked_asm!` name is clearer in error messages, and provides a place for documenting the specific requirements of inline assembly in naked functions.

The implementation strategy was changed to emitting a global assembly block. In effect, an extern function

```rust
extern "C" fn foo() {
    core::arch::naked_asm!("ret")
}
```

is emitted as something similar to

```rust
core::arch::global_asm!(
    "foo:",
    "ret"
);

extern "C" {
    fn foo();
}
```

The codegen approach was chosen over the llvm naked function attribute because:

- the rust compiler can guarantee the behavior (no sneaky additional instructions, no inlining, etc.)
- behavior is the same on all backends (llvm, cranelift, gcc, etc)

Finally, there is now an allow list of compatible attributes on naked functions, so that e.g. `#[inline]` is rejected with an error. The `#[target_feature]` attribute on naked functions was later made separately unstable, because implementing it is complex and we did not want to block naked functions themselves on how target features work on them. See also https://github.com/rust-lang/rust/issues/138568.

relevant PRs for these recent changes

- https://github.com/rust-lang/rust/pull/127853
- https://github.com/rust-lang/rust/pull/128651
- https://github.com/rust-lang/rust/pull/128004
- https://github.com/rust-lang/rust/pull/138570
-
### Various historical notes

#### `noreturn`
[RFC 2972](https://github.com/rust-lang/rfcs/blob/master/text/2972-constrained-naked.md) mentions that naked functions

> must have a body which contains only a single asm!() statement which:
> iii. must contain the noreturn option.

Instead of `asm!`, the current implementation mandates that the body contain a single `naked_asm!` statement. The `naked_asm!` macro is a heavily restricted version of the `asm!` macro, making it easier to talk about and document the rules of assembly in naked functions and give dedicated error messages.

For `naked_asm!`, the behavior of the `asm!`'s `noreturn` option is implicit. The `noreturn` option means that it is UB for control flow to fall through the end of the assembly block. With `asm!`, this option is usually used for blocks that diverge (and thus have no return and can be typed as `!`). With `naked_asm!`, the intent is different: usually naked funtions do return, but they must do so from within the assembly block. The `noreturn` option was used so that the compiler would not itself also insert a `ret` instruction at the very end.

#### padding / `ud2`

A `naked_asm!` block that violates the safety assumption that control flow must not fall through the end of the assembly block is UB. Because no return instruction is emitted, whatever bytes follow the naked function will be executed, resulting in truly undefined behavior. There has been discussion whether rustc should emit an invalid instruction (e.g. `ud2`  on x86) after the `naked_asm!` block to at least fail early in the case of an invalid `naked_asm!`. It was however decided that it is more useful to guarantee that `#[naked]` functions NEVER contain any instructions besides those in the `naked_asm!` block.

# unresolved questions

None

r? ``@Amanieu``

I've validated the tests on x86_64 and aarch64
2025-04-21 18:53:15 +00:00
Chris Denton
d15c603173
Rollup merge of #137953 - RalfJung:simd-intrinsic-masks, r=WaffleLapkin
simd intrinsics with mask: accept unsigned integer masks, and fix some of the errors

It's not clear at all why the mask would have to be signed, it is anyway interpreted bitwise. The backend should just make sure that works no matter the surface-level type; our LLVM backend already does this correctly. The note of "the mask may be widened, which only has the correct behavior for signed integers" explains... nothing? Why can't the code do the widening correctly? If necessary, just cast to the signed type first...

Also while we are at it, fix the errors. For simd_masked_load/store, the errors talked about the "third argument" but they meant the first argument (the mask is the first argument there). They also used the wrong type for `expected_element`.

I have extremely low confidence in the GCC part of this PR.

See [discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/257879-project-portable-simd/topic/On.20the.20sign.20of.20masks)
2025-04-20 13:02:48 +00:00
Ralf Jung
566dfd1a0d simd intrinsics with mask: accept unsigned integer masks 2025-04-20 12:25:27 +02:00
Folkert de Vries
df8a3d5f1d
stabilize naked_functions 2025-04-20 11:18:38 +02:00
Folkert de Vries
41ddf86722
Make #[naked] an unsafe attribute 2025-04-19 00:03:35 +02:00
Matthias Krüger
1b03b826c4
Rollup merge of #139989 - durin42:llvm-21-issue-101082, r=cuviper
tests: adjust 101082 test for LLVM 21 fix

Fixes #139987.
2025-04-18 05:17:54 +02:00
Matthias Krüger
026d56b0f6
Rollup merge of #139967 - jieyouxu:auxiliary, r=wesleywiser
Introduce and use specialized `//@ ignore-auxiliary` for test support files instead of using `//@ ignore-test`

### Summary

Add a semantically meaningful directive for ignoring test *auxiliary* files. This is for auxiliary files that *participate* in actual tests but should not be built by `compiletest` (i.e. these files are involved through `mod xxx;` or `include!()` or `#[path = "xxx"]`, etc.).

### Motivation

A specialized directive like `//@ ignore-auxiliary` makes it way easier to audit disabled tests via `//@ ignore-test`.
  - These support files cannot use the canonical `auxiliary/` dir because they participate in module resolution or are included, or their relative paths can be important for test intention otherwise.

Follow-up to:
- #139705
- #139783
- #139740

See also discussions in:

- [#t-compiler > Directive name for non-test aux files?](512773817)
- [#t-compiler > Handling disabled `//@ ignore-test` tests](512005974)
- [#t-compiler/meetings > [steering] 2025-04-11 Dealing with disabled tests](511717981)

### Remarks on remaining unconditionally disabled tests under `tests/`

After this PR, against commit 79a272c640, only **14** remaining test files are disabled through `//@ ignore-test`:

<details>
<summary>Remaining `//@ ignore-test` files under `tests/`</summary>

```
tests/debuginfo/drop-locations.rs
4://@ ignore-test (broken, see #128971)

tests/rustdoc/macro-document-private-duplicate.rs
1://@ ignore-test (fails spuriously, see issue #89228)

tests/rustdoc/inline_cross/assoc-const-equality.rs
3://@ ignore-test (FIXME: #125092)

tests/ui/match/issue-27021.rs
7://@ ignore-test (#54987)

tests/ui/match/issue-26996.rs
7://@ ignore-test (#54987)

tests/ui/issues/issue-49298.rs
9://@ ignore-test (#54987)

tests/ui/issues/issue-59756.rs
2://@ ignore-test (rustfix needs multiple suggestions)

tests/ui/precondition-checks/write.rs
5://@ ignore-test (unimplemented)

tests/ui/precondition-checks/read.rs
5://@ ignore-test (unimplemented)

tests/ui/precondition-checks/write_bytes.rs
5://@ ignore-test (unimplemented)

tests/ui/explicit-tail-calls/drop-order.rs
2://@ ignore-test: tail calls are not implemented in rustc_codegen_ssa yet, so this causes 🧊

tests/ui/panics/panic-short-backtrace-windows-x86_64.rs
3://@ ignore-test (#92000)

tests/ui/json/json-bom-plus-crlf-multifile-aux.rs
3://@ ignore-test Not a test. Used by other tests

tests/ui/traits/next-solver/object-soundness-requires-generalization.rs
2://@ ignore-test (see #114196)
```
</details>

Of these, most are either **unimplemented**, or **spurious**, or **known-broken**. The outstanding one is `tests/ui/json/json-bom-plus-crlf-multifile-aux.rs` which I did not want to touch in *this* PR -- that aux file has load-bearing BOM and carriage returns and byte offset matters. I think those test files that require special encoding / BOM probably are better off as `run-make` tests. See #139968 for that aux file.

### Review advice

- Best reviewed commit-by-commit.
- The directive name diverged from the most voted `//@ auxiliary` because I think that's easy to confuse with `//@ aux-{crate,dir}`.

r? compiler
2025-04-17 21:53:25 +02:00
Matthias Krüger
87a163523f
Rollup merge of #139351 - EnzymeAD:autodiff-batching2, r=oli-obk
Autodiff batching2

~I will rebase it once my first PR landed.~ done.
This autodiff batch mode is more similar to scalar autodiff, since it still only takes one shadow argument.
However, that argument is supposed to be `width` times larger.

r? `@oli-obk`

Tracking:

- https://github.com/rust-lang/rust/issues/124509
2025-04-17 21:53:23 +02:00
Augie Fackler
d3b167493e tests: adjust 101082 test for LLVM 21 fix
Fixes #139987.
2025-04-17 15:11:21 -04:00
Jieyou Xu
89cac55bb8
tests: use //@ ignore-auxiliary with backlinked primary test file 2025-04-17 19:45:28 +08:00
bors
15c4ccef03 Auto merge of #139940 - matthiaskrgr:rollup-rd4d3fn, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #135340 (Add `explicit_extern_abis` Feature and Enforce Explicit ABIs)
 - #139440 (rustc_target: RISC-V: feature addition batch 2)
 - #139667 (cfi: Remove #[no_sanitize(cfi)] for extern weak functions)
 - #139828 (Don't require rigid alias's trait to hold)
 - #139854 (Improve parse errors for stray lifetimes in type position)
 - #139889 (Clean UI tests 3 of n)
 - #139894 (Fix `opt-dist` CLI flag and make it work without LLD)
 - #139900 (stepping into impls for normalization is unproductive)
 - #139915 (replace some #[rustc_intrinsic] usage with use of the libcore declarations)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-17 04:52:34 +00:00
Matthias Krüger
cbe469a8b1
Rollup merge of #139917 - folkertdev:fn-align-multiple, r=jdonszelmann
fix for multiple `#[repr(align(N))]` on functions

tracking issue: https://github.com/rust-lang/rust/issues/82232
fixes https://github.com/rust-lang/rust/issues/132464

The behavior of align is specified at https://doc.rust-lang.org/reference/type-layout.html#r-layout.repr.alignment.align

> For align, if the specified alignment is less than the alignment of the type without the align modifier, then the alignment is unaffected.

So in effect that means that the maximum of the specified alignments should be chosen. That is also the current behavior for `align` on ADTs:

```rust
#![feature(fn_align)]

#[repr(C,  align(32), align(64))]
struct Foo {
    x: u64,
}

const _: () = assert!(core::mem::align_of::<Foo>() == 64);

// See the godbolt LLVM output: the alignment of this function is 32
#[no_mangle]
#[repr(align(32))]
#[repr(align(64))]
fn foo() {}

// The current logic just picks the first alignment: the alignment of this function is 64
#[no_mangle]
#[repr(align(64))]
#[repr(align(32))]
fn bar() {}
```

https://godbolt.org/z/scco435jE

afa859f812/compiler/rustc_middle/src/ty/mod.rs (L1529-L1532)

The https://github.com/rust-lang/rust/issues/132464 issue is really about parsing/representing the attribute, which has already been improved and now uses the "parse, don't validate" attribute approach. That means the behavior is already different from what the issue describes: on current `main`, the first value is chosen. This PR fixes a logic error, where we just did not check for the effect of two or more `align` modifiers. In combination, that fixes the issue.

cc ``@jdonszelmann`` if you do have further thoughs here
2025-04-17 00:14:28 +02:00
Manuel Drehwald
d7c0c32827 passing test for dualv 2025-04-16 17:13:50 -04:00
Ralf Jung
face4716ee replace some #[rustc_intrinsic] usage with use of the libcore declarations 2025-04-16 14:48:20 +02:00
Folkert de Vries
a6dcd519f3
fix multiple #[repr(align(N))] on functions 2025-04-16 12:16:40 +02:00
Christian Poveda
9dbd2bb85c
Include optional dso_local marker for functions in enum-match.rs 2025-04-15 22:18:10 -05:00
Jacob Pratt
4a1d0cd1bd
Rollup merge of #139718 - folkertdev:unsafe-attributes-earlier-editions, r=fmease
enforce unsafe attributes in pre-2024 editions by default

New unsafe attributes should emit an error when used without the `unsafe(...)` in all editions.

The `no_mangle`, `link_section` and `export_name` attributes are exceptions, and can still be used without an unsafe in earlier editions. The only attributes for which this change is relevant right now are `#[ffi_const]` and `#[ffi_pure]`.

This change is required for making `#[unsafe(naked)]` sound in pre-2024 editions.
2025-04-13 23:57:40 -04:00
bors
092a284ba0 Auto merge of #139746 - ChrisDenton:rollup-eq08b2e, r=ChrisDenton
Rollup of 10 pull requests

Successful merges:

 - #138972 (std: Fix build for NuttX targets)
 - #139177 (Use -C target-cpu=z13 on s390x vector test)
 - #139511 (libtest: Pass the test's panic payload as Option instead of Result)
 - #139605 (update ```miniz_oxide``` to 0.8.8)
 - #139618 (compiletest: Make `SUGGESTION` annotations viral)
 - #139677 (Fix profiler_builtins build script to handle full path to profiler lib)
 - #139683 (Use `with_native_path` for Windows)
 - #139710 (Move `args` into `std::sys`)
 - #139721 (End all lines in src/stage0 with trailing newline)
 - #139726 (Move `select_unpredictable` to the `hint` module)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-13 14:56:44 +00:00
Chris Denton
f1d0b9c645
Rollup merge of #139726 - Amanieu:select_unpredictable_hint, r=dtolnay
Move `select_unpredictable` to the `hint` module

There has been considerable discussion in both the ACP (rust-lang/libs-team#468) and tracking issue (#133962) about whether the `bool::select_unpredictable` method should be in `core::hint` instead.

I believe this is the right move for the following reasons:
- The documentation explicitly says that it is a hint, not a codegen guarantee.
- `bool` doesn't have a corresponding `select` method, and I don't think we should be adding one.
- This shouldn't be something that people reach for with auto-completion unless they specifically understand the interactions with branch prediction. Using conditional moves can easily make code *slower* by preventing the CPU from speculating past the condition due to the data dependency.
- Although currently `core::hint` only contains no-ops, this isn't a hard rule (for example `unreachable_unchecked` is a bit of a gray area). The documentation only status that the module contains "hints to compiler that affects how code should be emitted or optimized". This is consistent with what `select_unpredictable` does.
2025-04-13 11:48:20 +00:00
Chris Denton
f1b31ae8df
Rollup merge of #139177 - fneddy:fix_s390x_codegen_bswap, r=Mark-Simulacrum
Use -C target-cpu=z13 on s390x vector test

currently we see a regression in the `dont-shuffle-bswaps.rs` on s390x. This is due to, the default s390x cpu is set to z10 [here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_target/src/spec/targets/s390x_unknown_linux_gnu.rs#L9) which does not have vector instructions implemented. To make the test pass we need to create an extra test revision and set target-cpu at least to `z13`.
2025-04-13 11:48:16 +00:00
bors
53d4476111 Auto merge of #138881 - scottmcm:more-chaining-ord, r=Mark-Simulacrum
Use the chaining methods on PartialOrd for slices too

#138135 added these doc-hidden trait methods to improve the tuple codegen.  This PR adds more implementations and callers so that the codegen for slice (and array) comparisons also improves.
2025-04-13 11:47:23 +00:00
Scott McMurray
756670f40e Extend the chaining logic to slices too 2025-04-12 22:10:17 -07:00
Amanieu d'Antras
5d90ccb0fa Move select_unpredictable to the hint module 2025-04-13 01:34:25 +01:00
Folkert de Vries
f472cc8cd4
error on unsafe attributes in pre-2024 editions
the `no_mangle`, `link_section` and `export_name` attributes are exceptions, and can still be used without an unsafe in earlier editions
2025-04-13 01:22:59 +02:00
bors
1bc56185ee Auto merge of #139430 - scottmcm:polymorphic-array-into-iter, r=cuviper
Some checks failed
Post merge analysis / analysis (push) Has been cancelled
Polymorphize `array::IntoIter`'s iterator impl

Today we emit all the iterator methods for every different array width.  That's wasteful since the actual array length never even comes into it -- the indices used are from the separate `alive: IndexRange` field, not even the `N` const param.

This PR switches things so that an `array::IntoIter<T, N>` stores a `PolymorphicIter<[MaybeUninit<T>; N]>`, which we *unsize* to `PolymorphicIter<[MaybeUninit<T>]>` and call methods on that non-`Sized` type for all the iterator methods.

That also necessarily makes the layout consistent between the different lengths of arrays, because of the unsizing.  Compare that to today <https://rust.godbolt.org/z/Prb4xMPrb>, where different widths can't even be deduped because the offset to the indices is different for different array widths.
2025-04-11 23:21:31 +00:00
bors
71b68da1bd Auto merge of #139578 - ferrocene:pa-compiletest-edition, r=jieyouxu
Fix breakage when running compiletest with `--test-args=--edition=2015`

Compiletest has an `--edition` flag to change the default edition tests are run with. Unfortunately no test suite successfully executes when that flag is passed. If the edition is set to something greater than 2015 the breakage is expected, since the test suite currently supports only edition 2015 (Ferrous Systems will open an MCP about fixing that soonish). Surprisingly, the test suite is also broken if `--edition=2015` is passed to compiletest. This PR focuses on fixing the latter.

This PR fixes the two categories of failures happening when `--edition=2015` is passed:

* Some edition-specific tests set their edition through `//@ compile-flags` instead of `//@ edition`. Compiletest doesn't parse the compile flags, so it would see no `//@ edition` and add another `--edition` flag, leading to a rustc error.
* Compiletest would add the edition after `//@ compile-flags`, while some tests depend on flags passed to `//@ compile-flags` being the last flags in the rustc invocation.

Note that for the first category, I opted to manually go and replace all `//@ compile-flags` setting an edition with an explicit `//@ edition`. We could've changed compiletest to instead check whether an edition was set in `//@ compile-flags`, but I thought it was better to enforce a consistent way to set the edition in tests.

I also added the edition to the stamp, so that changing `--edition` results in tests being re-executed.

r? `@jieyouxu`
2025-04-11 10:53:45 +00:00
Pietro Albini
3ebf1c2e67
didn't catch this test failure, whoops 2025-04-11 09:57:21 +02:00
Stuart Cook
45ebc4060b
Rollup merge of #137447 - folkertdev:simd-extract-insert-dyn, r=scottmcm
add `core::intrinsics::simd::{simd_extract_dyn, simd_insert_dyn}`

fixes https://github.com/rust-lang/rust/issues/137372

adds `core::intrinsics::simd::{simd_extract_dyn, simd_insert_dyn}`, which contrary to their non-dyn counterparts allow a non-const index. Many platforms (but notably not x86_64 or aarch64) have dedicated instructions for this operation, which stdarch can emit with this change.

Future work is to also make the `Index` operation on the `Simd` type emit this operation, but the intrinsic can't be used directly. We'll need some MIR shenanigans for that.

r? `@ghost`
2025-04-11 13:31:43 +10:00
bors
0fe8f3454d Auto merge of #137412 - scottmcm:redo-swap, r=cuviper
Ensure `swap_nonoverlapping` is really always untyped

This replaces #134954, which was arguably overcomplicated.

## Fixes #134713

Actually using the type passed to `ptr::swap_nonoverlapping` for anything other than its size + align turns out to not work, so this goes back to always erasing the types down to just bytes.

(Except in `const`, which keeps doing the same thing as before to preserve `@RalfJung's` fix from #134689)

## Fixes #134946

I'd previously moved the swapping to use auto-vectorization *on bytes*, but someone pointed out on Discord that the tail loop handling from that left a whole bunch of byte-by-byte swapping around.  This goes back to manual tail handling to avoid that, then still triggers auto-vectorization on pointer-width values.  (So you'll see `<4 x i64>` on `x86-64-v3` for example.)
2025-04-10 20:19:11 +00:00
Folkert de Vries
59c55339af
add simd_insert_dyn and simd_extract_dyn 2025-04-10 21:22:07 +02:00
bors
7d7de5bf3c Auto merge of #139088 - spastorino:ergonomic-ref-counting-2, r=nikomatsakis
Ergonomic ref counting: optimize away clones when possible

This PR build on top of https://github.com/rust-lang/rust/pull/134797. It optimizes codegen of ergonomic ref-counting when the type being `use`d is only known to be copy after monomorphization. We avoid codening a clone and generate bitwise copy instead.

RFC: https://github.com/rust-lang/rfcs/pull/3680
Tracking issue: https://github.com/rust-lang/rust/issues/132290
Project goal: https://github.com/rust-lang/rust-project-goals/issues/107

r? `@nikomatsakis`

This PR could better sit on top of https://github.com/rust-lang/rust/pull/131650 but as it did not land yet I've decided to just do minimal changes. It may be the case that doing what I'm doing regress the performance and we may need to go the full route of https://github.com/rust-lang/rust/pull/131650.
cc `@saethlin` in this regard.
2025-04-10 09:08:23 +00:00
Pietro Albini
cd371b90e2
replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
Scott McMurray
4207c786e7 PR feedback 2025-04-09 21:44:59 -07:00
Scott McMurray
63dcac8423 skip tests/codegen/swap-small-types when debug assertions are on
In `swap_nonoverlapping_short` there's a new `debug_assert!`, and if that's enabled then the `alloca`s don't optimize out.
2025-04-09 10:44:49 -07:00
Scott McMurray
50d0ce1b42 Ensure swap_nonoverlapping is really always untyped 2025-04-09 09:09:37 -07:00
lincot
09d5bcf1ad
Speed up String::push and String::insert
Improve performance of `String` methods by avoiding unnecessary memcpy
for the character bytes, with added codegen check to ensure compliance.
2025-04-09 13:06:10 +03:00
Stuart Cook
7ffa56c3a3
Rollup merge of #139098 - scottmcm:assert-impossible-tags, r=WaffleLapkin
Tell LLVM about impossible niche tags

I was trying to find a better way of emitting discriminant calculations, but sadly had no luck.

So here's a fairly small PR with the bits that did seem worth bothering:

1. As the [`TagEncoding::Niche` docs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.TagEncoding.html#variant.Niche) describe, it's possible to end up with a dead value in the input that's not already communicated via the range parameter attribute nor the range load metadata attribute.  So this adds an `llvm.assume` in non-debug mode to tell LLVM about that.  (That way it can tell that the sides of the `select` have disjoint possible values.)

2. I'd written a bunch more tests, or at least made them parameterized, in the process of trying things out, so this checks in those tests to hopefully help future people not trip on the same weird edge cases, like when the tag type is `i8` but yet there's still a variant index and discriminant of `258` which doesn't fit in that tag type because the enum is really weird.
2025-04-08 20:55:03 +10:00
Scott McMurray
502f7f9c24 Address PR feedback 2025-04-07 18:12:06 -07:00
Santiago Pastorino
20f93c9e8e
Add codegen test to be sure we get rid of uneeded clones after monomorphization 2025-04-07 16:53:11 -03:00
Stuart Cook
5863b426b9
Rollup merge of #139465 - EnzymeAD:autodiff-sret, r=oli-obk
add sret handling for scalar autodiff

r? `@oli-obk`

Fixing one of the todo's which I left in my previous batching PR.
This one handles sret for scalar autodiff.  `sret` mostly shows up when we try to return a lot of scalar floats.
People often start testing autodiff which toy functions which just use a few scalars as inputs and outputs, and those were the most likely to be affected by this issue. So this fix should make learning/teaching hopefully a bit easier.

Tracking:

- https://github.com/rust-lang/rust/issues/124509
2025-04-07 22:29:21 +10:00
Manuel Drehwald
ca5bea3ebb move old tests, add sret test 2025-04-07 07:11:52 -04:00
Eduard Stefes
15e1a6676c Use -C target-cpu=z13 on s390x vector test
The default s390x cpu(z10) does not have vector support. Setting
target-cpu at least to z13 enables vectorisation for s390x architecture
and makes the tests pass.
2025-04-07 09:36:56 +02:00
Bennet Bleßmann
7dd57f085c
update/bless tests 2025-04-06 21:41:47 +02:00
Stuart Cook
f4aa209e20
Rollup merge of #139438 - Zalathar:fix-test-122600, r=scottmcm
Prevent a test from seeing forbidden numbers in the rustc version

The final CHECK-NOT directive in this test was able to see past the end of the enclosing function, and find the substring `753` or `754` in the git hash in the rustc version number, causing false failures in CI whenever the git hash happens to contain those digits in sequence.

Adding an explicit check for `ret` prevents the CHECK-NOT directive from seeing past the end of the function.

---

Manually tested by adding `// CHECK-NOT: rustc` after the existing CHECK-NOT directives, and demonstrating that the new check prevents it from seeing the rustc version string.
2025-04-06 16:21:03 +10:00
Scott McMurray
51e67e21cf LLVM18 compatibility fixes in the tests 2025-04-05 19:54:50 -07:00
Scott McMurray
1f06a6a252 Tell LLVM about impossible niche tags 2025-04-05 19:54:47 -07:00
Zalathar
f6afb35c61 Prevent a test from seeing forbidden numbers in the rustc version
The final CHECK-NOT directive in this test was able to see past the end of the
enclosing function, and find the substring 753 or 754 in the git hash in the
rustc version number, causing false failures in CI.

Adding an explicit check for `ret` prevents the CHECK-NOT directive from seeing
past the end of the function.
2025-04-06 12:38:20 +10:00
Scott McMurray
e30cb329d8 Polymorphize array::IntoIter's iterator impl 2025-04-05 17:55:24 -07:00
Josh Stone
12167d7064 Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
Matthias Krüger
543160dd62
Rollup merge of #138368 - rcvalle:rust-kcfi-arity, r=davidtwco
KCFI: Add KCFI arity indicator support

Adds KCFI arity indicator support to the Rust compiler (see https://github.com/rust-lang/rust/issues/138311, https://github.com/llvm/llvm-project/pull/121070, and https://lore.kernel.org/lkml/CANiq72=3ghFxy8E=AU9p+0imFxKr5iU3sd0hVUXed5BA+KjdNQ@mail.gmail.com/).
2025-04-05 10:18:03 +02:00