@@ -190,15 +190,11 @@ impl ReprOptions {
190190 /// `c_enum_min_size` along the way) and that will work just fine, it just induces casts when
191191 /// getting/setting the discriminant.
192192 pub fn discr_type ( & self , cx : & impl HasDataLayout ) -> IntegerType {
193- self . int . unwrap_or (
194- if self . c ( )
195- && let Some ( max_size) = cx. data_layout ( ) . c_enum_max_size
196- {
197- IntegerType :: Fixed ( max_size, true )
198- } else {
199- IntegerType :: Pointer ( true )
200- } ,
201- )
193+ self . int . unwrap_or ( if self . c ( ) {
194+ IntegerType :: Fixed ( cx. data_layout ( ) . c_enum_max_size , true )
195+ } else {
196+ IntegerType :: Pointer ( true )
197+ } )
202198 }
203199
204200 /// Returns `true` if this `#[repr()]` should inhabit "smart enum
@@ -288,8 +284,8 @@ pub struct TargetDataLayout {
288284 /// Note: This isn't in LLVM's data layout string, it is `short_enum`
289285 /// so the only valid spec for LLVM is c_int::BITS or 8
290286 pub c_enum_min_size : Integer ,
291- /// Maximum size of #[repr(C)] enums (defaults to pointer size ).
292- pub c_enum_max_size : Option < Integer > ,
287+ /// Maximum size of #[repr(C)] enums (defaults to c_longlong::BITS, which is always 64 ).
288+ pub c_enum_max_size : Integer ,
293289}
294290
295291impl Default for TargetDataLayout {
@@ -323,7 +319,10 @@ impl Default for TargetDataLayout {
323319 address_space_info : vec ! [ ] ,
324320 instruction_address_space : AddressSpace :: ZERO ,
325321 c_enum_min_size : Integer :: I32 ,
326- c_enum_max_size : None ,
322+ // C23 allows enums to have any integer type. The largest integer type in the standard
323+ // is `long long`, which is always 64bits (judging from our own definition in
324+ // `library/core/src/ffi/primitives.rs`).
325+ c_enum_max_size : Integer :: I64 ,
327326 }
328327 }
329328}
0 commit comments