@@ -452,51 +452,54 @@ let is_longlong ik =
452452 corresponding to the type of the operand with signed integer type.
453453 *)
454454
455- let get_integer_promotion (ty1 : typ ) (ty2 : typ ) =
456- let promote ik =
455+ let get_integer_promotion (ty1 : typ ) (ty2 : typ ): typ =
456+ let promote_ikind ( ik : ikind ): ikind =
457457 match ik with
458458 | IChar | ISChar | IUChar | IShort | IBool -> IInt
459459 | IUShort -> IUInt
460460 | _ -> ik in
461- let ik = match (ty1, ty2) with
462- | (TInt (ik1 , _ ), TInt (ik2 , _ )) ->
463- let ik1 = promote ik1 in
464- let ik2 = promote ik2 in
465- if ik1 = ik2 then
466- ik1
467- else
468- begin
469- match (ik1, ik2) with
470- | (IInt , ILong ) | (ILong, IInt) -> ILong
471- | (IInt , ILongLong ) | (ILongLong, IInt) -> ILongLong
472- | (ILong , ILongLong ) | (ILongLong, ILong) -> ILongLong
473- | (IUInt , IULong ) | (IULong, IUInt) -> IULong
474- | (_ , IULongLong ) | (IULongLong, _ ) -> IULongLong
475- | (IInt , IUInt ) | (IUInt, IInt) -> IUInt
476- | (ILong , IULong ) | (IULong, ILong) -> IULong
477- | (IInt , IULong ) | (IULong, IInt) -> IULong
478- | (ILong , IUInt ) | (IUInt, ILong) -> ILong
479- | (ILongLong , IUInt ) | (IUInt, ILongLong) -> ILongLong
480- | (IUInt128 , _ ) | (_ , IUInt128) -> IUInt128
481- | (IInt128 , _ ) | (_ , IInt128) -> IInt128
482- | _ ->
483- raise
484- (CCHFailure
485- (LBLOCK [
486- STR " Missing case in integer promotion: " ;
487- STR (int_type_to_string ik1);
488- STR " and " ;
489- STR (int_type_to_string ik2)]))
490- end
461+ let promote_type (ty : typ ): ikind =
462+ match ty with
463+ | TInt (ik , _ ) -> promote_ikind ik
464+ | TEnum (ename , _ ) ->
465+ let einfo = CCHFileEnvironment. file_environment#get_enum ename in
466+ promote_ikind einfo.ekind
491467 | _ ->
492468 raise
493469 (CCHFailure
494470 (LBLOCK [
495471 STR " Unexpected types for integer promotion: " ;
496- typ_to_pretty ty1;
472+ typ_to_pretty ty1])) in
473+ let usual_arithmetic_conversion (ik1 : ikind ) (ik2 : ikind ): ikind =
474+ match (ik1, ik2) with
475+ | (IInt , ILong ) | (ILong, IInt) -> ILong
476+ | (IInt , ILongLong ) | (ILongLong, IInt) -> ILongLong
477+ | (ILong , ILongLong ) | (ILongLong, ILong) -> ILongLong
478+ | (IUInt , IULong ) | (IULong, IUInt) -> IULong
479+ | (_ , IULongLong ) | (IULongLong, _ ) -> IULongLong
480+ | (IInt , IUInt ) | (IUInt, IInt) -> IUInt
481+ | (ILong , IULong ) | (IULong, ILong) -> IULong
482+ | (IInt , IULong ) | (IULong, IInt) -> IULong
483+ | (ILong , IUInt ) | (IUInt, ILong) -> ILong
484+ | (ILongLong , IUInt ) | (IUInt, ILongLong) -> ILongLong
485+ | (IUInt128 , _ ) | (_ , IUInt128) -> IUInt128
486+ | (IInt128 , _ ) | (_ , IInt128) -> IInt128
487+ | _ ->
488+ raise
489+ (CCHFailure
490+ (LBLOCK [
491+ STR " Missing case in integer promotion: " ;
492+ STR (int_type_to_string ik1);
497493 STR " and " ;
498- typ_to_pretty ty2])) in
499- TInt (ik, [] )
494+ STR (int_type_to_string ik2)])) in
495+ let ik1 = promote_type ty1 in
496+ let ik2 = promote_type ty2 in
497+ let result_ik =
498+ if ik1 = ik2 then
499+ ik1
500+ else
501+ usual_arithmetic_conversion ik1 ik2 in
502+ TInt (result_ik, [] )
500503
501504
502505let rec get_field_offset offset =
0 commit comments