@@ -1033,25 +1033,32 @@ typet c_typecheck_baset::enum_constant_type(
10331033 const mp_integer &min_value,
10341034 const mp_integer &max_value) const
10351035{
1036- // enum constants are at least 'int', but may be made larger.
1037- // 'Packing' has no influence.
1038- if (max_value<(mp_integer (1 )<<(config.ansi_c .int_width -1 )) &&
1039- min_value>=-(mp_integer (1 )<<(config.ansi_c .int_width -1 )))
1036+ if (config.ansi_c .mode ==configt::ansi_ct::flavourt::VISUAL_STUDIO)
1037+ {
10401038 return signed_int_type ();
1041- else if (max_value<(mp_integer (1 )<<config.ansi_c .int_width ) &&
1042- min_value>=0 )
1043- return unsigned_int_type ();
1044- else if (max_value<(mp_integer (1 )<<config.ansi_c .long_int_width ) &&
1045- min_value>=0 )
1046- return unsigned_long_int_type ();
1047- else if (max_value<(mp_integer (1 )<<config.ansi_c .long_long_int_width ) &&
1048- min_value>=0 )
1049- return unsigned_long_long_int_type ();
1050- else if (max_value<(mp_integer (1 )<<(config.ansi_c .long_int_width -1 )) &&
1051- min_value>=-(mp_integer (1 )<<(config.ansi_c .long_int_width -1 )))
1052- return signed_long_int_type ();
1039+ }
10531040 else
1054- return signed_long_long_int_type ();
1041+ {
1042+ // enum constants are at least 'int', but may be made larger.
1043+ // 'Packing' has no influence.
1044+ if (max_value<(mp_integer (1 )<<(config.ansi_c .int_width -1 )) &&
1045+ min_value>=-(mp_integer (1 )<<(config.ansi_c .int_width -1 )))
1046+ return signed_int_type ();
1047+ else if (max_value<(mp_integer (1 )<<config.ansi_c .int_width ) &&
1048+ min_value>=0 )
1049+ return unsigned_int_type ();
1050+ else if (max_value<(mp_integer (1 )<<config.ansi_c .long_int_width ) &&
1051+ min_value>=0 )
1052+ return unsigned_long_int_type ();
1053+ else if (max_value<(mp_integer (1 )<<config.ansi_c .long_long_int_width ) &&
1054+ min_value>=0 )
1055+ return unsigned_long_long_int_type ();
1056+ else if (max_value<(mp_integer (1 )<<(config.ansi_c .long_int_width -1 )) &&
1057+ min_value>=-(mp_integer (1 )<<(config.ansi_c .long_int_width -1 )))
1058+ return signed_long_int_type ();
1059+ else
1060+ return signed_long_long_int_type ();
1061+ }
10551062}
10561063
10571064/* ******************************************************************\
@@ -1071,49 +1078,56 @@ typet c_typecheck_baset::enum_underlying_type(
10711078 const mp_integer &max_value,
10721079 bool is_packed) const
10731080{
1074- if (min_value< 0 )
1081+ if (config. ansi_c . mode ==configt::ansi_ct::flavourt::VISUAL_STUDIO )
10751082 {
1076- // We'll want a signed type.
1077-
1078- if (is_packed)
1079- {
1080- // If packed, there are smaller options.
1081- if (max_value<(mp_integer (1 )<<(config.ansi_c .char_width -1 )) &&
1082- min_value>=-(mp_integer (1 )<<(config.ansi_c .char_width -1 )))
1083- return signed_char_type ();
1084- else if (max_value<(mp_integer (1 )<<(config.ansi_c .short_int_width -1 )) &&
1085- min_value>=-(mp_integer (1 )<<(config.ansi_c .short_int_width -1 )))
1086- return signed_short_int_type ();
1087- }
1088-
1089- if (max_value<(mp_integer (1 )<<(config.ansi_c .int_width -1 )) &&
1090- min_value>=-(mp_integer (1 )<<(config.ansi_c .int_width -1 )))
1091- return signed_int_type ();
1092- else if (max_value<(mp_integer (1 )<<(config.ansi_c .long_int_width -1 )) &&
1093- min_value>=-(mp_integer (1 )<<(config.ansi_c .long_int_width -1 )))
1094- return signed_long_int_type ();
1095- else
1096- return signed_long_long_int_type ();
1083+ return signed_int_type ();
10971084 }
10981085 else
10991086 {
1100- // We'll want an unsigned type.
1101-
1102- if (is_packed)
1087+ if (min_value<0 )
11031088 {
1104- // If packed, there are smaller options.
1105- if (max_value<(mp_integer (1 )<<config.ansi_c .char_width ))
1106- return unsigned_char_type ();
1107- else if (max_value<(mp_integer (1 )<<config.ansi_c .short_int_width ))
1108- return unsigned_short_int_type ();
1089+ // We'll want a signed type.
1090+
1091+ if (is_packed)
1092+ {
1093+ // If packed, there are smaller options.
1094+ if (max_value<(mp_integer (1 )<<(config.ansi_c .char_width -1 )) &&
1095+ min_value>=-(mp_integer (1 )<<(config.ansi_c .char_width -1 )))
1096+ return signed_char_type ();
1097+ else if (max_value<(mp_integer (1 )<<(config.ansi_c .short_int_width -1 )) &&
1098+ min_value>=-(mp_integer (1 )<<(config.ansi_c .short_int_width -1 )))
1099+ return signed_short_int_type ();
1100+ }
1101+
1102+ if (max_value<(mp_integer (1 )<<(config.ansi_c .int_width -1 )) &&
1103+ min_value>=-(mp_integer (1 )<<(config.ansi_c .int_width -1 )))
1104+ return signed_int_type ();
1105+ else if (max_value<(mp_integer (1 )<<(config.ansi_c .long_int_width -1 )) &&
1106+ min_value>=-(mp_integer (1 )<<(config.ansi_c .long_int_width -1 )))
1107+ return signed_long_int_type ();
1108+ else
1109+ return signed_long_long_int_type ();
11091110 }
1110-
1111- if (max_value<(mp_integer (1 )<<config.ansi_c .int_width ))
1112- return unsigned_int_type ();
1113- else if (max_value<(mp_integer (1 )<<config.ansi_c .long_int_width ))
1114- return unsigned_long_int_type ();
11151111 else
1116- return unsigned_long_long_int_type ();
1112+ {
1113+ // We'll want an unsigned type.
1114+
1115+ if (is_packed)
1116+ {
1117+ // If packed, there are smaller options.
1118+ if (max_value<(mp_integer (1 )<<config.ansi_c .char_width ))
1119+ return unsigned_char_type ();
1120+ else if (max_value<(mp_integer (1 )<<config.ansi_c .short_int_width ))
1121+ return unsigned_short_int_type ();
1122+ }
1123+
1124+ if (max_value<(mp_integer (1 )<<config.ansi_c .int_width ))
1125+ return unsigned_int_type ();
1126+ else if (max_value<(mp_integer (1 )<<config.ansi_c .long_int_width ))
1127+ return unsigned_long_int_type ();
1128+ else
1129+ return unsigned_long_long_int_type ();
1130+ }
11171131 }
11181132}
11191133
0 commit comments