@@ -391,36 +391,36 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
391
391
392
392
/// Creates the `main` function which will initialize the rust runtime and call
393
393
/// 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 > {
395
397
let ( main_def_id, span) = match cx. tcx ( ) . entry_fn ( LOCAL_CRATE ) {
396
398
Some ( ( def_id, _) ) => ( def_id, cx. tcx ( ) . def_span ( def_id) ) ,
397
- None => return ,
399
+ None => return None ,
398
400
} ;
399
401
400
402
let instance = Instance :: mono ( cx. tcx ( ) , main_def_id) ;
401
403
402
404
if !cx. codegen_unit ( ) . contains_item ( & MonoItem :: Fn ( instance) ) {
403
405
// We want to create the wrapper in the same codegen unit as Rust's main
404
406
// function.
405
- return ;
407
+ return None ;
406
408
}
407
409
408
410
let main_llfn = cx. get_fn_addr ( instance) ;
409
411
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
+ } ) ;
416
416
417
417
fn create_entry_fn < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
418
418
cx : & ' a Bx :: CodegenCx ,
419
419
sp : Span ,
420
420
rust_main : Bx :: Value ,
421
421
rust_main_def_id : DefId ,
422
422
use_start_lang_item : bool ,
423
- ) {
423
+ ) -> Bx :: Function {
424
424
// The entry function is either `int main(void)` or `int main(int argc, char **argv)`,
425
425
// depending on whether the target needs `argc` and `argv` to be passed in.
426
426
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: &'
481
481
let result = bx. call ( start_fn, & args, None ) ;
482
482
let cast = bx. intcast ( result, cx. type_int ( ) , true ) ;
483
483
bx. ret ( cast) ;
484
+
485
+ llfn
484
486
}
485
487
}
486
488
0 commit comments