@@ -172,6 +172,8 @@ pub trait TyAbiInterface<'a, C>: Sized + std::fmt::Debug {
172172 fn is_tuple ( this : TyAndLayout < ' a , Self > ) -> bool ;
173173 fn is_unit ( this : TyAndLayout < ' a , Self > ) -> bool ;
174174 fn is_transparent ( this : TyAndLayout < ' a , Self > ) -> bool ;
175+ /// See [`TyAndLayout::pass_indirectly_in_non_rustic_abis`] for details.
176+ fn is_pass_indirectly_in_non_rustic_abis_flag_set ( this : TyAndLayout < ' a , Self > ) -> bool ;
175177}
176178
177179impl < ' a , Ty > TyAndLayout < ' a , Ty > {
@@ -269,6 +271,30 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
269271 Ty :: is_transparent ( self )
270272 }
271273
274+ /// If this method returns `true`, then this type should always have a `PassMode` of
275+ /// `Indirect { on_stack: false, .. }` when being used as the argument type of a function with a
276+ /// non-Rustic ABI (this is true for structs annotated with the
277+ /// `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute). Currently this is only used by
278+ /// `VaList`, so this only needs to be handled on architectures where `VaList` requires it:
279+ /// specifically there is a `support_architectures` array in the
280+ /// `check_pass_indirectly_in_non_rustic_abis` function in
281+ /// `compiler/rustc_passes/src/check_attr.rs` which lists all the architectures this needs to be
282+ /// handled on. See the comment near the top of `library/core/src/ffi/va_list.rs` for more
283+ /// details.
284+ ///
285+ /// This function handles transparent types automatically.
286+ pub fn pass_indirectly_in_non_rustic_abis < C > ( mut self , cx : & C ) -> bool
287+ where
288+ Ty : TyAbiInterface < ' a , C > + Copy ,
289+ {
290+ while self . is_transparent ( )
291+ && let Some ( ( _, field) ) = self . non_1zst_field ( cx)
292+ {
293+ self = field;
294+ }
295+ Ty :: is_pass_indirectly_in_non_rustic_abis_flag_set ( self )
296+ }
297+
272298 /// Finds the one field that is not a 1-ZST.
273299 /// Returns `None` if there are multiple non-1-ZST fields or only 1-ZST-fields.
274300 pub fn non_1zst_field < C > ( & self , cx : & C ) -> Option < ( FieldIdx , Self ) >
0 commit comments