From 6c9a4ba8eb2badef6f1ff040e61e4fe494585d79 Mon Sep 17 00:00:00 2001 From: Daniel Klauer Date: Thu, 21 Sep 2017 23:43:05 +0200 Subject: [PATCH 1/6] rustc: Add Type::c_int() Add c_int for use in the compiler, assuming i32 for all targets as in libc. --- src/librustc_trans/type_.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustc_trans/type_.rs b/src/librustc_trans/type_.rs index e5e532703d7d0..65fdd72bd29e0 100644 --- a/src/librustc_trans/type_.rs +++ b/src/librustc_trans/type_.rs @@ -140,6 +140,10 @@ impl Type { } } + pub fn c_int(ccx: &CrateContext) -> Type { + Type::i32(ccx) + } + pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type { match t { ast::IntTy::Is => ccx.isize_ty(), From c2fe69b9bd410885b51d034628e0403e882689da Mon Sep 17 00:00:00 2001 From: Daniel Klauer Date: Fri, 22 Sep 2017 00:36:10 +0200 Subject: [PATCH 2/6] rustc: Fix main() entry point signature on 64bit To match the C signature, main() should be generated with C int type for the argc parameter and result, i.e. i32 instead of i64 on 64bit. That way it no longer relies on the upper 32 bits being zero, which I'm not sure is guaranteed by ABIs or startup code. --- src/librustc_trans/base.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 2d01d2947d6eb..306a2d4427033 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -77,7 +77,6 @@ use value::Value; use rustc::util::nodemap::{NodeSet, FxHashMap, FxHashSet, DefIdSet}; use CrateInfo; -use libc::c_uint; use std::any::Any; use std::cell::RefCell; use std::ffi::{CStr, CString}; @@ -692,7 +691,8 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) { sp: Span, rust_main: ValueRef, use_start_lang_item: bool) { - let llfty = Type::func(&[ccx.isize_ty(), Type::i8p(ccx).ptr_to()], &ccx.isize_ty()); + // 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)); if declare::get_defined_value(ccx, "main").is_some() { // FIXME: We should be smart and show a better diagnostic here. @@ -711,19 +711,27 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) { debuginfo::gdb::insert_reference_to_gdb_debug_scripts_section_global(ccx, &bld); + // Params from native main() used as args for rust start function + let param_argc = get_param(llfn, 0); + let param_argv = get_param(llfn, 1); + let arg_argc = bld.intcast(param_argc, ccx.isize_ty(), true); + let arg_argv = param_argv; + 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); - (start_fn, vec![bld.pointercast(rust_main, Type::i8p(ccx).ptr_to()), get_param(llfn, 0), - get_param(llfn, 1)]) + (start_fn, vec![bld.pointercast(rust_main, Type::i8p(ccx).ptr_to()), + arg_argc, arg_argv]) } else { debug!("using user-defined start fn"); - (rust_main, vec![get_param(llfn, 0 as c_uint), get_param(llfn, 1 as c_uint)]) + (rust_main, vec![arg_argc, arg_argv]) }; let result = bld.call(start_fn, &args, None); - bld.ret(result); + + // Return rust start function's result from native main() + bld.ret(bld.intcast(result, Type::c_int(ccx), true)); } } From 6c3f19002de71acc6881731859b1bf70b46de982 Mon Sep 17 00:00:00 2001 From: Daniel Klauer Date: Thu, 28 Sep 2017 23:36:08 +0200 Subject: [PATCH 3/6] test: Check native main() signature --- src/test/codegen/abi-main-signature.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/codegen/abi-main-signature.rs diff --git a/src/test/codegen/abi-main-signature.rs b/src/test/codegen/abi-main-signature.rs new file mode 100644 index 0000000000000..3d09e0d9e6f36 --- /dev/null +++ b/src/test/codegen/abi-main-signature.rs @@ -0,0 +1,17 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Checks the signature of the implicitly generated native main() +// entry point. It must match C's `int main(int, char **)`. + +fn main() { +} + +// CHECK: define i32 @main(i32, i8**) From a204c193cad7309412e98db09d6bf8f3c456b063 Mon Sep 17 00:00:00 2001 From: Daniel Klauer Date: Sat, 30 Sep 2017 13:47:49 +0200 Subject: [PATCH 4/6] rustc: Specify c_int width for each target (all i32 for now, as in liblibc) --- src/librustc_back/target/aarch64_apple_ios.rs | 1 + src/librustc_back/target/aarch64_linux_android.rs | 1 + src/librustc_back/target/aarch64_unknown_freebsd.rs | 1 + src/librustc_back/target/aarch64_unknown_fuchsia.rs | 1 + src/librustc_back/target/aarch64_unknown_linux_gnu.rs | 1 + src/librustc_back/target/aarch64_unknown_linux_musl.rs | 1 + src/librustc_back/target/arm_linux_androideabi.rs | 1 + src/librustc_back/target/arm_unknown_linux_gnueabi.rs | 1 + src/librustc_back/target/arm_unknown_linux_gnueabihf.rs | 1 + src/librustc_back/target/arm_unknown_linux_musleabi.rs | 1 + src/librustc_back/target/arm_unknown_linux_musleabihf.rs | 1 + src/librustc_back/target/armv5te_unknown_linux_gnueabi.rs | 1 + src/librustc_back/target/armv7_apple_ios.rs | 1 + src/librustc_back/target/armv7_linux_androideabi.rs | 1 + src/librustc_back/target/armv7_unknown_linux_gnueabihf.rs | 1 + src/librustc_back/target/armv7_unknown_linux_musleabihf.rs | 1 + src/librustc_back/target/armv7s_apple_ios.rs | 1 + src/librustc_back/target/asmjs_unknown_emscripten.rs | 1 + src/librustc_back/target/i386_apple_ios.rs | 1 + src/librustc_back/target/i686_apple_darwin.rs | 1 + src/librustc_back/target/i686_linux_android.rs | 1 + src/librustc_back/target/i686_pc_windows_gnu.rs | 1 + src/librustc_back/target/i686_pc_windows_msvc.rs | 1 + src/librustc_back/target/i686_unknown_dragonfly.rs | 1 + src/librustc_back/target/i686_unknown_freebsd.rs | 1 + src/librustc_back/target/i686_unknown_haiku.rs | 1 + src/librustc_back/target/i686_unknown_linux_gnu.rs | 1 + src/librustc_back/target/i686_unknown_linux_musl.rs | 1 + src/librustc_back/target/i686_unknown_netbsd.rs | 1 + src/librustc_back/target/i686_unknown_openbsd.rs | 1 + src/librustc_back/target/le32_unknown_nacl.rs | 1 + src/librustc_back/target/mips64_unknown_linux_gnuabi64.rs | 1 + .../target/mips64el_unknown_linux_gnuabi64.rs | 1 + src/librustc_back/target/mips_unknown_linux_gnu.rs | 1 + src/librustc_back/target/mips_unknown_linux_musl.rs | 1 + src/librustc_back/target/mips_unknown_linux_uclibc.rs | 1 + src/librustc_back/target/mipsel_unknown_linux_gnu.rs | 1 + src/librustc_back/target/mipsel_unknown_linux_musl.rs | 1 + src/librustc_back/target/mipsel_unknown_linux_uclibc.rs | 1 + src/librustc_back/target/mod.rs | 4 ++++ src/librustc_back/target/msp430_none_elf.rs | 1 + src/librustc_back/target/powerpc64_unknown_linux_gnu.rs | 1 + src/librustc_back/target/powerpc64le_unknown_linux_gnu.rs | 1 + src/librustc_back/target/powerpc_unknown_linux_gnu.rs | 1 + src/librustc_back/target/s390x_unknown_linux_gnu.rs | 1 + src/librustc_back/target/sparc64_unknown_linux_gnu.rs | 1 + src/librustc_back/target/sparc64_unknown_netbsd.rs | 1 + src/librustc_back/target/sparcv9_sun_solaris.rs | 1 + src/librustc_back/target/thumbv6m_none_eabi.rs | 1 + src/librustc_back/target/thumbv7em_none_eabi.rs | 1 + src/librustc_back/target/thumbv7em_none_eabihf.rs | 1 + src/librustc_back/target/thumbv7m_none_eabi.rs | 1 + src/librustc_back/target/wasm32_experimental_emscripten.rs | 1 + src/librustc_back/target/wasm32_unknown_emscripten.rs | 1 + src/librustc_back/target/x86_64_apple_darwin.rs | 1 + src/librustc_back/target/x86_64_apple_ios.rs | 1 + src/librustc_back/target/x86_64_linux_android.rs | 1 + src/librustc_back/target/x86_64_pc_windows_gnu.rs | 1 + src/librustc_back/target/x86_64_pc_windows_msvc.rs | 1 + src/librustc_back/target/x86_64_rumprun_netbsd.rs | 1 + src/librustc_back/target/x86_64_sun_solaris.rs | 1 + src/librustc_back/target/x86_64_unknown_bitrig.rs | 1 + src/librustc_back/target/x86_64_unknown_dragonfly.rs | 1 + src/librustc_back/target/x86_64_unknown_freebsd.rs | 1 + src/librustc_back/target/x86_64_unknown_fuchsia.rs | 1 + src/librustc_back/target/x86_64_unknown_haiku.rs | 1 + src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs | 1 + src/librustc_back/target/x86_64_unknown_linux_gnu.rs | 1 + src/librustc_back/target/x86_64_unknown_linux_musl.rs | 1 + src/librustc_back/target/x86_64_unknown_netbsd.rs | 1 + src/librustc_back/target/x86_64_unknown_openbsd.rs | 1 + src/librustc_back/target/x86_64_unknown_redox.rs | 1 + src/librustc_trans/type_.rs | 7 ++++++- 73 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/librustc_back/target/aarch64_apple_ios.rs b/src/librustc_back/target/aarch64_apple_ios.rs index 802a8c77db05b..cff6eb534b1e5 100644 --- a/src/librustc_back/target/aarch64_apple_ios.rs +++ b/src/librustc_back/target/aarch64_apple_ios.rs @@ -18,6 +18,7 @@ pub fn target() -> TargetResult { llvm_target: "arm64-apple-ios".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "ios".to_string(), diff --git a/src/librustc_back/target/aarch64_linux_android.rs b/src/librustc_back/target/aarch64_linux_android.rs index 7d8610b4a3684..2c0d6a55ed8e5 100644 --- a/src/librustc_back/target/aarch64_linux_android.rs +++ b/src/librustc_back/target/aarch64_linux_android.rs @@ -24,6 +24,7 @@ pub fn target() -> TargetResult { llvm_target: "aarch64-linux-android".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "android".to_string(), diff --git a/src/librustc_back/target/aarch64_unknown_freebsd.rs b/src/librustc_back/target/aarch64_unknown_freebsd.rs index c5427a13e4c7d..1ce8d600c0331 100644 --- a/src/librustc_back/target/aarch64_unknown_freebsd.rs +++ b/src/librustc_back/target/aarch64_unknown_freebsd.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "aarch64-unknown-freebsd".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "freebsd".to_string(), diff --git a/src/librustc_back/target/aarch64_unknown_fuchsia.rs b/src/librustc_back/target/aarch64_unknown_fuchsia.rs index 5d680504a02d0..73cd9c9270153 100644 --- a/src/librustc_back/target/aarch64_unknown_fuchsia.rs +++ b/src/librustc_back/target/aarch64_unknown_fuchsia.rs @@ -19,6 +19,7 @@ pub fn target() -> TargetResult { llvm_target: "aarch64-unknown-fuchsia".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), target_os: "fuchsia".to_string(), diff --git a/src/librustc_back/target/aarch64_unknown_linux_gnu.rs b/src/librustc_back/target/aarch64_unknown_linux_gnu.rs index 7c2c45a2843a7..5c9c9a0c555c2 100644 --- a/src/librustc_back/target/aarch64_unknown_linux_gnu.rs +++ b/src/librustc_back/target/aarch64_unknown_linux_gnu.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "aarch64-unknown-linux-gnu".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), target_env: "gnu".to_string(), data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), diff --git a/src/librustc_back/target/aarch64_unknown_linux_musl.rs b/src/librustc_back/target/aarch64_unknown_linux_musl.rs index 1edac616366dd..d39ad97bbcb87 100644 --- a/src/librustc_back/target/aarch64_unknown_linux_musl.rs +++ b/src/librustc_back/target/aarch64_unknown_linux_musl.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "aarch64-unknown-linux-musl".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), target_env: "musl".to_string(), data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), arch: "aarch64".to_string(), diff --git a/src/librustc_back/target/arm_linux_androideabi.rs b/src/librustc_back/target/arm_linux_androideabi.rs index 6bfe90af2ca16..e93a9a788a42b 100644 --- a/src/librustc_back/target/arm_linux_androideabi.rs +++ b/src/librustc_back/target/arm_linux_androideabi.rs @@ -21,6 +21,7 @@ pub fn target() -> TargetResult { llvm_target: "arm-linux-androideabi".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "android".to_string(), diff --git a/src/librustc_back/target/arm_unknown_linux_gnueabi.rs b/src/librustc_back/target/arm_unknown_linux_gnueabi.rs index 165d34fe6c7ce..b9f40accaeb72 100644 --- a/src/librustc_back/target/arm_unknown_linux_gnueabi.rs +++ b/src/librustc_back/target/arm_unknown_linux_gnueabi.rs @@ -18,6 +18,7 @@ pub fn target() -> TargetResult { llvm_target: "arm-unknown-linux-gnueabi".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/arm_unknown_linux_gnueabihf.rs b/src/librustc_back/target/arm_unknown_linux_gnueabihf.rs index 731021d979bc4..a3ea69caec646 100644 --- a/src/librustc_back/target/arm_unknown_linux_gnueabihf.rs +++ b/src/librustc_back/target/arm_unknown_linux_gnueabihf.rs @@ -18,6 +18,7 @@ pub fn target() -> TargetResult { llvm_target: "arm-unknown-linux-gnueabihf".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/arm_unknown_linux_musleabi.rs b/src/librustc_back/target/arm_unknown_linux_musleabi.rs index f81bcd78b03aa..598f722d9af7e 100644 --- a/src/librustc_back/target/arm_unknown_linux_musleabi.rs +++ b/src/librustc_back/target/arm_unknown_linux_musleabi.rs @@ -25,6 +25,7 @@ pub fn target() -> TargetResult { llvm_target: "arm-unknown-linux-gnueabi".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs index 6c47678ede6ad..ea0bf75b103c9 100644 --- a/src/librustc_back/target/arm_unknown_linux_musleabihf.rs +++ b/src/librustc_back/target/arm_unknown_linux_musleabihf.rs @@ -25,6 +25,7 @@ pub fn target() -> TargetResult { llvm_target: "arm-unknown-linux-gnueabihf".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/armv5te_unknown_linux_gnueabi.rs b/src/librustc_back/target/armv5te_unknown_linux_gnueabi.rs index ef00c9a3278b9..b95737216787b 100644 --- a/src/librustc_back/target/armv5te_unknown_linux_gnueabi.rs +++ b/src/librustc_back/target/armv5te_unknown_linux_gnueabi.rs @@ -17,6 +17,7 @@ pub fn target() -> TargetResult { llvm_target: "armv5te-unknown-linux-gnueabi".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/armv7_apple_ios.rs b/src/librustc_back/target/armv7_apple_ios.rs index 4d87458283294..67d3d12fb5776 100644 --- a/src/librustc_back/target/armv7_apple_ios.rs +++ b/src/librustc_back/target/armv7_apple_ios.rs @@ -18,6 +18,7 @@ pub fn target() -> TargetResult { llvm_target: "armv7-apple-ios".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(), arch: "arm".to_string(), target_os: "ios".to_string(), diff --git a/src/librustc_back/target/armv7_linux_androideabi.rs b/src/librustc_back/target/armv7_linux_androideabi.rs index 45654b0f87020..9e3eec13ab763 100644 --- a/src/librustc_back/target/armv7_linux_androideabi.rs +++ b/src/librustc_back/target/armv7_linux_androideabi.rs @@ -25,6 +25,7 @@ pub fn target() -> TargetResult { llvm_target: "armv7-none-linux-android".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "android".to_string(), diff --git a/src/librustc_back/target/armv7_unknown_linux_gnueabihf.rs b/src/librustc_back/target/armv7_unknown_linux_gnueabihf.rs index d3a6a68449c39..569c721473da5 100644 --- a/src/librustc_back/target/armv7_unknown_linux_gnueabihf.rs +++ b/src/librustc_back/target/armv7_unknown_linux_gnueabihf.rs @@ -17,6 +17,7 @@ pub fn target() -> TargetResult { llvm_target: "armv7-unknown-linux-gnueabihf".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs index 5086cd44f7ac9..a36e26c0b7d5f 100644 --- a/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs +++ b/src/librustc_back/target/armv7_unknown_linux_musleabihf.rs @@ -26,6 +26,7 @@ pub fn target() -> TargetResult { llvm_target: "armv7-unknown-linux-gnueabihf".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/armv7s_apple_ios.rs b/src/librustc_back/target/armv7s_apple_ios.rs index 96c89a7ed3bd5..e4cc89ab21140 100644 --- a/src/librustc_back/target/armv7s_apple_ios.rs +++ b/src/librustc_back/target/armv7s_apple_ios.rs @@ -18,6 +18,7 @@ pub fn target() -> TargetResult { llvm_target: "armv7s-apple-ios".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32".to_string(), arch: "arm".to_string(), target_os: "ios".to_string(), diff --git a/src/librustc_back/target/asmjs_unknown_emscripten.rs b/src/librustc_back/target/asmjs_unknown_emscripten.rs index b884d4e54101e..033e840f2020a 100644 --- a/src/librustc_back/target/asmjs_unknown_emscripten.rs +++ b/src/librustc_back/target/asmjs_unknown_emscripten.rs @@ -38,6 +38,7 @@ pub fn target() -> Result { llvm_target: "asmjs-unknown-emscripten".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), target_os: "emscripten".to_string(), target_env: "".to_string(), target_vendor: "unknown".to_string(), diff --git a/src/librustc_back/target/i386_apple_ios.rs b/src/librustc_back/target/i386_apple_ios.rs index 0e4e6900024b0..82eae1a31a9ad 100644 --- a/src/librustc_back/target/i386_apple_ios.rs +++ b/src/librustc_back/target/i386_apple_ios.rs @@ -18,6 +18,7 @@ pub fn target() -> TargetResult { llvm_target: "i386-apple-ios".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "ios".to_string(), diff --git a/src/librustc_back/target/i686_apple_darwin.rs b/src/librustc_back/target/i686_apple_darwin.rs index 8c931f18411ca..14937f9aa55b6 100644 --- a/src/librustc_back/target/i686_apple_darwin.rs +++ b/src/librustc_back/target/i686_apple_darwin.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-apple-darwin".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "macos".to_string(), diff --git a/src/librustc_back/target/i686_linux_android.rs b/src/librustc_back/target/i686_linux_android.rs index 565fbe37bf89e..bf27bce79acec 100644 --- a/src/librustc_back/target/i686_linux_android.rs +++ b/src/librustc_back/target/i686_linux_android.rs @@ -28,6 +28,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-linux-android".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "android".to_string(), diff --git a/src/librustc_back/target/i686_pc_windows_gnu.rs b/src/librustc_back/target/i686_pc_windows_gnu.rs index 4a736a93be7d7..5f20a620b6e1c 100644 --- a/src/librustc_back/target/i686_pc_windows_gnu.rs +++ b/src/librustc_back/target/i686_pc_windows_gnu.rs @@ -26,6 +26,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-pc-windows-gnu".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32".to_string(), arch: "x86".to_string(), target_os: "windows".to_string(), diff --git a/src/librustc_back/target/i686_pc_windows_msvc.rs b/src/librustc_back/target/i686_pc_windows_msvc.rs index 17fe306804f4a..48cee04457348 100644 --- a/src/librustc_back/target/i686_pc_windows_msvc.rs +++ b/src/librustc_back/target/i686_pc_windows_msvc.rs @@ -30,6 +30,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-pc-windows-msvc".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32".to_string(), arch: "x86".to_string(), target_os: "windows".to_string(), diff --git a/src/librustc_back/target/i686_unknown_dragonfly.rs b/src/librustc_back/target/i686_unknown_dragonfly.rs index 9eda49a3709a5..891127b9d3711 100644 --- a/src/librustc_back/target/i686_unknown_dragonfly.rs +++ b/src/librustc_back/target/i686_unknown_dragonfly.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-unknown-dragonfly".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "dragonfly".to_string(), diff --git a/src/librustc_back/target/i686_unknown_freebsd.rs b/src/librustc_back/target/i686_unknown_freebsd.rs index 041f3070c95bb..076acb8ed318c 100644 --- a/src/librustc_back/target/i686_unknown_freebsd.rs +++ b/src/librustc_back/target/i686_unknown_freebsd.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-unknown-freebsd".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "freebsd".to_string(), diff --git a/src/librustc_back/target/i686_unknown_haiku.rs b/src/librustc_back/target/i686_unknown_haiku.rs index f21c2f8c77ab0..02a15d6445c47 100644 --- a/src/librustc_back/target/i686_unknown_haiku.rs +++ b/src/librustc_back/target/i686_unknown_haiku.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-unknown-haiku".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "haiku".to_string(), diff --git a/src/librustc_back/target/i686_unknown_linux_gnu.rs b/src/librustc_back/target/i686_unknown_linux_gnu.rs index f7b916816b313..b509e019c7e1a 100644 --- a/src/librustc_back/target/i686_unknown_linux_gnu.rs +++ b/src/librustc_back/target/i686_unknown_linux_gnu.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-unknown-linux-gnu".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/i686_unknown_linux_musl.rs b/src/librustc_back/target/i686_unknown_linux_musl.rs index 00567d70fd6ce..99c0d4c817915 100644 --- a/src/librustc_back/target/i686_unknown_linux_musl.rs +++ b/src/librustc_back/target/i686_unknown_linux_musl.rs @@ -37,6 +37,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-unknown-linux-musl".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/i686_unknown_netbsd.rs b/src/librustc_back/target/i686_unknown_netbsd.rs index 7a9de529566b5..dd21c205106ea 100644 --- a/src/librustc_back/target/i686_unknown_netbsd.rs +++ b/src/librustc_back/target/i686_unknown_netbsd.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-unknown-netbsdelf".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "netbsd".to_string(), diff --git a/src/librustc_back/target/i686_unknown_openbsd.rs b/src/librustc_back/target/i686_unknown_openbsd.rs index b19bdbe049bcd..8daa5fcb88b3f 100644 --- a/src/librustc_back/target/i686_unknown_openbsd.rs +++ b/src/librustc_back/target/i686_unknown_openbsd.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "i686-unknown-openbsd".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128".to_string(), arch: "x86".to_string(), target_os: "openbsd".to_string(), diff --git a/src/librustc_back/target/le32_unknown_nacl.rs b/src/librustc_back/target/le32_unknown_nacl.rs index 51eeae50e22ee..9af4606f1f1f6 100644 --- a/src/librustc_back/target/le32_unknown_nacl.rs +++ b/src/librustc_back/target/le32_unknown_nacl.rs @@ -39,6 +39,7 @@ pub fn target() -> TargetResult { llvm_target: "le32-unknown-nacl".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), target_os: "nacl".to_string(), target_env: "newlib".to_string(), target_vendor: "unknown".to_string(), diff --git a/src/librustc_back/target/mips64_unknown_linux_gnuabi64.rs b/src/librustc_back/target/mips64_unknown_linux_gnuabi64.rs index 2d77902046109..5c3cf31b3e45f 100644 --- a/src/librustc_back/target/mips64_unknown_linux_gnuabi64.rs +++ b/src/librustc_back/target/mips64_unknown_linux_gnuabi64.rs @@ -16,6 +16,7 @@ pub fn target() -> TargetResult { llvm_target: "mips64-unknown-linux-gnuabi64".to_string(), target_endian: "big".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(), arch: "mips64".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/mips64el_unknown_linux_gnuabi64.rs b/src/librustc_back/target/mips64el_unknown_linux_gnuabi64.rs index c26780b9e65ce..96988388e811e 100644 --- a/src/librustc_back/target/mips64el_unknown_linux_gnuabi64.rs +++ b/src/librustc_back/target/mips64el_unknown_linux_gnuabi64.rs @@ -16,6 +16,7 @@ pub fn target() -> TargetResult { llvm_target: "mips64el-unknown-linux-gnuabi64".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(), arch: "mips64".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/mips_unknown_linux_gnu.rs b/src/librustc_back/target/mips_unknown_linux_gnu.rs index 24649851d76fd..5a43e1c4c7a0f 100644 --- a/src/librustc_back/target/mips_unknown_linux_gnu.rs +++ b/src/librustc_back/target/mips_unknown_linux_gnu.rs @@ -16,6 +16,7 @@ pub fn target() -> TargetResult { llvm_target: "mips-unknown-linux-gnu".to_string(), target_endian: "big".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), arch: "mips".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/mips_unknown_linux_musl.rs b/src/librustc_back/target/mips_unknown_linux_musl.rs index 6303722945c9f..3f6b984272ed5 100644 --- a/src/librustc_back/target/mips_unknown_linux_musl.rs +++ b/src/librustc_back/target/mips_unknown_linux_musl.rs @@ -16,6 +16,7 @@ pub fn target() -> TargetResult { llvm_target: "mips-unknown-linux-musl".to_string(), target_endian: "big".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), arch: "mips".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/mips_unknown_linux_uclibc.rs b/src/librustc_back/target/mips_unknown_linux_uclibc.rs index 1a7a56a977921..c851cab069a1c 100644 --- a/src/librustc_back/target/mips_unknown_linux_uclibc.rs +++ b/src/librustc_back/target/mips_unknown_linux_uclibc.rs @@ -16,6 +16,7 @@ pub fn target() -> TargetResult { llvm_target: "mips-unknown-linux-uclibc".to_string(), target_endian: "big".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), arch: "mips".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/mipsel_unknown_linux_gnu.rs b/src/librustc_back/target/mipsel_unknown_linux_gnu.rs index cbf8339993c86..2c38444d050fb 100644 --- a/src/librustc_back/target/mipsel_unknown_linux_gnu.rs +++ b/src/librustc_back/target/mipsel_unknown_linux_gnu.rs @@ -16,6 +16,7 @@ pub fn target() -> TargetResult { llvm_target: "mipsel-unknown-linux-gnu".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), arch: "mips".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/mipsel_unknown_linux_musl.rs b/src/librustc_back/target/mipsel_unknown_linux_musl.rs index b367bce75a1d9..464f0bfe48058 100644 --- a/src/librustc_back/target/mipsel_unknown_linux_musl.rs +++ b/src/librustc_back/target/mipsel_unknown_linux_musl.rs @@ -16,6 +16,7 @@ pub fn target() -> TargetResult { llvm_target: "mipsel-unknown-linux-musl".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), arch: "mips".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/mipsel_unknown_linux_uclibc.rs b/src/librustc_back/target/mipsel_unknown_linux_uclibc.rs index 686dfbe987d10..5d2ba548769ff 100644 --- a/src/librustc_back/target/mipsel_unknown_linux_uclibc.rs +++ b/src/librustc_back/target/mipsel_unknown_linux_uclibc.rs @@ -16,6 +16,7 @@ pub fn target() -> TargetResult { llvm_target: "mipsel-unknown-linux-uclibc".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".to_string(), arch: "mips".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 27a0855dc29fe..b1b208d2de4f1 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -239,6 +239,8 @@ pub struct Target { pub target_endian: String, /// String to use as the `target_pointer_width` `cfg` variable. pub target_pointer_width: String, + /// Width of c_int type + pub target_c_int_width: String, /// OS name to use for conditional compilation. pub target_os: String, /// Environment name to use for conditional compilation. @@ -556,6 +558,7 @@ impl Target { llvm_target: get_req_field("llvm-target")?, target_endian: get_req_field("target-endian")?, target_pointer_width: get_req_field("target-pointer-width")?, + target_c_int_width: get_req_field("target-c-int-width")?, data_layout: get_req_field("data-layout")?, arch: get_req_field("arch")?, target_os: get_req_field("os")?, @@ -860,6 +863,7 @@ impl ToJson for Target { target_val!(llvm_target); target_val!(target_endian); target_val!(target_pointer_width); + target_val!(target_c_int_width); target_val!(arch); target_val!(target_os, "os"); target_val!(target_env, "env"); diff --git a/src/librustc_back/target/msp430_none_elf.rs b/src/librustc_back/target/msp430_none_elf.rs index 588a8bde79b98..e3851ec0829dd 100644 --- a/src/librustc_back/target/msp430_none_elf.rs +++ b/src/librustc_back/target/msp430_none_elf.rs @@ -16,6 +16,7 @@ pub fn target() -> TargetResult { llvm_target: "msp430-none-elf".to_string(), target_endian: "little".to_string(), target_pointer_width: "16".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16".to_string(), arch: "msp430".to_string(), target_os: "none".to_string(), diff --git a/src/librustc_back/target/powerpc64_unknown_linux_gnu.rs b/src/librustc_back/target/powerpc64_unknown_linux_gnu.rs index 7b038ac007396..1f119c7204b16 100644 --- a/src/librustc_back/target/powerpc64_unknown_linux_gnu.rs +++ b/src/librustc_back/target/powerpc64_unknown_linux_gnu.rs @@ -28,6 +28,7 @@ pub fn target() -> TargetResult { llvm_target: "powerpc64-unknown-linux-gnu".to_string(), target_endian: "big".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "E-m:e-i64:64-n32:64".to_string(), arch: "powerpc64".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/powerpc64le_unknown_linux_gnu.rs b/src/librustc_back/target/powerpc64le_unknown_linux_gnu.rs index 5b50b96837fbe..13c59785d480b 100644 --- a/src/librustc_back/target/powerpc64le_unknown_linux_gnu.rs +++ b/src/librustc_back/target/powerpc64le_unknown_linux_gnu.rs @@ -24,6 +24,7 @@ pub fn target() -> TargetResult { llvm_target: "powerpc64le-unknown-linux-gnu".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-n32:64".to_string(), arch: "powerpc64".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/powerpc_unknown_linux_gnu.rs b/src/librustc_back/target/powerpc_unknown_linux_gnu.rs index 8d4ad5f0b447f..1797126b3104a 100644 --- a/src/librustc_back/target/powerpc_unknown_linux_gnu.rs +++ b/src/librustc_back/target/powerpc_unknown_linux_gnu.rs @@ -23,6 +23,7 @@ pub fn target() -> TargetResult { llvm_target: "powerpc-unknown-linux-gnu".to_string(), target_endian: "big".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "E-m:e-p:32:32-i64:64-n32".to_string(), arch: "powerpc".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/s390x_unknown_linux_gnu.rs b/src/librustc_back/target/s390x_unknown_linux_gnu.rs index aad9effacd440..d96379547fb0f 100644 --- a/src/librustc_back/target/s390x_unknown_linux_gnu.rs +++ b/src/librustc_back/target/s390x_unknown_linux_gnu.rs @@ -28,6 +28,7 @@ pub fn target() -> TargetResult { llvm_target: "s390x-unknown-linux-gnu".to_string(), target_endian: "big".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64".to_string(), arch: "s390x".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/sparc64_unknown_linux_gnu.rs b/src/librustc_back/target/sparc64_unknown_linux_gnu.rs index 7f710ad402053..aed40e9df436e 100644 --- a/src/librustc_back/target/sparc64_unknown_linux_gnu.rs +++ b/src/librustc_back/target/sparc64_unknown_linux_gnu.rs @@ -21,6 +21,7 @@ pub fn target() -> TargetResult { llvm_target: "sparc64-unknown-linux-gnu".to_string(), target_endian: "big".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "E-m:e-i64:64-n32:64-S128".to_string(), arch: "sparc64".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/sparc64_unknown_netbsd.rs b/src/librustc_back/target/sparc64_unknown_netbsd.rs index bc65a17ce6ea9..483c87909455d 100644 --- a/src/librustc_back/target/sparc64_unknown_netbsd.rs +++ b/src/librustc_back/target/sparc64_unknown_netbsd.rs @@ -21,6 +21,7 @@ pub fn target() -> TargetResult { llvm_target: "sparc64-unknown-netbsd".to_string(), target_endian: "big".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "E-m:e-i64:64-n32:64-S128".to_string(), arch: "sparc64".to_string(), target_os: "netbsd".to_string(), diff --git a/src/librustc_back/target/sparcv9_sun_solaris.rs b/src/librustc_back/target/sparcv9_sun_solaris.rs index 122b38968a9c0..bfe1afebdb3a3 100644 --- a/src/librustc_back/target/sparcv9_sun_solaris.rs +++ b/src/librustc_back/target/sparcv9_sun_solaris.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "sparcv9-sun-solaris".to_string(), target_endian: "big".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "E-m:e-i64:64-n32:64-S128".to_string(), // Use "sparc64" instead of "sparcv9" here, since the former is already // used widely in the source base. If we ever needed ABI diff --git a/src/librustc_back/target/thumbv6m_none_eabi.rs b/src/librustc_back/target/thumbv6m_none_eabi.rs index 08bf145e5518a..d164fbf9d96f9 100644 --- a/src/librustc_back/target/thumbv6m_none_eabi.rs +++ b/src/librustc_back/target/thumbv6m_none_eabi.rs @@ -18,6 +18,7 @@ pub fn target() -> TargetResult { llvm_target: "thumbv6m-none-eabi".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "none".to_string(), diff --git a/src/librustc_back/target/thumbv7em_none_eabi.rs b/src/librustc_back/target/thumbv7em_none_eabi.rs index 13f9cc5f65fb9..7e66ddf7b06a7 100644 --- a/src/librustc_back/target/thumbv7em_none_eabi.rs +++ b/src/librustc_back/target/thumbv7em_none_eabi.rs @@ -27,6 +27,7 @@ pub fn target() -> TargetResult { llvm_target: "thumbv7em-none-eabi".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "none".to_string(), diff --git a/src/librustc_back/target/thumbv7em_none_eabihf.rs b/src/librustc_back/target/thumbv7em_none_eabihf.rs index 929b6db6fb2c6..31835de36d6a4 100644 --- a/src/librustc_back/target/thumbv7em_none_eabihf.rs +++ b/src/librustc_back/target/thumbv7em_none_eabihf.rs @@ -26,6 +26,7 @@ pub fn target() -> TargetResult { llvm_target: "thumbv7em-none-eabihf".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "none".to_string(), diff --git a/src/librustc_back/target/thumbv7m_none_eabi.rs b/src/librustc_back/target/thumbv7m_none_eabi.rs index 8d46e7cb90760..8f16ae4ea12df 100644 --- a/src/librustc_back/target/thumbv7m_none_eabi.rs +++ b/src/librustc_back/target/thumbv7m_none_eabi.rs @@ -18,6 +18,7 @@ pub fn target() -> TargetResult { llvm_target: "thumbv7m-none-eabi".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), arch: "arm".to_string(), target_os: "none".to_string(), diff --git a/src/librustc_back/target/wasm32_experimental_emscripten.rs b/src/librustc_back/target/wasm32_experimental_emscripten.rs index 42ab19404049e..71668444d9aec 100644 --- a/src/librustc_back/target/wasm32_experimental_emscripten.rs +++ b/src/librustc_back/target/wasm32_experimental_emscripten.rs @@ -46,6 +46,7 @@ pub fn target() -> Result { llvm_target: "wasm32-unknown-unknown".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), target_os: "emscripten".to_string(), target_env: "".to_string(), target_vendor: "unknown".to_string(), diff --git a/src/librustc_back/target/wasm32_unknown_emscripten.rs b/src/librustc_back/target/wasm32_unknown_emscripten.rs index a0a2699d8f951..e6584addf4aef 100644 --- a/src/librustc_back/target/wasm32_unknown_emscripten.rs +++ b/src/librustc_back/target/wasm32_unknown_emscripten.rs @@ -42,6 +42,7 @@ pub fn target() -> Result { llvm_target: "asmjs-unknown-emscripten".to_string(), target_endian: "little".to_string(), target_pointer_width: "32".to_string(), + target_c_int_width: "32".to_string(), target_os: "emscripten".to_string(), target_env: "".to_string(), target_vendor: "unknown".to_string(), diff --git a/src/librustc_back/target/x86_64_apple_darwin.rs b/src/librustc_back/target/x86_64_apple_darwin.rs index 8ac76679008e9..71ac360eb9906 100644 --- a/src/librustc_back/target/x86_64_apple_darwin.rs +++ b/src/librustc_back/target/x86_64_apple_darwin.rs @@ -23,6 +23,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-apple-darwin".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "macos".to_string(), diff --git a/src/librustc_back/target/x86_64_apple_ios.rs b/src/librustc_back/target/x86_64_apple_ios.rs index 61a71da2162a0..eed99e3784ce0 100644 --- a/src/librustc_back/target/x86_64_apple_ios.rs +++ b/src/librustc_back/target/x86_64_apple_ios.rs @@ -18,6 +18,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-apple-ios".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:o-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "ios".to_string(), diff --git a/src/librustc_back/target/x86_64_linux_android.rs b/src/librustc_back/target/x86_64_linux_android.rs index 158e2b13604ec..2aae73941539f 100644 --- a/src/librustc_back/target/x86_64_linux_android.rs +++ b/src/librustc_back/target/x86_64_linux_android.rs @@ -24,6 +24,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-linux-android".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "android".to_string(), diff --git a/src/librustc_back/target/x86_64_pc_windows_gnu.rs b/src/librustc_back/target/x86_64_pc_windows_gnu.rs index 10e88d88ee372..70062d1363841 100644 --- a/src/librustc_back/target/x86_64_pc_windows_gnu.rs +++ b/src/librustc_back/target/x86_64_pc_windows_gnu.rs @@ -21,6 +21,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-pc-windows-gnu".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:w-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "windows".to_string(), diff --git a/src/librustc_back/target/x86_64_pc_windows_msvc.rs b/src/librustc_back/target/x86_64_pc_windows_msvc.rs index 7eb673d8b363c..813d0f1bad947 100644 --- a/src/librustc_back/target/x86_64_pc_windows_msvc.rs +++ b/src/librustc_back/target/x86_64_pc_windows_msvc.rs @@ -21,6 +21,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-pc-windows-msvc".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:w-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "windows".to_string(), diff --git a/src/librustc_back/target/x86_64_rumprun_netbsd.rs b/src/librustc_back/target/x86_64_rumprun_netbsd.rs index c7e5edde63db3..ab5a6f71ebc42 100644 --- a/src/librustc_back/target/x86_64_rumprun_netbsd.rs +++ b/src/librustc_back/target/x86_64_rumprun_netbsd.rs @@ -31,6 +31,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-rumprun-netbsd".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "netbsd".to_string(), diff --git a/src/librustc_back/target/x86_64_sun_solaris.rs b/src/librustc_back/target/x86_64_sun_solaris.rs index 38a38ed68bc92..d554138539083 100644 --- a/src/librustc_back/target/x86_64_sun_solaris.rs +++ b/src/librustc_back/target/x86_64_sun_solaris.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-pc-solaris".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "solaris".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_bitrig.rs b/src/librustc_back/target/x86_64_unknown_bitrig.rs index cf4b019dce2df..1ea985d70eaca 100644 --- a/src/librustc_back/target/x86_64_unknown_bitrig.rs +++ b/src/librustc_back/target/x86_64_unknown_bitrig.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-bitrig".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "bitrig".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_dragonfly.rs b/src/librustc_back/target/x86_64_unknown_dragonfly.rs index 8885d89c6f7a8..56e4685fed5b4 100644 --- a/src/librustc_back/target/x86_64_unknown_dragonfly.rs +++ b/src/librustc_back/target/x86_64_unknown_dragonfly.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-dragonfly".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "dragonfly".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_freebsd.rs b/src/librustc_back/target/x86_64_unknown_freebsd.rs index 95870f2be5fc0..3d26592530abf 100644 --- a/src/librustc_back/target/x86_64_unknown_freebsd.rs +++ b/src/librustc_back/target/x86_64_unknown_freebsd.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-freebsd".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "freebsd".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_fuchsia.rs b/src/librustc_back/target/x86_64_unknown_fuchsia.rs index 1aebb885595e2..6e97d53cfad6a 100644 --- a/src/librustc_back/target/x86_64_unknown_fuchsia.rs +++ b/src/librustc_back/target/x86_64_unknown_fuchsia.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-fuchsia".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "fuchsia".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_haiku.rs b/src/librustc_back/target/x86_64_unknown_haiku.rs index 3794a516ec4a8..f42c480e7a117 100644 --- a/src/librustc_back/target/x86_64_unknown_haiku.rs +++ b/src/librustc_back/target/x86_64_unknown_haiku.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-haiku".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "haiku".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs b/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs index 99d3171e1c0e0..6e849f19cf20f 100644 --- a/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs +++ b/src/librustc_back/target/x86_64_unknown_l4re_uclibc.rs @@ -20,6 +20,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-l4re-uclibc".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "l4re".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_linux_gnu.rs b/src/librustc_back/target/x86_64_unknown_linux_gnu.rs index d2135f8a0bdce..cfe80c96732bf 100644 --- a/src/librustc_back/target/x86_64_unknown_linux_gnu.rs +++ b/src/librustc_back/target/x86_64_unknown_linux_gnu.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-linux-gnu".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_linux_musl.rs b/src/librustc_back/target/x86_64_unknown_linux_musl.rs index 7d542b4d3cb5a..7e304748e3207 100644 --- a/src/librustc_back/target/x86_64_unknown_linux_musl.rs +++ b/src/librustc_back/target/x86_64_unknown_linux_musl.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-linux-musl".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "linux".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_netbsd.rs b/src/librustc_back/target/x86_64_unknown_netbsd.rs index 5d49fcbd64ab1..7afb446f5dc97 100644 --- a/src/librustc_back/target/x86_64_unknown_netbsd.rs +++ b/src/librustc_back/target/x86_64_unknown_netbsd.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-netbsd".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "netbsd".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_openbsd.rs b/src/librustc_back/target/x86_64_unknown_openbsd.rs index aa289fb577501..e4bbdbec4c850 100644 --- a/src/librustc_back/target/x86_64_unknown_openbsd.rs +++ b/src/librustc_back/target/x86_64_unknown_openbsd.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-openbsd".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "openbsd".to_string(), diff --git a/src/librustc_back/target/x86_64_unknown_redox.rs b/src/librustc_back/target/x86_64_unknown_redox.rs index 8d2a7afeeacf0..401fa4ca2cbdd 100644 --- a/src/librustc_back/target/x86_64_unknown_redox.rs +++ b/src/librustc_back/target/x86_64_unknown_redox.rs @@ -22,6 +22,7 @@ pub fn target() -> TargetResult { llvm_target: "x86_64-unknown-redox".to_string(), target_endian: "little".to_string(), target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), arch: "x86_64".to_string(), target_os: "redox".to_string(), diff --git a/src/librustc_trans/type_.rs b/src/librustc_trans/type_.rs index 65fdd72bd29e0..ffb303688aaf6 100644 --- a/src/librustc_trans/type_.rs +++ b/src/librustc_trans/type_.rs @@ -141,7 +141,12 @@ impl Type { } pub fn c_int(ccx: &CrateContext) -> Type { - Type::i32(ccx) + match &ccx.tcx().sess.target.target.target_c_int_width[..] { + "16" => Type::i16(ccx), + "32" => Type::i32(ccx), + "64" => Type::i64(ccx), + width => bug!("Unsupported target_c_int_width: {}", width), + } } pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type { From 12a8bc6eb916c3b8a61ad813c2e15aac8184c357 Mon Sep 17 00:00:00 2001 From: Daniel Klauer Date: Sat, 30 Sep 2017 13:48:12 +0200 Subject: [PATCH 5/6] rustc: Use 16bit c_int for msp430 Fix regression from c2fe69b9, where main() signature was changed from using 16bit isize to 32bit c_int for argc parameter/result. --- src/librustc_back/target/msp430_none_elf.rs | 2 +- .../codegen/abi-main-signature-16bit-c-int.rs | 32 +++++++++++++++++++ ...e.rs => abi-main-signature-32bit-c-int.rs} | 3 ++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/test/codegen/abi-main-signature-16bit-c-int.rs rename src/test/codegen/{abi-main-signature.rs => abi-main-signature-32bit-c-int.rs} (90%) diff --git a/src/librustc_back/target/msp430_none_elf.rs b/src/librustc_back/target/msp430_none_elf.rs index e3851ec0829dd..9227a96e75049 100644 --- a/src/librustc_back/target/msp430_none_elf.rs +++ b/src/librustc_back/target/msp430_none_elf.rs @@ -16,7 +16,7 @@ pub fn target() -> TargetResult { llvm_target: "msp430-none-elf".to_string(), target_endian: "little".to_string(), target_pointer_width: "16".to_string(), - target_c_int_width: "32".to_string(), + target_c_int_width: "16".to_string(), data_layout: "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16".to_string(), arch: "msp430".to_string(), target_os: "none".to_string(), diff --git a/src/test/codegen/abi-main-signature-16bit-c-int.rs b/src/test/codegen/abi-main-signature-16bit-c-int.rs new file mode 100644 index 0000000000000..fbe2fd10e7a14 --- /dev/null +++ b/src/test/codegen/abi-main-signature-16bit-c-int.rs @@ -0,0 +1,32 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Checks the signature of the implicitly generated native main() +// entry point. It must match C's `int main(int, char **)`. + +// This test is for targets with 16bit c_int only. +// ignore-aarch64 +// ignore-arm +// ignore-asmjs +// ignore-hexagon +// ignore-mips +// ignore-powerpc +// ignore-powerpc64 +// ignore-s390x +// ignore-sparc +// ignore-wasm32 +// ignore-x86 +// ignore-x86_64 +// ignore-xcore + +fn main() { +} + +// CHECK: define i16 @main(i16, i8**) diff --git a/src/test/codegen/abi-main-signature.rs b/src/test/codegen/abi-main-signature-32bit-c-int.rs similarity index 90% rename from src/test/codegen/abi-main-signature.rs rename to src/test/codegen/abi-main-signature-32bit-c-int.rs index 3d09e0d9e6f36..3139749dfcb06 100644 --- a/src/test/codegen/abi-main-signature.rs +++ b/src/test/codegen/abi-main-signature-32bit-c-int.rs @@ -11,6 +11,9 @@ // Checks the signature of the implicitly generated native main() // entry point. It must match C's `int main(int, char **)`. +// This test is for targets with 32bit c_int only. +// ignore-msp430 + fn main() { } From a4e83731e9aa0cd1a412b090626ace6aa54250bb Mon Sep 17 00:00:00 2001 From: Daniel Klauer Date: Sat, 30 Sep 2017 23:45:36 +0200 Subject: [PATCH 6/6] test: Update target specs test for new target-c-int-width field --- src/test/run-make/target-specs/my-awesome-platform.json | 1 + src/test/run-make/target-specs/my-incomplete-platform.json | 1 + src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json | 1 + 3 files changed, 3 insertions(+) diff --git a/src/test/run-make/target-specs/my-awesome-platform.json b/src/test/run-make/target-specs/my-awesome-platform.json index 14515ad7f00b9..8d028280a8da7 100644 --- a/src/test/run-make/target-specs/my-awesome-platform.json +++ b/src/test/run-make/target-specs/my-awesome-platform.json @@ -4,6 +4,7 @@ "llvm-target": "i686-unknown-linux-gnu", "target-endian": "little", "target-pointer-width": "32", + "target-c-int-width": "32", "arch": "x86", "os": "linux", "morestack": false diff --git a/src/test/run-make/target-specs/my-incomplete-platform.json b/src/test/run-make/target-specs/my-incomplete-platform.json index 74787b28d2233..ceaa25cdf2fef 100644 --- a/src/test/run-make/target-specs/my-incomplete-platform.json +++ b/src/test/run-make/target-specs/my-incomplete-platform.json @@ -3,6 +3,7 @@ "linker-flavor": "gcc", "target-endian": "little", "target-pointer-width": "32", + "target-c-int-width": "32", "arch": "x86", "os": "foo", "morestack": false diff --git a/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json b/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json index cfe152f9e8728..c1dd0cf406366 100644 --- a/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json +++ b/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json @@ -5,6 +5,7 @@ "llvm-target": "x86_64-unknown-linux-gnu", "target-endian": "little", "target-pointer-width": "64", + "target-c-int-width": "32", "arch": "x86_64", "os": "linux", "morestack": false