1
Fork 0

De-duplicate and improve definition of core::ffi::c_char

Instead of having a list of unsigned char targets for each OS, follow the
logic Clang uses and instead set the value based on architecture with
a special case for Darwin and Windows operating systems. This makes it
easier to support new operating systems targeting Arm/AArch64 without
having to modify this config statement for each new OS. The new list does
not quite match Clang since I noticed a few bugs in the Clang
implementation (https://github.com/llvm/llvm-project/issues/115957).

Fixes: https://github.com/rust-lang/rust/issues/129945
This commit is contained in:
Alex Richardson 2024-11-12 17:27:52 -08:00
parent 33c245b9e9
commit 028ca8e616

View file

@ -91,59 +91,30 @@ pub type c_ssize_t = isize;
mod c_char_definition { mod c_char_definition {
cfg_if! { cfg_if! {
// These are the targets on which c_char is unsigned. // These are the targets on which c_char is unsigned. Usually the
if #[cfg(any( // signedness is the same for all target_os values on a given
all( // architecture but there are some exceptions (see isSignedCharDefault()
target_os = "linux", // in clang/lib/Driver/ToolChains/Clang.cpp):
any( // - PowerPC uses unsigned char for all targets except Darwin
target_arch = "aarch64", // - Arm/AArch64 uses unsigned char except for Darwin and Windows
target_arch = "arm", // - L4RE builds with -funsigned-char on all targets
target_arch = "hexagon", if #[cfg(all(
target_arch = "powerpc", not(windows),
target_arch = "powerpc64", not(target_vendor = "apple"),
target_arch = "s390x", any(
target_arch = "riscv64", target_arch = "aarch64",
target_arch = "riscv32", target_arch = "arm",
target_arch = "csky" target_arch = "csky",
) target_arch = "hexagon",
), target_arch = "msp430",
all(target_os = "android", any(target_arch = "aarch64", target_arch = "arm")), target_arch = "powerpc",
all(target_os = "l4re", target_arch = "x86_64"), target_arch = "powerpc64",
all( target_arch = "riscv64",
any(target_os = "freebsd", target_os = "openbsd", target_os = "rtems"), target_arch = "riscv32",
any( target_arch = "s390x",
target_arch = "aarch64", target_arch = "xtensa",
target_arch = "arm", target_os = "l4re",
target_arch = "powerpc", )
target_arch = "powerpc64",
target_arch = "riscv64"
)
),
all(
target_os = "netbsd",
any(
target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc",
target_arch = "riscv64"
)
),
all(
target_os = "vxworks",
any(
target_arch = "aarch64",
target_arch = "arm",
target_arch = "powerpc64",
target_arch = "powerpc"
)
),
all(
target_os = "fuchsia",
any(target_arch = "aarch64", target_arch = "riscv64")
),
all(target_os = "nto", target_arch = "aarch64"),
target_os = "horizon",
target_os = "aix",
))] { ))] {
pub type c_char = u8; pub type c_char = u8;
} else { } else {