-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
c_char signedness doesn't match with Clang's default on various no-std and tier 3 targets #129945
Comments
This would be a great check to have in CI, probably for all the types since I'm sure at least one Edit: this should be pretty easy so I opened an issue for anyone to work on it #133058 |
On MSP430 (tier 3), both Clang and rustc don't match with the ABI's default char type... Section 2.1 "Basic Types" in MSP430 Embedded Application Binary Interface says:
However clang doesn't set $ clang -E -dM -x c /dev/null -target msp430-none-elf | grep __CHAR
#define __CHAR16_TYPE__ unsigned short
#define __CHAR32_TYPE__ unsigned int
#define __CHAR_BIT__ 8 |
Something tangentially related is that C compilers expose |
In Rust, it may be more complicated than “like C compilers”, given that |
I mistyped - I meant to say "Cargo feature" and not "target feature", as in something that would need to be used with |
See also llvm/llvm-project#115957 which I filed while investigating #132975. I'll take a look at the script posted in the initial comment and will check my patch. |
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
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
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 Closes rust-lang#131319
Rollup merge of rust-lang#132975 - arichardson:ffi-c-char, r=tgross35 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 Closes rust-lang#131319
As an next step of #122985 ("c_char on AIX should be u8"), I checked all builtin targets' c_char (as of nightly-2024-09-03) using the following script.
check_c_char.sh
The result (stdout of the script) is:
stderr of the script (version info, etc.)
Note about the above script (potential false positive / false negative)
m68k-unknown-linux-gnu
: can't compile functions with certain return types #89498) are ignored in the above script. (potential false negative)As stated in the title, there are many
target_os = "none" target
and tier3 targets that do not match.target_os = "none" target
, most of them probably do not match with Clang's default.c_char
was originally defined instd
and this mismatch was missed when it was moved tocore
.c_char
directly on these targets, but this includes a lot of tier 2 targets, so changing this to match Clang could have a not small impact on embedded ecosystem.References:
char
data type is unsigned."char
type is unsigned by default".@rustbot label +A-abi +O-Arm +O-AArch64 +O-riscv +O-csky +O-msp430 +O-xtensa +O-bare-metal +O-android +O-illumos +O-hermit
The text was updated successfully, but these errors were encountered: