@@ -1033,25 +1033,32 @@ typet c_typecheck_baset::enum_constant_type(
1033
1033
const mp_integer &min_value,
1034
1034
const mp_integer &max_value) const
1035
1035
{
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
+ {
1040
1038
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
+ }
1053
1040
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
+ }
1055
1062
}
1056
1063
1057
1064
/* ******************************************************************\
@@ -1071,49 +1078,56 @@ typet c_typecheck_baset::enum_underlying_type(
1071
1078
const mp_integer &max_value,
1072
1079
bool is_packed) const
1073
1080
{
1074
- if (min_value< 0 )
1081
+ if (config. ansi_c . mode ==configt::ansi_ct::flavourt::VISUAL_STUDIO )
1075
1082
{
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 ();
1097
1084
}
1098
1085
else
1099
1086
{
1100
- // We'll want an unsigned type.
1101
-
1102
- if (is_packed)
1087
+ if (min_value<0 )
1103
1088
{
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 ();
1109
1110
}
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 ();
1115
1111
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
+ }
1117
1131
}
1118
1132
}
1119
1133
0 commit comments