@@ -391,36 +391,36 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
391391
392392/// Creates the `main` function which will initialize the rust runtime and call
393393/// users main function.
394- pub fn maybe_create_entry_wrapper < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > ( cx : & ' a Bx :: CodegenCx ) {
394+ pub fn maybe_create_entry_wrapper < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
395+ cx : & ' a Bx :: CodegenCx ,
396+ ) -> Option < Bx :: Function > {
395397 let ( main_def_id, span) = match cx. tcx ( ) . entry_fn ( LOCAL_CRATE ) {
396398 Some ( ( def_id, _) ) => ( def_id, cx. tcx ( ) . def_span ( def_id) ) ,
397- None => return ,
399+ None => return None ,
398400 } ;
399401
400402 let instance = Instance :: mono ( cx. tcx ( ) , main_def_id) ;
401403
402404 if !cx. codegen_unit ( ) . contains_item ( & MonoItem :: Fn ( instance) ) {
403405 // We want to create the wrapper in the same codegen unit as Rust's main
404406 // function.
405- return ;
407+ return None ;
406408 }
407409
408410 let main_llfn = cx. get_fn_addr ( instance) ;
409411
410- let et = cx. tcx ( ) . entry_fn ( LOCAL_CRATE ) . map ( |e| e. 1 ) ;
411- match et {
412- Some ( EntryFnType :: Main ) => create_entry_fn :: < Bx > ( cx, span, main_llfn, main_def_id, true ) ,
413- Some ( EntryFnType :: Start ) => create_entry_fn :: < Bx > ( cx, span, main_llfn, main_def_id, false ) ,
414- None => { } // Do nothing.
415- }
412+ return cx. tcx ( ) . entry_fn ( LOCAL_CRATE ) . map ( |( _, et) | {
413+ let use_start_lang_item = EntryFnType :: Start != et;
414+ create_entry_fn :: < Bx > ( cx, span, main_llfn, main_def_id, use_start_lang_item)
415+ } ) ;
416416
417417 fn create_entry_fn < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
418418 cx : & ' a Bx :: CodegenCx ,
419419 sp : Span ,
420420 rust_main : Bx :: Value ,
421421 rust_main_def_id : DefId ,
422422 use_start_lang_item : bool ,
423- ) {
423+ ) -> Bx :: Function {
424424 // The entry function is either `int main(void)` or `int main(int argc, char **argv)`,
425425 // depending on whether the target needs `argc` and `argv` to be passed in.
426426 let llfty = if cx. sess ( ) . target . target . options . main_needs_argc_argv {
@@ -481,6 +481,8 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
481481 let result = bx. call ( start_fn, & args, None ) ;
482482 let cast = bx. intcast ( result, cx. type_int ( ) , true ) ;
483483 bx. ret ( cast) ;
484+
485+ llfn
484486 }
485487}
486488
0 commit comments