-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implements RFC 1937: ?
in main
#46479
Changes from all commits
d7918fb
b452c43
19adeaa
011c9ea
99a108c
f842f75
8232734
267800a
8f539b0
c7a57d2
a8a9a05
83cb299
88bf2b4
347165f
faff382
072f3eb
7efeeba
f972f52
dbbba55
c2f22f0
7dfec34
81e375d
2cdd1c4
5a4298b
09f94be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ use rustc::ty::{self, Ty, TyCtxt}; | |
use rustc::ty::layout::{self, Align, TyLayout, LayoutOf}; | ||
use rustc::ty::maps::Providers; | ||
use rustc::dep_graph::{DepNode, DepConstructor}; | ||
use rustc::ty::subst::Kind; | ||
use rustc::middle::cstore::{self, LinkMeta, LinkagePreference}; | ||
use rustc::util::common::{time, print_time_passes_entry}; | ||
use rustc::session::config::{self, NoDebugInfo}; | ||
|
@@ -79,6 +80,7 @@ use std::str; | |
use std::sync::Arc; | ||
use std::time::{Instant, Duration}; | ||
use std::i32; | ||
use std::iter; | ||
use std::sync::mpsc; | ||
use syntax_pos::Span; | ||
use syntax_pos::symbol::InternedString; | ||
|
@@ -540,18 +542,26 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) { | |
|
||
let et = ccx.sess().entry_type.get().unwrap(); | ||
match et { | ||
config::EntryMain => create_entry_fn(ccx, span, main_llfn, true), | ||
config::EntryStart => create_entry_fn(ccx, span, main_llfn, false), | ||
config::EntryMain => create_entry_fn(ccx, span, main_llfn, main_def_id, true), | ||
config::EntryStart => create_entry_fn(ccx, span, main_llfn, main_def_id, false), | ||
config::EntryNone => {} // Do nothing. | ||
} | ||
|
||
fn create_entry_fn(ccx: &CrateContext, | ||
fn create_entry_fn<'ccx>(ccx: &'ccx CrateContext, | ||
sp: Span, | ||
rust_main: ValueRef, | ||
rust_main_def_id: DefId, | ||
use_start_lang_item: bool) { | ||
// Signature of native main(), corresponding to C's `int main(int, char **)` | ||
let llfty = Type::func(&[Type::c_int(ccx), Type::i8p(ccx).ptr_to()], &Type::c_int(ccx)); | ||
|
||
let main_ret_ty = ccx.tcx().fn_sig(rust_main_def_id).output(); | ||
// Given that `main()` has no arguments, | ||
// then its return type cannot have | ||
// late-bound regions, since late-bound | ||
// regions must appear in the argument | ||
// listing. | ||
let main_ret_ty = main_ret_ty.no_late_bound_regions().unwrap(); | ||
|
||
if declare::get_defined_value(ccx, "main").is_some() { | ||
// FIXME: We should be smart and show a better diagnostic here. | ||
ccx.sess().struct_span_err(sp, "entry symbol `main` defined multiple times") | ||
|
@@ -577,8 +587,8 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) { | |
|
||
let (start_fn, args) = if use_start_lang_item { | ||
let start_def_id = ccx.tcx().require_lang_item(StartFnLangItem); | ||
let start_instance = Instance::mono(ccx.tcx(), start_def_id); | ||
let start_fn = callee::get_fn(ccx, start_instance); | ||
let start_fn = callee::resolve_and_get_fn(ccx, start_def_id, ccx.tcx().mk_substs( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because user-defined There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, but user-defined |
||
iter::once(Kind::from(main_ret_ty)))); | ||
(start_fn, vec![bld.pointercast(rust_main, Type::i8p(ccx).ptr_to()), | ||
arg_argc, arg_argv]) | ||
} else { | ||
|
@@ -587,8 +597,6 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) { | |
}; | ||
|
||
let result = bld.call(start_fn, &args, None); | ||
|
||
// Return rust start function's result from native main() | ||
bld.ret(bld.intcast(result, Type::c_int(ccx), true)); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this line expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that is expected. There are multiple empty lines (scroll a little bit up in the file).