@@ -190,15 +190,11 @@ impl ReprOptions {
190
190
/// `c_enum_min_size` along the way) and that will work just fine, it just induces casts when
191
191
/// getting/setting the discriminant.
192
192
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
+ } )
202
198
}
203
199
204
200
/// Returns `true` if this `#[repr()]` should inhabit "smart enum
@@ -288,8 +284,8 @@ pub struct TargetDataLayout {
288
284
/// Note: This isn't in LLVM's data layout string, it is `short_enum`
289
285
/// so the only valid spec for LLVM is c_int::BITS or 8
290
286
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 ,
293
289
}
294
290
295
291
impl Default for TargetDataLayout {
@@ -323,7 +319,10 @@ impl Default for TargetDataLayout {
323
319
address_space_info : vec ! [ ] ,
324
320
instruction_address_space : AddressSpace :: ZERO ,
325
321
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 ,
327
326
}
328
327
}
329
328
}
0 commit comments