Skip to content

Commit

Permalink
Cleanup wchar_t layout computation to happen later. (rust-lang#1596)
Browse files Browse the repository at this point in the history
This is a breaking cheange since WChar is exposed, but should be no behavior
change otherwise.
  • Loading branch information
emilio authored and LoganBarnett committed Dec 2, 2023
1 parent 89e769a commit e570a4c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/codegen/mod.rs
Expand Up @@ -3060,8 +3060,9 @@ impl TryToRustTy for Type {
IntKind::ULong => Ok(raw_type(ctx, "c_ulong")),
IntKind::LongLong => Ok(raw_type(ctx, "c_longlong")),
IntKind::ULongLong => Ok(raw_type(ctx, "c_ulonglong")),
IntKind::WChar { size } => {
let ty = Layout::known_type_for_size(ctx, size)
IntKind::WChar => {
let layout = self.layout(ctx).expect("Couldn't compute wchar_t's layout?");
let ty = Layout::known_type_for_size(ctx, layout.size)
.expect("Non-representable wchar_t?");
let ident = ctx.rust_ident_raw(ty);
Ok(quote! { #ident })
Expand Down
6 changes: 1 addition & 5 deletions src/ir/context.rs
Expand Up @@ -2011,11 +2011,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
CXType_UChar => TypeKind::Int(IntKind::UChar),
CXType_Short => TypeKind::Int(IntKind::Short),
CXType_UShort => TypeKind::Int(IntKind::UShort),
CXType_WChar => {
TypeKind::Int(IntKind::WChar {
size: ty.fallible_size(self).expect("Couldn't compute size of wchar_t?"),
})
},
CXType_WChar => TypeKind::Int(IntKind::WChar),
CXType_Char16 => TypeKind::Int(IntKind::U16),
CXType_Char32 => TypeKind::Int(IntKind::U32),
CXType_Long => TypeKind::Int(IntKind::Long),
Expand Down
7 changes: 2 additions & 5 deletions src/ir/int.rs
Expand Up @@ -13,10 +13,7 @@ pub enum IntKind {
UChar,

/// An `wchar_t`.
WChar {
/// The size of the wchar_t in bytes, which will be 2 or 4.
size: usize,
},
WChar,

/// A platform-dependent `char` type, with the signedness support.
Char {
Expand Down Expand Up @@ -97,7 +94,7 @@ impl IntKind {
// to know whether it is or not right now (unlike char, there's no
// WChar_S / WChar_U).
Bool | UChar | UShort | UInt | ULong | ULongLong | U8 | U16 |
WChar { .. } | U32 | U64 | U128 => false,
WChar | U32 | U64 | U128 => false,

SChar | Short | Int | Long | LongLong | I8 | I16 | I32 | I64 |
I128 => true,
Expand Down

0 comments on commit e570a4c

Please sign in to comment.