Rollup merge of #87922 - Manishearth:c-enum-target-spec, r=nagisa,eddyb
Add c_enum_min_bits target spec field, use for arm-none and thumb-none targets Fixes https://github.com/rust-lang/rust/issues/87917 <s>Haven't tested this yet, still playing around.</s> This seems to fix the issue.
This commit is contained in:
commit
692833a28f
13 changed files with 529 additions and 16 deletions
|
@ -36,6 +36,9 @@ pub struct TargetDataLayout {
|
|||
pub vector_align: Vec<(Size, AbiAndPrefAlign)>,
|
||||
|
||||
pub instruction_address_space: AddressSpace,
|
||||
|
||||
/// Minimum size of #[repr(C)] enums (default I32 bits)
|
||||
pub c_enum_min_size: Integer,
|
||||
}
|
||||
|
||||
impl Default for TargetDataLayout {
|
||||
|
@ -60,6 +63,7 @@ impl Default for TargetDataLayout {
|
|||
(Size::from_bits(128), AbiAndPrefAlign::new(align(128))),
|
||||
],
|
||||
instruction_address_space: AddressSpace::DATA,
|
||||
c_enum_min_size: Integer::I32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -173,6 +177,8 @@ impl TargetDataLayout {
|
|||
));
|
||||
}
|
||||
|
||||
dl.c_enum_min_size = Integer::from_size(Size::from_bits(target.c_enum_min_bits))?;
|
||||
|
||||
Ok(dl)
|
||||
}
|
||||
|
||||
|
@ -610,6 +616,17 @@ impl Integer {
|
|||
}
|
||||
I8
|
||||
}
|
||||
|
||||
fn from_size(size: Size) -> Result<Self, String> {
|
||||
match size.bits() {
|
||||
8 => Ok(Integer::I8),
|
||||
16 => Ok(Integer::I16),
|
||||
32 => Ok(Integer::I32),
|
||||
64 => Ok(Integer::I64),
|
||||
128 => Ok(Integer::I128),
|
||||
_ => Err(format!("rust does not support integers with {} bits", size.bits())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Fundamental unit of memory access and layout.
|
||||
|
|
|
@ -20,6 +20,8 @@ pub fn target() -> Target {
|
|||
panic_strategy: PanicStrategy::Abort,
|
||||
max_atomic_width: Some(32),
|
||||
emit_debug_gdb_scripts: false,
|
||||
// GCC and Clang default to 8 for arm-none here
|
||||
c_enum_min_bits: 8,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ pub fn target() -> Target {
|
|||
features: "+vfp3,-d32,-fp16".to_string(),
|
||||
max_atomic_width: Some(32),
|
||||
emit_debug_gdb_scripts: false,
|
||||
// GCC and Clang default to 8 for arm-none here
|
||||
c_enum_min_bits: 8,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ pub fn target() -> Target {
|
|||
max_atomic_width: Some(64),
|
||||
panic_strategy: PanicStrategy::Abort,
|
||||
emit_debug_gdb_scripts: false,
|
||||
c_enum_min_bits: 8,
|
||||
..Default::default()
|
||||
};
|
||||
Target {
|
||||
|
|
|
@ -19,6 +19,8 @@ pub fn target() -> Target {
|
|||
max_atomic_width: Some(64),
|
||||
panic_strategy: PanicStrategy::Abort,
|
||||
emit_debug_gdb_scripts: false,
|
||||
// GCC and Clang default to 8 for arm-none here
|
||||
c_enum_min_bits: 8,
|
||||
..Default::default()
|
||||
};
|
||||
Target {
|
||||
|
|
|
@ -19,6 +19,8 @@ pub fn target() -> Target {
|
|||
panic_strategy: PanicStrategy::Abort,
|
||||
max_atomic_width: Some(32),
|
||||
emit_debug_gdb_scripts: false,
|
||||
// GCC and Clang default to 8 for arm-none here
|
||||
c_enum_min_bits: 8,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ pub fn target() -> Target {
|
|||
features: "+vfp3,-d32,-fp16".to_string(),
|
||||
max_atomic_width: Some(32),
|
||||
emit_debug_gdb_scripts: false,
|
||||
// GCC and Clang default to 8 for arm-none here
|
||||
c_enum_min_bits: 8,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ pub fn target() -> Target {
|
|||
base.dynamic_linking = true;
|
||||
base.executables = true;
|
||||
|
||||
base.c_enum_min_bits = 8;
|
||||
|
||||
Target {
|
||||
llvm_target: "hexagon-unknown-linux-musl".to_string(),
|
||||
pointer_width: 32,
|
||||
|
|
|
@ -1336,6 +1336,9 @@ pub struct TargetOptions {
|
|||
|
||||
/// If present it's a default value to use for adjusting the C ABI.
|
||||
pub default_adjusted_cabi: Option<Abi>,
|
||||
|
||||
/// Minimum number of bits in #[repr(C)] enum. Defaults to 32.
|
||||
pub c_enum_min_bits: u64,
|
||||
}
|
||||
|
||||
impl Default for TargetOptions {
|
||||
|
@ -1440,6 +1443,7 @@ impl Default for TargetOptions {
|
|||
split_debuginfo: SplitDebuginfo::Off,
|
||||
supported_sanitizers: SanitizerSet::empty(),
|
||||
default_adjusted_cabi: None,
|
||||
c_enum_min_bits: 32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1604,6 +1608,12 @@ impl Target {
|
|||
base.$key_name = s;
|
||||
}
|
||||
} );
|
||||
($key_name:ident, u64) => ( {
|
||||
let name = (stringify!($key_name)).replace("_", "-");
|
||||
if let Some(s) = obj.remove_key(&name).and_then(|j| Json::as_u64(&j)) {
|
||||
base.$key_name = s;
|
||||
}
|
||||
} );
|
||||
($key_name:ident, Option<u32>) => ( {
|
||||
let name = (stringify!($key_name)).replace("_", "-");
|
||||
if let Some(s) = obj.remove_key(&name).and_then(|j| Json::as_u64(&j)) {
|
||||
|
@ -2017,6 +2027,7 @@ impl Target {
|
|||
key!(split_debuginfo, SplitDebuginfo)?;
|
||||
key!(supported_sanitizers, SanitizerSet)?;
|
||||
key!(default_adjusted_cabi, Option<Abi>)?;
|
||||
key!(c_enum_min_bits, u64);
|
||||
|
||||
if base.is_builtin {
|
||||
// This can cause unfortunate ICEs later down the line.
|
||||
|
@ -2255,6 +2266,7 @@ impl ToJson for Target {
|
|||
target_option_val!(has_thumb_interworking);
|
||||
target_option_val!(split_debuginfo);
|
||||
target_option_val!(supported_sanitizers);
|
||||
target_option_val!(c_enum_min_bits);
|
||||
|
||||
if let Some(abi) = self.default_adjusted_cabi {
|
||||
d.insert("default-adjusted-cabi".to_string(), Abi::name(abi).to_json());
|
||||
|
|
|
@ -53,6 +53,9 @@ pub fn opts() -> TargetOptions {
|
|||
// LLVM is eager to trash the link register when calling `noreturn` functions, which
|
||||
// breaks debugging. Preserve LR by default to prevent that from happening.
|
||||
frame_pointer: FramePointer::Always,
|
||||
// ARM supports multiple ABIs for enums, the linux one matches the default of 32 here
|
||||
// but any arm-none or thumb-none target will be defaulted to 8 on GCC and clang
|
||||
c_enum_min_bits: 8,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue