@@ -4,7 +4,7 @@ mod simd;
44#[ cfg( feature = "master" ) ]
55use std:: iter;
66
7- use gccjit:: { ComparisonOp , Function , FunctionType , RValue , ToRValue , Type , UnaryOp } ;
7+ use gccjit:: { CType , ComparisonOp , Function , FunctionType , RValue , ToRValue , Type , UnaryOp } ;
88use rustc_abi:: { Align , BackendRepr , HasDataLayout , WrappingRange } ;
99use rustc_codegen_ssa:: base:: wants_msvc_seh;
1010use rustc_codegen_ssa:: common:: IntPredicate ;
@@ -362,7 +362,9 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
362362 unimplemented ! ( ) ;
363363 }
364364 sym:: va_arg => {
365- unimplemented ! ( ) ;
365+ let va_list = args[ 0 ] . immediate ( ) ;
366+ let gcc_type = self . immediate_backend_type ( result. layout ) ;
367+ self . va_arg ( va_list, gcc_type)
366368 }
367369
368370 sym:: volatile_load | sym:: unaligned_volatile_load => {
@@ -691,8 +693,18 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
691693 self . context . new_rvalue_from_int ( self . int_type , 0 )
692694 }
693695
694- fn va_start ( & mut self , _va_list : RValue < ' gcc > ) {
695- unimplemented ! ( ) ;
696+ fn va_start ( & mut self , va_list : RValue < ' gcc > ) {
697+ let func = self . context . get_builtin_function ( "__builtin_va_start" ) ;
698+
699+ let va_list_type = self . context . new_c_type ( CType :: VaList ) ;
700+ let va_list = self . context . new_cast ( self . location , va_list, va_list_type. make_pointer ( ) ) ;
701+
702+ // Pre-C23 requires that the last "normal" argument was passed to va_start.
703+ // Just pass 0, this appears to be handled correctly.
704+ let last_normal_arg = self . context . new_rvalue_from_int ( self . int_type , 0 ) ;
705+
706+ let call = self . context . new_call ( self . location , func, & [ va_list, last_normal_arg] ) ;
707+ self . block . add_eval ( self . location , call) ;
696708 }
697709
698710 fn retag_reg ( & mut self , _ptr : Self :: Value , _info : & RetagInfo < Self :: Value > ) -> Self :: Value {
0 commit comments