Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions c2rust-transpile/src/c_ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2173,7 +2173,9 @@ impl CastKind {

(CTypeKind::Function(..), CTypeKind::Pointer(..)) => CastKind::FunctionToPointerDecay,

(_, CTypeKind::Pointer(..)) if source_ty_kind.is_enum_or_integral_type() => {
(_, CTypeKind::Pointer(..))
if source_ty_kind.is_enum_or_integral_type() || source_ty_kind.is_bool() =>
{
CastKind::IntegralToPointer
}

Expand Down Expand Up @@ -3224,7 +3226,7 @@ impl CTypeKind {
use CTypeKind::*;
matches!(
self,
Bool | UChar
UChar
| UInt
| UShort
| ULong
Expand Down Expand Up @@ -3272,7 +3274,11 @@ impl CTypeKind {
}

pub fn is_scalar(&self) -> bool {
self.is_integral_type() || self.is_floating_type() || self.is_enum() || self.is_pointer()
self.is_bool()
|| self.is_integral_type()
|| self.is_floating_type()
|| self.is_enum()
|| self.is_pointer()
}

pub fn as_underlying_decl(&self) -> Option<CDeclId> {
Expand All @@ -3297,7 +3303,7 @@ impl CTypeKind {

/// Choose the smaller, simpler of the two types if they are cast-compatible.
pub fn smaller_compatible_type(ty1: CTypeKind, ty2: CTypeKind) -> Option<CTypeKind> {
let int = Self::is_integral_type;
let int = |ty: &Self| ty.is_integral_type() || ty.is_bool();
let float = Self::is_floating_type;

use CTypeKind::*;
Expand Down
2 changes: 1 addition & 1 deletion c2rust-transpile/src/translator/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'c> Translation<'c> {
let ty_kind = &self.ast_context.resolve_type(ty.ctype).kind;
match *lit {
CLiteral::Integer(value, _) | CLiteral::Character(value)
if ty_kind.is_integral_type() && !ty_kind.is_bool() =>
if ty_kind.is_integral_type() =>
{
ty_kind.guaranteed_integer_in_range(value)
&& (!is_negated || ty_kind.is_signed_integral_type())
Expand Down
1 change: 1 addition & 0 deletions c2rust-transpile/src/translator/pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ impl<'c> Translation<'c> {
}
}

/// Makes a cast from an integer, enum or boolean type to a pointer.
pub fn convert_integral_to_pointer_cast(
&self,
ctx: ExprContext,
Expand Down
Loading