Skip to content

Commit d03ec88

Browse files
arichardsongitbot
authored and
gitbot
committed
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 (llvm/llvm-project#115957). Fixes: rust-lang#129945
1 parent 2cb1a6e commit d03ec88

File tree

1 file changed

+24
-53
lines changed

1 file changed

+24
-53
lines changed

core/src/ffi/mod.rs

+24-53
Original file line numberDiff line numberDiff line change
@@ -91,59 +91,30 @@ pub type c_ssize_t = isize;
9191

9292
mod c_char_definition {
9393
cfg_if! {
94-
// These are the targets on which c_char is unsigned.
95-
if #[cfg(any(
96-
all(
97-
target_os = "linux",
98-
any(
99-
target_arch = "aarch64",
100-
target_arch = "arm",
101-
target_arch = "hexagon",
102-
target_arch = "powerpc",
103-
target_arch = "powerpc64",
104-
target_arch = "s390x",
105-
target_arch = "riscv64",
106-
target_arch = "riscv32",
107-
target_arch = "csky"
108-
)
109-
),
110-
all(target_os = "android", any(target_arch = "aarch64", target_arch = "arm")),
111-
all(target_os = "l4re", target_arch = "x86_64"),
112-
all(
113-
any(target_os = "freebsd", target_os = "openbsd", target_os = "rtems"),
114-
any(
115-
target_arch = "aarch64",
116-
target_arch = "arm",
117-
target_arch = "powerpc",
118-
target_arch = "powerpc64",
119-
target_arch = "riscv64"
120-
)
121-
),
122-
all(
123-
target_os = "netbsd",
124-
any(
125-
target_arch = "aarch64",
126-
target_arch = "arm",
127-
target_arch = "powerpc",
128-
target_arch = "riscv64"
129-
)
130-
),
131-
all(
132-
target_os = "vxworks",
133-
any(
134-
target_arch = "aarch64",
135-
target_arch = "arm",
136-
target_arch = "powerpc64",
137-
target_arch = "powerpc"
138-
)
139-
),
140-
all(
141-
target_os = "fuchsia",
142-
any(target_arch = "aarch64", target_arch = "riscv64")
143-
),
144-
all(target_os = "nto", target_arch = "aarch64"),
145-
target_os = "horizon",
146-
target_os = "aix",
94+
// These are the targets on which c_char is unsigned. Usually the
95+
// signedness is the same for all target_os values on a given
96+
// architecture but there are some exceptions (see isSignedCharDefault()
97+
// in clang/lib/Driver/ToolChains/Clang.cpp):
98+
// - PowerPC uses unsigned char for all targets except Darwin
99+
// - Arm/AArch64 uses unsigned char except for Darwin and Windows
100+
// - L4RE builds with -funsigned-char on all targets
101+
if #[cfg(all(
102+
not(windows),
103+
not(target_vendor = "apple"),
104+
any(
105+
target_arch = "aarch64",
106+
target_arch = "arm",
107+
target_arch = "csky",
108+
target_arch = "hexagon",
109+
target_arch = "msp430",
110+
target_arch = "powerpc",
111+
target_arch = "powerpc64",
112+
target_arch = "riscv64",
113+
target_arch = "riscv32",
114+
target_arch = "s390x",
115+
target_arch = "xtensa",
116+
target_os = "l4re",
117+
)
147118
))] {
148119
pub type c_char = u8;
149120
} else {

0 commit comments

Comments
 (0)