Skip to content

Commit 2407761

Browse files
authored
Rollup merge of #142352 - workingjubilee:c-int-width-is-an-integer, r=wesleywiser
compiler: Make `c_int_width` an integer Because it is. That's all I got.
2 parents 78d8395 + 87feee9 commit 2407761

File tree

10 files changed

+24
-26
lines changed

10 files changed

+24
-26
lines changed

compiler/rustc_codegen_ssa/src/traits/type_.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ pub trait DerivedTypeCodegenMethods<'tcx>:
4444
BaseTypeCodegenMethods + MiscCodegenMethods<'tcx> + HasTyCtxt<'tcx> + HasTypingEnv<'tcx>
4545
{
4646
fn type_int(&self) -> Self::Type {
47-
match &self.sess().target.c_int_width[..] {
48-
"16" => self.type_i16(),
49-
"32" => self.type_i32(),
50-
"64" => self.type_i64(),
47+
match &self.sess().target.c_int_width {
48+
16 => self.type_i16(),
49+
32 => self.type_i32(),
50+
64 => self.type_i64(),
5151
width => bug!("Unsupported c_int_width: {}", width),
5252
}
5353
}

compiler/rustc_target/src/spec/base/xtensa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub(crate) fn opts() -> TargetOptions {
66
TargetOptions {
77
os: "none".into(),
88
endian: Endian::Little,
9-
c_int_width: "32".into(),
9+
c_int_width: 32,
1010
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
1111
executables: true,
1212
panic_strategy: PanicStrategy::Abort,

compiler/rustc_target/src/spec/json.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ impl Target {
8080
base.$key_name = s;
8181
}
8282
} );
83+
($key_name:ident = $json_name:expr, u64 as $int_ty:ty) => ( {
84+
let name = $json_name;
85+
if let Some(s) = obj.remove(name).and_then(|b| b.as_u64()) {
86+
base.$key_name = s as $int_ty;
87+
}
88+
} );
8389
($key_name:ident, bool) => ( {
8490
let name = (stringify!($key_name)).replace("_", "-");
8591
if let Some(s) = obj.remove(&name).and_then(|b| b.as_bool()) {
@@ -554,7 +560,7 @@ impl Target {
554560
}
555561
}
556562

557-
key!(c_int_width = "target-c-int-width");
563+
key!(c_int_width = "target-c-int-width", u64 as u16);
558564
key!(c_enum_min_bits, Option<u64>); // if None, matches c_int_width
559565
key!(os);
560566
key!(env);

compiler/rustc_target/src/spec/mod.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,18 +2213,10 @@ impl Target {
22132213
});
22142214
}
22152215

2216-
dl.c_enum_min_size = self
2217-
.c_enum_min_bits
2218-
.map_or_else(
2219-
|| {
2220-
self.c_int_width
2221-
.parse()
2222-
.map_err(|_| String::from("failed to parse c_int_width"))
2223-
},
2224-
Ok,
2225-
)
2226-
.and_then(|i| Integer::from_size(Size::from_bits(i)))
2227-
.map_err(|err| TargetDataLayoutErrors::InvalidBitsSize { err })?;
2216+
dl.c_enum_min_size = Integer::from_size(Size::from_bits(
2217+
self.c_enum_min_bits.unwrap_or(self.c_int_width as _),
2218+
))
2219+
.map_err(|err| TargetDataLayoutErrors::InvalidBitsSize { err })?;
22282220

22292221
Ok(dl)
22302222
}
@@ -2286,7 +2278,7 @@ pub struct TargetOptions {
22862278
/// Used as the `target_endian` `cfg` variable. Defaults to little endian.
22872279
pub endian: Endian,
22882280
/// Width of c_int type. Defaults to "32".
2289-
pub c_int_width: StaticCow<str>,
2281+
pub c_int_width: u16,
22902282
/// OS name to use for conditional compilation (`target_os`). Defaults to "none".
22912283
/// "none" implies a bare metal target without `std` library.
22922284
/// A couple of targets having `std` also use "unknown" as an `os` value,
@@ -2783,7 +2775,7 @@ impl Default for TargetOptions {
27832775
fn default() -> TargetOptions {
27842776
TargetOptions {
27852777
endian: Endian::Little,
2786-
c_int_width: "32".into(),
2778+
c_int_width: 32,
27872779
os: "none".into(),
27882780
env: "".into(),
27892781
abi: "".into(),

compiler/rustc_target/src/spec/targets/armv7_sony_vita_newlibeabihf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) fn target() -> Target {
3131
options: TargetOptions {
3232
os: "vita".into(),
3333
endian: Endian::Little,
34-
c_int_width: "32".into(),
34+
c_int_width: 32,
3535
env: "newlib".into(),
3636
vendor: "sony".into(),
3737
abi: "eabihf".into(),

compiler/rustc_target/src/spec/targets/avr_none.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn target() -> Target {
1313
llvm_target: "avr-unknown-unknown".into(),
1414
pointer_width: 16,
1515
options: TargetOptions {
16-
c_int_width: "16".into(),
16+
c_int_width: 16,
1717
exe_suffix: ".elf".into(),
1818
linker: Some("avr-gcc".into()),
1919
eh_frame_header: false,

compiler/rustc_target/src/spec/targets/msp430_none_elf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) fn target() -> Target {
1616
arch: "msp430".into(),
1717

1818
options: TargetOptions {
19-
c_int_width: "16".into(),
19+
c_int_width: 16,
2020

2121
// The LLVM backend currently can't generate object files. To
2222
// workaround this LLVM generates assembly files which then we feed

compiler/rustc_target/src/spec/targets/xtensa_esp32_espidf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn target() -> Target {
1313

1414
options: TargetOptions {
1515
endian: Endian::Little,
16-
c_int_width: "32".into(),
16+
c_int_width: 32,
1717
families: cvs!["unix"],
1818
os: "espidf".into(),
1919
env: "newlib".into(),

compiler/rustc_target/src/spec/targets/xtensa_esp32s2_espidf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn target() -> Target {
1313

1414
options: TargetOptions {
1515
endian: Endian::Little,
16-
c_int_width: "32".into(),
16+
c_int_width: 32,
1717
families: cvs!["unix"],
1818
os: "espidf".into(),
1919
env: "newlib".into(),

compiler/rustc_target/src/spec/targets/xtensa_esp32s3_espidf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn target() -> Target {
1313

1414
options: TargetOptions {
1515
endian: Endian::Little,
16-
c_int_width: "32".into(),
16+
c_int_width: 32,
1717
families: cvs!["unix"],
1818
os: "espidf".into(),
1919
env: "newlib".into(),

0 commit comments

Comments
 (0)