@@ -105,13 +105,30 @@ pub(super) fn emit_va_arg(
105
105
) -> & ' ll Value {
106
106
// Determine the va_arg implementation to use. The LLVM va_arg instruction
107
107
// is lacking in some instances, so we should only use it as a fallback.
108
+ let target = & bx. cx . tcx . sess . target . target ;
108
109
let arch = & bx. cx . tcx . sess . target . target . arch ;
109
- match ( & * * arch,
110
- bx . cx . tcx . sess . target . target . options . is_like_windows ) {
110
+ match ( & * * arch, target . options . is_like_windows ) {
111
+ // Windows x86
111
112
( "x86" , true ) => {
112
113
emit_ptr_va_arg ( bx, addr, target_ty, false ,
113
114
Align :: from_bytes ( 4 ) . unwrap ( ) , false )
114
115
}
116
+ // Generic x86
117
+ ( "x86" , _) => {
118
+ emit_ptr_va_arg ( bx, addr, target_ty, false ,
119
+ Align :: from_bytes ( 4 ) . unwrap ( ) , true )
120
+ }
121
+ // Windows Aarch64
122
+ ( "aarch4" , true ) => {
123
+ emit_ptr_va_arg ( bx, addr, target_ty, false ,
124
+ Align :: from_bytes ( 8 ) . unwrap ( ) , false )
125
+ }
126
+ // iOS Aarch64
127
+ ( "aarch4" , _) if target. target_os == "ios" => {
128
+ emit_ptr_va_arg ( bx, addr, target_ty, false ,
129
+ Align :: from_bytes ( 8 ) . unwrap ( ) , true )
130
+ }
131
+ // Windows x86_64
115
132
( "x86_64" , true ) => {
116
133
let target_ty_size = bx. cx . size_of ( target_ty) . bytes ( ) ;
117
134
let indirect = if target_ty_size > 8 || !target_ty_size. is_power_of_two ( ) {
@@ -122,15 +139,14 @@ pub(super) fn emit_va_arg(
122
139
emit_ptr_va_arg ( bx, addr, target_ty, indirect,
123
140
Align :: from_bytes ( 8 ) . unwrap ( ) , false )
124
141
}
125
- ( "x86" , false ) => {
126
- emit_ptr_va_arg ( bx, addr, target_ty, false ,
127
- Align :: from_bytes ( 4 ) . unwrap ( ) , true )
128
- }
142
+ // For all other architecture/OS combinations fall back to using
143
+ // the LLVM va_arg instruction.
144
+ // https://llvm.org/docs/LangRef.html#va-arg-instruction
129
145
_ => {
130
- let va_list = if ( bx . tcx ( ) . sess . target . target . arch == "aarch64" ||
131
- bx . tcx ( ) . sess . target . target . arch == "x86_64" ||
132
- bx . tcx ( ) . sess . target . target . arch == "powerpc" ) &&
133
- !bx . tcx ( ) . sess . target . target . options . is_like_windows {
146
+ let va_list = if ( target. arch == "aarch64" ||
147
+ target. arch == "x86_64" ||
148
+ target. arch == "powerpc" ) &&
149
+ !target. options . is_like_windows {
134
150
bx. load ( addr. immediate ( ) , bx. tcx ( ) . data_layout . pointer_align . abi )
135
151
} else {
136
152
addr. immediate ( )
0 commit comments