summaryrefslogtreecommitdiff
path: root/compiler/rustc_abi
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-02-17 12:39:05 +0100
committerGitHub <noreply@github.com>2023-02-17 12:39:05 +0100
commite0aa5613d818085a6511265abfdd445802c4d0ba (patch)
tree1957ac850ffd87e654022af581ad1282037b4fc2 /compiler/rustc_abi
parentb5c8c329a7b4f6a12ae72ae41cb834989228221e (diff)
parent2edf6c878449294efee45ca5b7f5a921658ff666 (diff)
downloadrust-e0aa5613d818085a6511265abfdd445802c4d0ba.tar.gz
Rollup merge of #107592 - workingjubilee:use-16-bit-enum-on-16-bit-targets, r=WaffleLapkin
Default `repr(C)` enums to `c_int` size This is what ISO C strongly implies this is correct, and many processor-specific ABIs imply or mandate this size, so "everyone" (LLVM, gcc...) defaults to emitting enums this way. However, this is by no means guaranteed by ISO C, and the bare-metal Arm targets show it can be overridden, which rustc supports via `c-enum-min-bits` in a target.json. The override is a flag named `-fshort-enums` in clang and gcc, but introducing a CLI flag is probably unnecessary for rustc. This flag can be used by non-Arm microcontroller targets, like AVR and MSP430, but it is not enabled for them by default. Rust programmers who know the size of a target's enums can use explicit reprs, which also lets them match C23 code. This change is most relevant to 16-bit targets: AVR and MSP430. Most of rustc's targets use 32-bit ints, but ILP64 does exist. Regardless, rustc should now correctly handle enums for both very small and very large targets. Thanks to William for confirming MSP430 behavior, and to Waffle for better style and no-core `size_of` asserts. Fixes rust-lang/rust#107361 Fixes rust-lang/rust#77806
Diffstat (limited to 'compiler/rustc_abi')
-rw-r--r--compiler/rustc_abi/src/lib.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs
index c88a60c62b9..aa3a666b0b2 100644
--- a/compiler/rustc_abi/src/lib.rs
+++ b/compiler/rustc_abi/src/lib.rs
@@ -171,7 +171,9 @@ pub struct TargetDataLayout {
pub instruction_address_space: AddressSpace,
- /// Minimum size of #[repr(C)] enums (default I32 bits)
+ /// Minimum size of #[repr(C)] enums (default c_int::BITS, usually 32)
+ /// Note: This isn't in LLVM's data layout string, it is `short_enum`
+ /// so the only valid spec for LLVM is c_int::BITS or 8
pub c_enum_min_size: Integer,
}