rust/compiler
bors 36b2369c91 Auto merge of #141980 - beetrees:va-list-proposal, r=workingjubilee
`c_variadic`: make `VaList` abi-compatible with C

tracking issue: https://github.com/rust-lang/rust/issues/44930
related PR: rust-lang/rust#144529

On some platforms, the C `va_list` type is actually a single-element array of a struct (on other platforms it is just a pointer). In C, arrays passed as function arguments expirience array-to-pointer decay, which means that C will pass a pointer to the array in the caller instead of the array itself, and modifications to the array in the callee will be visible to the caller (this does not match Rust by-value semantics). However, for `va_list`, the C standard explicitly states that it is undefined behaviour to use a `va_list` after it has been passed by value to a function (in Rust parlance, the `va_list` is moved, not copied). This matches Rust's pass-by-value semantics, meaning that when the C `va_list` type is a single-element array of a struct, the ABI will match C as long as the Rust type is always be passed indirectly.

In the old implementation, this ABI was achieved by having two separate types: `VaList` was the type that needed to be used when passing a `VaList` as a function parameter, whereas `VaListImpl` was the actual `va_list` type that was correct everywhere else. This however is quite confusing, as there are lots of footguns: it is easy to cause bugs by mixing them up (e.g. the C function `void foo(va_list va)` was equivalent to the Rust `fn foo(va: VaList)` whereas the C function `void bar(va_list* va)` was equivalent to the Rust `fn foo(va: *mut VaListImpl)`, not `fn foo(va: *mut VaList)` as might be expected); also converting from `VaListImpl` to `VaList` with `as_va_list()` had platform specific behaviour: on single-element array of a struct platforms it would return a `VaList` referencing the original `VaListImpl`, whereas on other platforms it would return a cioy,

In this PR, there is now just a single `VaList` type (renamed from `VaListImpl`) which represents the C `va_list` type and will just work in all positions. Instead of having a separate type just to make the ABI work, rust-lang/rust#144529 adds a `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute, which when applied to a struct will force the struct to be passed indirectly by non-Rustic calling conventions. This PR then implements the `VaList` rework, making use of the new attribute on all platforms where the C `va_list` type is a single-element array of a struct.

Cleanup of the `VaList` API and implementation is also included in this PR: since it was decided it was OK to experiment with Rust requiring that not calling `va_end` is not undefined behaviour (https://github.com/rust-lang/rust/issues/141524#issuecomment-3028383594), I've removed the `with_copy` method as it was redundant to the `Clone` impl (the `Drop` impl of `VaList` is a no-op as `va_end` is a no-op on all known platforms).

Previous discussion: rust-lang/rust#141524 and [t-compiler > c_variadic API and ABI](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/c_variadic.20API.20and.20ABI)
Tracking issue: https://github.com/rust-lang/rust/issues/44930
r? `@joshtriplett`
2025-12-05 23:36:55 +00:00
..
rustc Auto merge of #148925 - madsmtm:jemalloc-perf, r=Kobzol 2025-11-23 20:34:07 +00:00
rustc_abi Rollup merge of #145954 - RalfJung:syscall-c-variadics, r=jackh726 2025-11-16 20:30:53 +11:00
rustc_arena fix 2025-11-27 17:55:34 +07:00
rustc_ast Rollup merge of #148256 - lcnr:orphan-check, r=spastorino,WaffleLapkin 2025-11-27 15:59:11 +01:00
rustc_ast_ir Implement &pin patterns and ref pin bindings 2025-11-10 09:57:08 +08:00
rustc_ast_lowering Generate error delegation body when delegation is not resolved 2025-12-05 15:22:26 +03:00
rustc_ast_passes Rollup merge of #149524 - JonathanBrouwer:move_attr_safety, r=jdonszelmann 2025-12-04 16:07:53 +01:00
rustc_ast_pretty remove support for type-of 2025-11-25 10:19:44 +01:00
rustc_attr_parsing Lower spans in AttrPath correctly 2025-12-03 17:00:20 +01:00
rustc_baked_icu_data Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_borrowck Rollup merge of #149101 - reddevilmidzy:mutable, r=eholk 2025-12-05 16:17:07 +01:00
rustc_builtin_macros Rollup merge of #149524 - JonathanBrouwer:move_attr_safety, r=jdonszelmann 2025-12-04 16:07:53 +01:00
rustc_codegen_cranelift account for safe target features in fndef<->closure and fndef<->fndef coerce-lubs 2025-12-03 14:55:41 +00:00
rustc_codegen_gcc Auto merge of #149642 - GuillaumeGomez:subtree-update_cg_gcc_2025-12-04, r=GuillaumeGomez 2025-12-04 17:48:32 +00:00
rustc_codegen_llvm Rollup merge of #149666 - Zalathar:backend-has-zstd, r=jieyouxu 2025-12-05 16:17:12 +01:00
rustc_codegen_ssa Auto merge of #141980 - beetrees:va-list-proposal, r=workingjubilee 2025-12-05 23:36:55 +00:00
rustc_const_eval Rollup merge of #149671 - RalfJung:interpret-float-min-max, r=mati865 2025-12-05 16:17:13 +01:00
rustc_data_structures Auto merge of #148818 - Zalathar:rollup-4vujcg0, r=Zalathar 2025-11-11 13:30:50 +00:00
rustc_driver Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_driver_impl Add perma-unstable --print=backend-has-zstd for use by compiletest 2025-12-05 14:27:52 +11:00
rustc_error_codes Rollup merge of #148678 - xonx4l:EO412_replacement_with_EO425, r=Kivooeo 2025-12-02 22:02:30 +01:00
rustc_error_messages Remove unused pop_span_label method 2025-11-21 14:16:12 +00:00
rustc_errors Auto merge of #149529 - Muscraft:update-annotate-snippets, r=jieyouxu 2025-12-02 13:55:16 +00:00
rustc_expand Move attribute safety checking to rustc_attr_parsing 2025-12-03 17:00:06 +01:00
rustc_feature remove feature(never_type_fallback) 2025-11-27 22:48:00 +01:00
rustc_fluent_macro Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_fs_util Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_graphviz Allow internal_features lint in doc tests 2025-11-05 11:25:29 +00:00
rustc_hashes some cleanups in compiler 2025-10-12 08:08:30 +00:00
rustc_hir Auto merge of #149646 - matthiaskrgr:rollup-jbfeow8, r=matthiaskrgr 2025-12-04 22:04:03 +00:00
rustc_hir_analysis Rename supertrait item shadowing lints 2025-12-02 17:21:01 +00:00
rustc_hir_id rustc_hir_id: Add a comment explaining why the crate exists 2025-08-20 15:04:00 -07:00
rustc_hir_pretty remove support for type-of 2025-11-25 10:19:44 +01:00
rustc_hir_typeck Auto merge of #148602 - BoxyUwU:coercion_cleanup_uncontroversial, r=lcnr 2025-12-05 11:46:41 +00:00
rustc_incremental Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_index Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_index_macros Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_infer fudge infer vars in cause code intentionally 2025-12-01 12:40:49 +08:00
rustc_interface Emscripten: Turn wasm-eh on by default 2025-12-03 14:34:07 -08:00
rustc_lexer Update memchr to 2.7.6 2025-09-26 17:53:49 +02:00
rustc_lint Auto merge of #149646 - matthiaskrgr:rollup-jbfeow8, r=matthiaskrgr 2025-12-04 22:04:03 +00:00
rustc_lint_defs Rollup merge of #149524 - JonathanBrouwer:move_attr_safety, r=jdonszelmann 2025-12-04 16:07:53 +01:00
rustc_llvm Fix for LLVM22 making lowering decisions dependent on RuntimeLibraryInfo. 2025-12-04 20:23:00 +00:00
rustc_log Restrict sysroot crate imports to those defined in this repo. 2025-10-15 13:17:25 +01:00
rustc_macros use declarative macro for #[derive(TryFromU32)] 2025-10-06 14:54:38 +00:00
rustc_metadata Rollup merge of #149388 - jdonszelmann:rm-sess-blob, r=jieyouxu 2025-11-27 20:07:15 +01:00
rustc_middle Auto merge of #148602 - BoxyUwU:coercion_cleanup_uncontroversial, r=lcnr 2025-12-05 11:46:41 +00:00
rustc_mir_build reword error for invalid range patterns 2025-12-02 18:28:05 +00:00
rustc_mir_dataflow Auto merge of #142821 - cjgillot:jump-threading-single, r=saethlin 2025-12-01 23:44:49 +00:00
rustc_mir_transform Auto merge of #148602 - BoxyUwU:coercion_cleanup_uncontroversial, r=lcnr 2025-12-05 11:46:41 +00:00
rustc_monomorphize account for safe target features in fndef<->closure and fndef<->fndef coerce-lubs 2025-12-03 14:55:41 +00:00
rustc_next_trait_solver Rollup merge of #148256 - lcnr:orphan-check, r=spastorino,WaffleLapkin 2025-11-27 15:59:11 +01:00
rustc_parse Recover on misspelled item keyword 2025-12-03 18:09:40 +00:00
rustc_parse_format Allow internal_features lint in doc tests 2025-11-05 11:25:29 +00:00
rustc_passes Point to the item that is incorrectly annotated with #[diagnostic::on_const] 2025-12-04 11:59:19 +09:00
rustc_pattern_analysis fix: Do not ICE when missing match arm with ill-formed subty is met 2025-11-13 01:36:35 +09:00
rustc_privacy Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_proc_macro Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_public account for safe target features in fndef<->closure and fndef<->fndef coerce-lubs 2025-12-03 14:55:41 +00:00
rustc_public_bridge Add DefId::parent() accessor in rustc_public 2025-11-14 17:12:50 -05:00
rustc_query_impl Lock shards while collecting active jobs. 2025-11-14 09:01:22 +08:00
rustc_query_system fix(span): track unnormalized source len for dep-info 2025-11-15 09:05:08 -05:00
rustc_resolve Check identifiers defined in macros when suggesting identifiers hidden by hygiene 2025-12-04 14:58:46 +08:00
rustc_sanitizers Rollup merge of #144936 - rcvalle:rust-cfi-fix-144641, r=lcnr 2025-10-28 20:39:32 +11:00
rustc_serialize Allow internal_features lint in doc tests 2025-11-05 11:25:29 +00:00
rustc_session Add perma-unstable --print=backend-has-zstd for use by compiletest 2025-12-05 14:27:52 +11:00
rustc_span Allow PowerPC spe_acc as clobber-only register 2025-12-03 12:37:22 -06:00
rustc_symbol_mangling Rollup merge of #148452 - Fulgen301:pdb-large-symbols-v0, r=jackh726 2025-11-26 23:32:05 +11:00
rustc_target Auto merge of #149632 - matthiaskrgr:rollup-c5iqgtn, r=matthiaskrgr 2025-12-04 14:38:19 +00:00
rustc_thread_pool some cleanups in compiler 2025-10-12 08:08:30 +00:00
rustc_trait_selection Rollup merge of #149183 - tiif:typing_env_fix, r=BoxyUwU 2025-12-04 08:46:19 +01:00
rustc_traits add const_of_item query and use it in normalization 2025-11-08 13:50:47 -05:00
rustc_transmute prefer to use repeat_n over repeat and take 2025-10-09 01:24:55 +08:00
rustc_ty_utils Rollup merge of #149433 - scottmcm:delay-layout-ICEs, r=jdonszelmann 2025-12-01 18:35:11 +01:00
rustc_type_ir Auto merge of #135634 - joboet:trivial-clone, r=Mark-Simulacrum 2025-11-10 15:41:43 +00:00
rustc_type_ir_macros compiler: Fix a couple issues around cargo feature unification 2025-10-31 14:14:05 -04:00
rustc_windows_rc [win] Use find-msvc-tools instead of cc to find the linker and rc on Windows 2025-09-19 12:00:30 -07:00