about summary refs log tree commit diff
path: root/tests/codegen
AgeCommit message (Collapse)AuthorLines
2025-07-22Rename `tests/codegen` into `tests/codegen-llvm`Guillaume Gomez-31706/+0
2025-07-22Rename `tests/assembly` into `tests/assembly-llvm`Guillaume Gomez-1/+1
2025-07-22Rollup merge of #144080 - jieyouxu:realign, r=BoxyUwU许杰友 Jieyou Xu (Joe)-31/+40
Mitigate `#[align]` name resolution ambiguity regression with a rename Mitigates beta regression rust-lang/rust#143834 after a beta backport. ### Background on the beta regression The name resolution regression arises due to rust-lang/rust#142507 adding a new feature-gated built-in attribute named `#[align]`. However, unfortunately even [introducing new feature-gated unstable built-in attributes can break user code](https://www.github.com/rust-lang/rust/issues/134963) such as ```rs macro_rules! align { () => { /* .. */ }; } pub(crate) use align; // `use` here becomes ambiguous ``` ### Mitigation approach This PR renames `#[align]` to `#[rustc_align]` to mitigate the beta regression by: 1. Undoing the introduction of a new built-in attribute with a common name, i.e. `#[align]`. 2. Renaming `#[align]` to `#[rustc_align]`. The renamed attribute being `rustc_align` will not introduce new stable breakages, as attributes beginning with `rustc` are reserved and perma-unstable. This does mean existing nightly code using `fn_align` feature will additionally need to specify `#![feature(rustc_attrs)]`. This PR is very much a short-term mitigation to alleviate time pressure from having to fully fix the current limitation of inevitable name resolution regressions that would arise from adding any built-in attributes. Long-term solutions are discussed in [#t-lang > namespacing macro attrs to reduce conflicts with new adds](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/namespacing.20macro.20attrs.20to.20reduce.20conflicts.20with.20new.20adds/with/529249622). ### Alternative mitigation options [Various mitigation options were considered during the compiler triage meeting](https://github.com/rust-lang/rust/issues/143834#issuecomment-3084415277), and those consideration are partly reproduced here: - Reverting the PR doesn't seem very minimal/trivial, and carries risks of its own. - Rename to a less-common but aim-to-stabilization name is itself not safe nor convenient, because (1) that risks introducing new regressions (i.e. ambiguity against the new name), and (2) lang would have to FCP the new name hastily for the mitigation to land timely and have a chance to be backported. This also makes the path towards stabilization annoying. - Rename the attribute to a rustc attribute, which will be perma-unstable and does not cause new ambiguities in stable code. - This alleviates the time pressure to address *this* regression, or for lang to have to rush an FCP for some new name that can still break user code. - This avoids backing out a whole implementation. ### Review advice This PR is best reviewed commit-by-commit. - Commit 1 adds a test `tests/ui/attributes/fn-align-nameres-ambiguity-143834.rs` which demonstrates the current name resolution regression re. `align`. This test fails against current master. - Commit 2 carries out the renames and test reblesses. Notably, commit 2 will cause `tests/ui/attributes/fn-align-nameres-ambiguity-143834.rs` to change from fail (nameres regression) to pass. This PR, if the approach still seems acceptable, will need a beta-backport to address the beta regression.
2025-07-22Rollup merge of #142097 - ZuseZ4:offload-host1, r=oli-obk许杰友 Jieyou Xu (Joe)-0/+80
gpu offload host code generation r? ghost This will generate most of the host side code to use llvm's offload feature. The first PR will only handle automatic mem-transfers to and from the device. So if a user calls a kernel, we will copy inputs back and forth, but we won't do the actual kernel launch. Before merging, we will use LLVM's Info infrastructure to verify that the memcopies match what openmp offloa generates in C++. `LIBOMPTARGET_INFO=-1 ./my_rust_binary` should print that a memcpy to and later from the device is happening. A follow-up PR will generate the actual device-side kernel which will then do computations on the GPU. A third PR will implement manual host2device and device2host functionality, but the goal is to minimize cases where a user has to overwrite our default handling due to performance issues. I'm trying to get a full MVP out first, so this just recognizes GPU functions based on magic names. The final frontend will obviously move this over to use proper macros, like I'm already doing it for the autodiff work. This work will also be compatible with std::autodiff, so one can differentiate GPU kernels. Tracking: - https://github.com/rust-lang/rust/issues/131513
2025-07-20Ban projecting into SIMD types [MCP838]Scott McMurray-31/+0
2025-07-20So many test updates x_xScott McMurray-515/+132
2025-07-19Split repeat-operand codegen testScott McMurray-11/+28
Looks like the output it's looking for can be in different orders, so separate tests will fix that.
2025-07-19Allow `Rvalue::Repeat` to return true in `rvalue_creates_operand` tooScott McMurray-0/+39
The conversation in 143502 made be realize how easy this is to handle, since the only possibilty is ZSTs -- everything else ends up with the destination being `LocalKind::Memory` and thus doesn't call `codegen_rvalue_operand` at all. This gets us perilously close to a world where `rvalue_creates_operand` only ever returns true. I'll try out such a world next :)
2025-07-19Auto merge of #143784 - scottmcm:enums-again-new-ex2, r=dianqkbors-10/+539
Simplify discriminant codegen for niche-encoded variants which don't wrap across an integer boundary Inspired by rust-lang/rust#139729, this attempts to be a much-simpler and more-localized change while still making a difference. (Specifically, this does not try to solve the problem with select-sinking, leaving that to be fixed by https://github.com/llvm/llvm-project/issues/134024 -- once it gets released -- instead of in rustc's codegen.) What this *does* improve is checking for the variant in a 3+ variant enum when that variant is the type providing the niche. Something like `if let Foo::WithBool(_) = ...` previously compiled to `ugt(add(x, -2), 2)`, which is non-trivial to think about because it's depending on the unsigned wrapping to shift the 0/1 up above 2. With this PR it compiles to just `ult(x, 2)`, which is probably what you'd have written yourself if you were doing it by hand to look for "is this byte a bool?". That's done by leaving most of the codegen alone, but adding a couple new special cases to the `is_niche` check. The default looks at the relative discriminant, but in the common cases where there's no wraparound involved, we can just check the original value, rather than the offsetted one. The first commit just adds some tests, so the best way to see the effect of this change is to look at the second commit and how it updates the test expectations.
2025-07-18add gpu offload codegen host side testManuel Drehwald-0/+80
2025-07-19Mitigate `#[align]` name resolution ambiguity regression with a renameJieyou Xu-31/+40
From `#[align]` -> `#[rustc_align]`. Attributes starting with `rustc` are always perma-unstable and feature-gated by `feature(rustc_attrs)`. See regression RUST-143834. For the underlying problem where even introducing new feature-gated unstable built-in attributes can break user code such as ```rs macro_rules! align { () => { /* .. */ }; } pub(crate) use align; // `use` here becomes ambiguous ``` refer to RUST-134963. Since the `#[align]` attribute is still feature-gated by `feature(fn_align)`, we can rename it as a mitigation. Note that `#[rustc_align]` will obviously mean that current unstable user code using `feature(fn_aling)` will need additionally `feature(rustc_attrs)`, but this is a short-term mitigation to buy time, and is expected to be changed to a better name with less collision potential. See <https://rust-lang.zulipchat.com/#narrow/channel/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202025-07-17/near/529290371> where mitigation options were considered.
2025-07-18Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-errorsMatthias Krüger-0/+47
fix `-Zsanitizer=kcfi` on `#[naked]` functions fixes https://github.com/rust-lang/rust/issues/143266 With `-Zsanitizer=kcfi`, indirect calls happen via generated intermediate shim that forwards the call. The generated shim preserves the attributes of the original, including `#[unsafe(naked)]`. The shim is not a naked function though, and violates its invariants (like having a body that consists of a single `naked_asm!` call). My fix here is to match on the `InstanceKind`, and only use `codegen_naked_asm` when the instance is not a `ReifyShim`. That does beg the question whether there are other `InstanceKind`s that could come up. As far as I can tell the answer is no: calling via `dyn` seems to work find, and `#[track_caller]` is disallowed in combination with `#[naked]`. r? codegen ````@rustbot```` label +A-naked cc ````@maurer```` ````@rcvalle````
2025-07-17Rollup merge of #143880 - ↵Matthias Krüger-0/+22
Enselic:fn-parameters-on-different-lines-debuginfo, r=wesleywiser tests: Test line debuginfo for linebreaked function parameters Closes rust-lang/rust#45010 which just [E-needs-test](https://github.com/rust-lang/rust/issues/45010#issuecomment-1187565077). To verify that this is actually a regression test, do this, which is a simplified and adapted version of what compiletest does for 1.39 and then 1.88: ```sh for toolchain in 1.39 1.88; do echo -e "\nWith $toolchain:" rustc +$toolchain "tests/codegen/fn-parameters-on-different-lines-debuginfo.rs" "--emit" "llvm-ir" "-o" "/tmp/fn-parameters-on-different-lines-debuginfo.ll" "-g" "-Copt-level=0" "build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/tmp/fn-parameters-on-different-lines-debuginfo.ll" "tests/codegen/fn-parameters-on-different-lines-debuginfo.rs" "--check-prefix=CHECK" "--dump-input-context" "100" && echo OK || echo FAIL done ``` which gives ``` With 1.39: FAIL With 1.88: OK ``` <details> <summary>Click to expand full output</summary> ``` $ for toolchain in 1.39 1.88; do echo -e "\nWith $toolchain:" rustc +$toolchain "tests/codegen/fn-parameters-on-different-lines-debuginfo.rs" "--emit" "llvm-ir" "-o" "/tmp/fn-parameters-on-different-lines-debuginfo.ll" "-g" "-Copt-level=0" "build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/tmp/fn-parameters-on-different-lines-debuginfo.ll" "tests/codegen/fn-parameters-on-different-lines-debuginfo.rs" "--check-prefix=CHECK" "--dump-input-context" "100" && echo OK || echo FAIL done With 1.39: tests/codegen/fn-parameters-on-different-lines-debuginfo.rs:16:16: error: CHECK-SAME: expected string not found in input // CHECK-SAME: line: 10 ^ /tmp/fn-parameters-on-different-lines-debuginfo.ll:69:42: note: scanning from here !10 = !DILocalVariable(name: "x", arg: 1, scope: !5, file: !3, line: 1, type: !9) ^ /tmp/fn-parameters-on-different-lines-debuginfo.ll:69:64: note: possible intended match here !10 = !DILocalVariable(name: "x", arg: 1, scope: !5, file: !3, line: 1, type: !9) ^ Input file: /tmp/fn-parameters-on-different-lines-debuginfo.ll Check file: tests/codegen/fn-parameters-on-different-lines-debuginfo.rs -dump-input=help explains the following input dump. Input was: <<<<<< 1: ; ModuleID = 'fn_parameters_on_different_lines_debuginfo.3a1fbbbh-cgu.0' 2: source_filename = "fn_parameters_on_different_lines_debuginfo.3a1fbbbh-cgu.0" 3: target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 4: target triple = "x86_64-unknown-linux-gnu" 5: 6: ``@str.0`` = internal constant [59 x i8] c"tests/codegen/fn-parameters-on-different-lines-debuginfo.rs" 7: ``@str.1`` = internal constant [28 x i8] c"attempt to add with overflow" 8: ``@panic_loc.2`` = private unnamed_addr constant { { [0 x i8]*, i64 }, { [0 x i8]*, i64 }, i32, i32 } { { [0 x i8]*, i64 } { [0 x i8]* bitcast ([28 x i8]* ``@str.1`` to [0 x i8]*), i64 28 }, { [0 x i8]*, i64 } { [0 x i8]* bitcast ([59 x i8]* ``@str.0`` to [0 x i8]*), i64 59 }, i32 13, i32 3 }, align 8 9: ``@__rustc_debug_gdb_scripts_section__`` = linkonce_odr unnamed_addr constant [34 x i8] c"\01gdb_load_rust_pretty_printers.py\00", section ".debug_gdb_scripts", align 1 10: 11: ; fn_parameters_on_different_lines_debuginfo::foo 12: ; Function Attrs: nonlazybind uwtable 13: define i32 ``@_ZN42fn_parameters_on_different_lines_debuginfo3foo17ha98e7c29f4ed8d60E(i32,`` i32) unnamed_addr #0 !dbg !5 { 14: start: 15: %y = alloca i32, align 4 16: %x = alloca i32, align 4 17: store i32 %0, i32* %x, align 4 18: call void ``@llvm.dbg.declare(metadata`` i32* %x, metadata !10, metadata !DIExpression()), !dbg !11 19: store i32 %1, i32* %y, align 4 20: call void ``@llvm.dbg.declare(metadata`` i32* %y, metadata !12, metadata !DIExpression()), !dbg !11 21: %2 = load i32, i32* %x, align 4, !dbg !13 22: %3 = load i32, i32* %y, align 4, !dbg !14 23: %4 = call { i32, i1 } ``@llvm.sadd.with.overflow.i32(i32`` %2, i32 %3), !dbg !13 24: %5 = extractvalue { i32, i1 } %4, 0, !dbg !13 25: %6 = extractvalue { i32, i1 } %4, 1, !dbg !13 26: %7 = call i1 ``@llvm.expect.i1(i1`` %6, i1 false), !dbg !13 27: br i1 %7, label %panic, label %bb1, !dbg !13 28: 29: bb1: ; preds = %start 30: ret i32 %5, !dbg !15 31: 32: panic: ; preds = %start 33: ; call core::panicking::panic 34: call void ``@_ZN4core9panicking5panic17h2f49f09cf859b728E({`` [0 x i64], { [0 x i8]*, i64 }, [0 x i64], { [0 x i8]*, i64 }, [0 x i32], i32, [0 x i32], i32, [0 x i32] }* noalias readonly align 8 dereferenceable(40) bitcast ({ { [0 x i8]*, i64 }, { [0 x i8]*, i64 }, i32, i32 }* ``@panic_loc.2`` to { [0 x i64], { [0 x i8]*, i64 }, [0 x i64], { [0 x i8]*, i64 }, [0 x i32], i32, [0 x i32], i32, [0 x i32] }*)), !dbg !13 35: unreachable, !dbg !13 36: } 37: 38: ; Function Attrs: nounwind readnone speculatable 39: declare void ``@llvm.dbg.declare(metadata,`` metadata, metadata) #1 40: 41: ; Function Attrs: nounwind readnone speculatable 42: declare { i32, i1 } ``@llvm.sadd.with.overflow.i32(i32,`` i32) #1 43: 44: ; Function Attrs: nounwind readnone 45: declare i1 ``@llvm.expect.i1(i1,`` i1) #2 46: 47: ; core::panicking::panic 48: ; Function Attrs: cold noinline noreturn nonlazybind uwtable 49: declare void ``@_ZN4core9panicking5panic17h2f49f09cf859b728E({`` [0 x i64], { [0 x i8]*, i64 }, [0 x i64], { [0 x i8]*, i64 }, [0 x i32], i32, [0 x i32], i32, [0 x i32] }* noalias readonly align 8 dereferenceable(40)) unnamed_addr #3 50: 51: attributes #0 = { nonlazybind uwtable "probe-stack"="__rust_probestack" "target-cpu"="x86-64" } 52: attributes #1 = { nounwind readnone speculatable } 53: attributes #2 = { nounwind readnone } 54: attributes #3 = { cold noinline noreturn nonlazybind uwtable "probe-stack"="__rust_probestack" "target-cpu"="x86-64" } 55: 56: !llvm.module.flags = !{!0, !1} 57: !llvm.dbg.cu = !{!2} 58: 59: !0 = !{i32 2, !"RtLibUseGOT", i32 1} 60: !1 = !{i32 2, !"Debug Info Version", i32 3} 61: !2 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !3, producer: "clang LLVM (rustc version 1.39.0 (4560ea788 2019-11-04))", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4) 62: !3 = !DIFile(filename: "tests/codegen/fn-parameters-on-different-lines-debuginfo.rs", directory: "/home/martin/src/rust") 63: !4 = !{} 64: !5 = distinct !DISubprogram(name: "foo", linkageName: "_ZN42fn_parameters_on_different_lines_debuginfo3foo17ha98e7c29f4ed8d60E", scope: !6, file: !3, line: 9, type: !7, scopeLine: 9, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, templateParams: !4, retainedNodes: !4) 65: !6 = !DINamespace(name: "fn_parameters_on_different_lines_debuginfo", scope: null) 66: !7 = !DISubroutineType(types: !8) 67: !8 = !{!9, !9, !9} 68: !9 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) 69: !10 = !DILocalVariable(name: "x", arg: 1, scope: !5, file: !3, line: 1, type: !9) same:16'0 X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found same:16'1 ? possible intended match 70: !11 = !DILocation(line: 1, scope: !5) same:16'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 71: !12 = !DILocalVariable(name: "y", arg: 2, scope: !5, file: !3, line: 1, type: !9) same:16'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 72: !13 = !DILocation(line: 13, column: 2, scope: !5) same:16'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73: !14 = !DILocation(line: 13, column: 6, scope: !5) same:16'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 74: !15 = !DILocation(line: 13, column: 9, scope: !5) same:16'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>>>>> FAIL With 1.88: OK ``` <details>
2025-07-16add `codegen_instance_attrs` queryFolkert de Vries-6/+6
and use it for naked functions
2025-07-16fix `-Zsanitizer=kcfi` on `#[naked]` functionsFolkert de Vries-0/+47
And more broadly only codegen `InstanceKind::Item` using the naked function codegen code. Other instance kinds should follow the normal path.
2025-07-14tests: Test line debuginfo for linebreaked function parametersMartin Nordholts-0/+22
2025-07-12Simplify codegen for niche-encoded variant testsScott McMurray-35/+26
2025-07-11More discriminant codegen testsScott McMurray-0/+538
These are from 139729, updated to pass on master.
2025-07-11Rollup merge of #143718 - scottmcm:ub-transmute-is-ub, r=WaffleLapkinMatthias Krüger-17/+20
Make UB transmutes really UB in LLVM Ralf suggested in <https://github.com/rust-lang/rust/pull/143410#discussion_r2184928123> that UB transmutes shouldn't be trapping, which happened for the one path *that* PR was changing, but there's another path as well, so *this* PR changes that other path to match. r? codegen
2025-07-10Add `BuilderMethods::unreachable_nonterminator`Scott McMurray-21/+20
So places that need `unreachable` but in the middle of a basic block can call that instead of figuring out the best way to do it.
2025-07-10Auto merge of #143721 - tgross35:rollup-sjdfp6r, r=tgross35bors-1/+1
Rollup of 9 pull requests Successful merges: - rust-lang/rust#141996 (Fix `proc_macro::Ident`'s handling of `$crate`) - rust-lang/rust#142950 (mbe: Rework diagnostics for metavariable expressions) - rust-lang/rust#143011 (Make lint `ambiguous_glob_imports` deny-by-default and report-in-deps) - rust-lang/rust#143265 (Mention as_chunks in the docs for chunks) - rust-lang/rust#143270 (tests/codegen/enum/enum-match.rs: accept negative range attribute) - rust-lang/rust#143298 (`tests/ui`: A New Order [23/N]) - rust-lang/rust#143396 (Move NaN tests to floats/mod.rs) - rust-lang/rust#143398 (tidy: add support for `--extra-checks=auto:` feature) - rust-lang/rust#143644 (Add triagebot stdarch mention ping) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-10Rollup merge of #143270 - TimNN:fix-enum-match, r=nikicTrevor Gross-1/+1
tests/codegen/enum/enum-match.rs: accept negative range attribute The test current fails when `rustc` is built with HEAD LLVM: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/38097/steps/canvas?sid=0197c492-5661-4c42-8ae7-3d789e85c6ca I suspect the change was caused by https://github.com/llvm/llvm-project/commit/545cdca4883552b147a0f1adfac713f76fc22305 ``@rustbot`` label llvm-main
2025-07-10Auto merge of #143696 - oli-obk:constable-type-id2, r=RalfJungbors-3/+3
Add opaque TypeId handles for CTFE Reopen of https://github.com/rust-lang/rust/pull/142789#issuecomment-3053155043 after some bors insta-merge chaos r? `@RalfJung`
2025-07-09Make UB transmutes really UB in LLVMScott McMurray-9/+13
Ralf suggested in <https://github.com/rust-lang/rust/pull/143410#discussion_r2184928123> that UB transmutes shouldn't be trapping, which happened for the one path that PR was changing, but there's another path as well, so this PR changes that other path to match.
2025-07-09Auto merge of #143502 - scottmcm:aggregate-simd, r=oli-obkbors-9/+135
Let `rvalue_creates_operand` return true for *all* `Rvalue::Aggregate`s ~~Draft for now because it's built on Ralf's rust-lang/rust#143291~~ Inspired by https://github.com/rust-lang/rust/pull/138759#discussion_r2156375342 where I noticed that we were nearly at this point, plus the comments I was writing in rust-lang/rust#143410 that reminded me a type-dependent `true` is fine. This PR splits the `OperandRef::builder` logic out to a separate type, with the updates needed to handle SIMD as well. In doing so, that makes the existing `Aggregate` path in `codegen_rvalue_operand` capable of handing SIMD values just fine. As a result, we no longer need to do layout calculations for aggregate result types when running the analysis to determine which things can be SSA in codegen.
2025-07-09Add opaque TypeId handles for CTFEOli Scherer-3/+3
2025-07-07Let `rvalue_creates_operand` return true for *all* `Rvalue::Aggregate`sScott McMurray-9/+135
Inspired by <https://github.com/rust-lang/rust/pull/138759#discussion_r2156375342> where I noticed that we were nearly at this point, plus the comments I was writing in 143410 that reminded me a type-dependent `true` is fine. This PR splits the `OperandRef::builder` logic out to a separate type, with the updates needed to handle SIMD as well. In doing so, that makes the existing `Aggregate` path in `codegen_rvalue_operand` capable of handing SIMD values just fine. As a result, we no longer need to do layout calculations for aggregate result types when running the analysis to determine which things can be SSA in codegen.
2025-07-06Skip `align` tests on wasmJules Bertholet-0/+4
2025-07-06Add FIXME for gen et alJules Bertholet-0/+1
2025-07-06Test `async fn`Jules Bertholet-0/+7
2025-07-06Support `#[align(…)]` on fns in `extern` blocksJules Bertholet-0/+14
2025-07-04Rollup merge of #143410 - scottmcm:redo-transmute-again, ↵Jubilee-49/+27
r=RalfJung,workingjubilee Block SIMD in transmute_immediate; delete `OperandValueKind` Vectors have been causing me problems for years in this code, for example https://github.com/rust-lang/rust/pull/110021#discussion_r1160975086 and https://github.com/rust-lang/rust/pull/143194 See conversation in <https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Is.20transmuting.20a.20.60T.60.20to.20.60Tx1.60.20.28one-element.20SIMD.20vector.29.20UB.3F/near/526262799>. By blocking SIMD in `transmute_immediate` it can be simplified to just take the `Scalar`s involved -- the backend types can be gotten from those `Scalar`s, rather than needing to be passed. And there's an assert added to ICE it if it does get hit. Accordingly, this changes `rvalue_creates_operand` to not send SIMD transmutes through the operand path, but to always go through memory instead, like they did back before rust-lang/rust#108442. And thanks to those changes, I could also remove the `OperandValueKind` type that I added back then which `@RalfJung` rightly considers pretty sketchy. cc `@folkertdev` `@workingjubilee` from the zulip conversation too
2025-07-04Address PR feedbackScott McMurray-7/+7
2025-07-03Allow all MIR `Aggregate`s to take the operand path (if layout permits)Scott McMurray-8/+223
2025-07-03Block SIMD in transmute_immediate; delete `OperandValueKind`Scott McMurray-42/+20
See conversation in <https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Is.20transmuting.20a.20.60T.60.20to.20.60Tx1.60.20.28one-element.20SIMD.20vector.29.20UB.3F/near/526262799>.
2025-07-02Rollup merge of #143194 - folkertdev:fix-single-element-simd-bitcast, ↵Matthias Krüger-10/+45
r=workingjubilee fix bitcast of single-element SIMD vectors in effect this reverts https://github.com/rust-lang/rust/pull/142768 and adds additional tests. That PR relaxed the conditions on an early return in an incorrect way that would create broken LLVM IR. https://godbolt.org/z/PaaGWTv5a ```rust #![feature(repr_simd)] #[repr(simd)] #[derive(Clone, Copy)] struct S([i64; 1]); #[no_mangle] pub extern "C" fn single_element_simd(b: S) -> i64 { unsafe { std::mem::transmute(b) } } ``` at the time of writing generates this LLVM IR, where the type of the return is different from the function's return type. ```llvm define noundef i64 ``````@single_element_simd(<1`````` x i64> %b) unnamed_addr { start: ret <1 x i64> %b } ``` The test output is actually the same for the existing tests, showing that the change didn't actually matter for any tested behavior. It is probably a bit faster to do the early return, but, well, it's incorrect in general. zullip thread: [#t-compiler > Is transmuting a &#96;T&#96; to &#96;Tx1&#96; (one-element SIMD vector) UB?](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Is.20transmuting.20a.20.60T.60.20to.20.60Tx1.60.20.28one-element.20SIMD.20vector.29.20UB.3F/with/526262799) cc ``````@sayantn`````` r? ``````@scottmcm``````
2025-07-01Remove support for dyn*Michael Goulet-9/+0
2025-07-01tests/codegen/enum/enum-match.rs: accept negative range attributeTim Neumann-1/+1
2025-06-30fix bitcast of single-element SIMD vectorsFolkert de Vries-10/+45
2025-06-29inherit `#[align]` from trait method prototypesFolkert de Vries-17/+65
2025-06-24Rollup merge of #142768 - scottmcm:avoid-unneeded-bitcast, r=WaffleLapkinJubilee-0/+45
Avoid a bitcast FFI call in transmuting For things that only change the valid ranges, we can just return the input, rather than making the `LLVMBuildBitCast` call and having *it* then do nothing. I tried to tweak this a bit more and broke stuff, so I also added some extra tests for that as we apparently didn't have coverage.
2025-06-24Error on invalid signatures for interrupt ABIsFolkert de Vries-4/+2
2025-06-23fix `-Zmin-function-alignment` without attributesFolkert de Vries-4/+6
the minimum function alignment was skipped on functions without attributes. That is because in our testing we generally apply `#[no_mangle]` to functions that are tested. I've added a test now that deliberately has no attributes
2025-06-22Auto merge of #142508 - Mark-Simulacrum:skip-noop-drop-glue, r=fee1-deadbors-5/+9
Skip no-op drop glue Since rust-lang/rust#122662 this no longer gets used in vtables, so we're safe to fully drop generating functions from vtables. Those are eventually cleaned up by LLVM, but it's wasteful to produce them in the first place. This doesn't appear to be a significant win (and shows some slight regressions) but seems like the right thing to do. At minimum it reduces noise in the LLVM IR we generate, which seems like a good thing.
2025-06-22Fix tests to drop now-skipped codegenMark Rousskov-5/+9
2025-06-21remove asm_goto feature annotation, for it is now stabilizedTshepang Mbambo-1/+0
2025-06-21Rollup merge of #142597 - folkertdev:abi-cannot-be-called, r=workingjubileeMatthias Krüger-8/+14
error on calls to ABIs that cannot be called We recently added `extern "custom"`, which cannot be called using a rust call expression. But there are more ABIs that can't be called in that way, because the call does not semantically make sense. More details are in https://github.com/rust-lang/rust/issues/140566#issuecomment-2846205457 r? `@workingjubilee` try-job: x86_64-gnu-llvm-19-3
2025-06-20error on calls to ABIs that cannot be calledFolkert de Vries-8/+14
2025-06-20Rollup merge of #140920 - RalfJung:target-feature-unification, ↵Trevor Gross-5/+35
r=nnethercote,WaffleLapkin Extract some shared code from codegen backend target feature handling There's a bunch of code duplication between the GCC and LLVM backends in target feature handling. This moves that into new shared helper functions in `rustc_codegen_ssa`. The first two commits should be purely refactoring. I am fairly sure the LLVM-side behavior stays the same; if the GCC side deliberately diverges from this then I may have missed that. I did account for one divergence, which I do not know is deliberate or not: GCC does not seem to use the `-Ctarget-feature` flag to populate `cfg(target_feature)`. That seems odd, since the `-Ctarget-feature` flag is used to populate the return value of `global_gcc_features` which controls the target features actually used by GCC. ``@GuillaumeGomez`` ``@antoyo`` is there a reason `target_config` ignores `-Ctarget-feature` but `global_gcc_features` does not? The second commit also cleans up a bunch of unneeded complexity added in https://github.com/rust-lang/rust/pull/135927. The third commit extracts some shared logic out of the functions that populate `cfg(target_feature)` and the backend target feature set, respectively. This one actually has some slight functional changes: - Before, with `-Ctarget-feature=-feat`, if there is some other feature `x` that implies `feat` we would *not* add `-x` to the backend target feature set. Now, we do. This fixes rust-lang/rust#134792. - The logic that removes `x` from `cfg(target_feature)` in this case also changed a bit, avoiding a large number of calls to the (uncached) `sess.target.implied_target_features` (if there were a large number of positive features listed before a negative feature) but instead constructing a full inverse implication map when encountering the first negative feature. Ideally this would be done with queries but the backend target feature logic runs before `tcx` so we can't use that... - Previously, if feature "a" implied "b" and "b" was unstable, then using `-Ctarget-feature=+a` would also emit a warning about `b`. I had to remove this since when accounting for negative implications, this emits a ton of warnings in a bunch of existing tests... I assume this was unintentional anyway. The fourth commit increases consistency of the GCC backend with the LLVM backend. The last commit does some further cleanup: - Get rid of RUSTC_SPECIAL_FEATURES. It was only needed for s390x "backchain", but since LLVM 19 that is always a regular target feature so we don't need this hack any more. The hack also has various unintended side-effects so we don't want to keep it. Fixes https://github.com/rust-lang/rust/issues/142412. - Move RUSTC_SPECIFIC_FEATURES handling into the shared parse_rust_feature_flag helper so all consumers of `-Ctarget-feature` that only care about actual target features (and not "crt-static") have it. Previously, we actually set `cfg(target_feature = "crt-static")` twice: once in the backend target feature logic, and once specifically for that one feature. IIUC, some targets are meant to ignore `-Ctarget-feature=+crt-static`, it seems like before this PR that flag still incorrectly enabled `cfg(target_feature = "crt-static")` (but I didn't test this). - Move fixed_x18 handling together with retpoline handling. - Forbid setting fixed_x18 as a regular target feature, even unstably. It must be set via the `-Z` flag. ``@bjorn3`` I did not touch the cranelift backend here, since AFAIK it doesn't really support target features. But if you ever do, please use the new helpers. :) Cc ``@workingjubilee``
2025-06-19Avoid a bitcast FFI call in transmutingScott McMurray-0/+45
For things that only change the valid ranges, we can just skip the `LLVMBuildBitCast` call. I tried to tweak this a bit more and broke stuff, so I also added some extra tests for that as we apparently didn't have coverage.