mirror of https://github.com/rust-lang/rust.git
Fix argv.rs under the LLVM compiler.
The call to rust_start was assuming that all rust main() functions have the same signature, but the compiler doesn't actually canonicalize them. So instead just match the C signature of rust_start, and cast.
This commit is contained in:
parent
8ebf72ed29
commit
22eca31d98
|
@ -366,7 +366,6 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
|
||||||
acyclic-unwind.rs \
|
acyclic-unwind.rs \
|
||||||
alt-pattern-simple.rs \
|
alt-pattern-simple.rs \
|
||||||
alt-tag.rs \
|
alt-tag.rs \
|
||||||
argv.rs \
|
|
||||||
basic.rs \
|
basic.rs \
|
||||||
bind-obj-ctor.rs \
|
bind-obj-ctor.rs \
|
||||||
bind-thunk.rs \
|
bind-thunk.rs \
|
||||||
|
|
|
@ -11,6 +11,8 @@ type abi = {
|
||||||
|
|
||||||
let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi =
|
let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi =
|
||||||
let i32 = Llvm.i32_type llctx in
|
let i32 = Llvm.i32_type llctx in
|
||||||
|
(* FIXME: Use Llvm_target.intptr_type for more platform support. *)
|
||||||
|
let word_ty = i32 in
|
||||||
|
|
||||||
let crate_ty =
|
let crate_ty =
|
||||||
(* TODO: other architectures besides x86 *)
|
(* TODO: other architectures besides x86 *)
|
||||||
|
@ -51,19 +53,16 @@ let declare_abi (llctx:Llvm.llcontext) (llmod:Llvm.llmodule) : abi =
|
||||||
ignore (Llvm.define_type_name "rust_task" task_ty llmod);
|
ignore (Llvm.define_type_name "rust_task" task_ty llmod);
|
||||||
|
|
||||||
let rust_start_ty =
|
let rust_start_ty =
|
||||||
let task_ptr_ty = Llvm.pointer_type task_ty in
|
(* Rust's main function can have several types, so we cast them
|
||||||
let llnilty = Llvm.array_type (Llvm.i1_type llctx) 0 in
|
all to uintptr_t. *)
|
||||||
let main_ty = Llvm.function_type (Llvm.void_type llctx)
|
let main_ty = word_ty in
|
||||||
[| Llvm.pointer_type llnilty; task_ptr_ty; |]
|
let args_ty = [| main_ty; Llvm.pointer_type crate_ty; i32; i32 |] in
|
||||||
in
|
|
||||||
let args_ty = Array.map Llvm.pointer_type [| main_ty; crate_ty; |] in
|
|
||||||
let args_ty = Array.append args_ty [| i32; i32 |] in
|
|
||||||
Llvm.function_type i32 args_ty
|
Llvm.function_type i32 args_ty
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
crate_ty = crate_ty;
|
crate_ty = crate_ty;
|
||||||
task_ty = task_ty;
|
task_ty = task_ty;
|
||||||
word_ty = i32;
|
word_ty = word_ty;
|
||||||
rust_start = Llvm.declare_function "rust_start" rust_start_ty llmod
|
rust_start = Llvm.declare_function "rust_start" rust_start_ty llmod
|
||||||
}
|
}
|
||||||
;;
|
;;
|
||||||
|
|
|
@ -79,7 +79,8 @@ let finalize_module
|
||||||
| Some fn -> fn
|
| Some fn -> fn
|
||||||
in
|
in
|
||||||
let rust_start = abi.Llabi.rust_start in
|
let rust_start = abi.Llabi.rust_start in
|
||||||
let rust_start_args = [| rust_main_fn; crate_ptr; argc; argv |] in
|
let rust_start_args = [| Llvm.const_ptrtoint rust_main_fn abi.Llabi.word_ty;
|
||||||
|
crate_ptr; argc; argv |] in
|
||||||
ignore (Llvm.build_call
|
ignore (Llvm.build_call
|
||||||
rust_start rust_start_args "start_rust" main_builder);
|
rust_start rust_start_args "start_rust" main_builder);
|
||||||
ignore (Llvm.build_ret (Llvm.const_int i32 0) main_builder)
|
ignore (Llvm.build_ret (Llvm.const_int i32 0) main_builder)
|
||||||
|
|
Loading…
Reference in New Issue