Skip to content

Commit 2598141

Browse files
committed
Mark integer constants as unsigned when lhs is unsigned
1 parent 0da9766 commit 2598141

File tree

7 files changed

+38
-27
lines changed

7 files changed

+38
-27
lines changed

jbmc/src/java_bytecode/java_utils.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ unsigned java_local_variable_slots(const typet &t)
4343
"all types constructed in java_types.cpp encode JVM types "
4444
"with these bit widths");
4545

46-
return bitwidth==64 ? 2 : 1;
46+
return bitwidth == 64 ? 2u : 1u;
4747
}
4848

4949
unsigned java_method_parameter_slots(const code_typet &t)

src/ansi-c/c_typecheck_expr.cpp

+17-10
Original file line numberDiff line numberDiff line change
@@ -2694,20 +2694,27 @@ exprt c_typecheck_baset::do_special_functions(
26942694
// clang returns 4 for _Bool, gcc treats these as 'int'.
26952695
type_number =
26962696
config.ansi_c.preprocessor == configt::ansi_ct::preprocessort::CLANG
2697-
? 4
2698-
: 1;
2697+
? 4u
2698+
: 1u;
26992699
}
27002700
else
27012701
{
27022702
type_number =
2703-
type.id() == ID_empty ? 0
2704-
: (type.id() == ID_bool || type.id() == ID_c_bool) ? 4
2705-
: (type.id() == ID_pointer || type.id() == ID_array) ? 5
2706-
: type.id() == ID_floatbv ? 8
2707-
: (type.id() == ID_complex && type.subtype().id() == ID_floatbv) ? 9
2708-
: type.id() == ID_struct ? 12
2709-
: type.id() == ID_union ? 13
2710-
: 1; // int, short, char, enum_tag
2703+
type.id() == ID_empty
2704+
? 0u
2705+
: (type.id() == ID_bool || type.id() == ID_c_bool)
2706+
? 4u
2707+
: (type.id() == ID_pointer || type.id() == ID_array)
2708+
? 5u
2709+
: type.id() == ID_floatbv
2710+
? 8u
2711+
: (type.id() == ID_complex && type.subtype().id() == ID_floatbv)
2712+
? 9u
2713+
: type.id() == ID_struct
2714+
? 12u
2715+
: type.id() == ID_union
2716+
? 13u
2717+
: 1u; // int, short, char, enum_tag
27112718
}
27122719

27132720
exprt tmp=from_integer(type_number, expr.type());

src/ansi-c/literals/unescape_string.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ std::basic_string<T> unescape_string_templ(const std::string &src)
7373
{
7474
std::string hex;
7575

76-
const unsigned digits=(ch=='u')?4:8;
76+
const unsigned digits = (ch == 'u') ? 4u : 8u;
7777
hex.reserve(digits);
7878

7979
for(unsigned count=digits;

src/goto-cc/gcc_mode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ int gcc_modet::doit()
534534

535535
config.ansi_c.Float128_type =
536536
gcc_version.flavor == gcc_versiont::flavort::GCC &&
537-
gcc_version.is_at_least(4, gcc_float128_minor_version);
537+
gcc_version.is_at_least(4u, gcc_float128_minor_version);
538538

539539
// -fshort-double makes double the same as float
540540
if(cmdline.isset("fshort-double"))

src/solvers/refinement/string_constraint_generator_testing.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ exprt string_constraint_generatort::add_axioms_for_is_prefix(
9595
const function_application_exprt::argumentst &args=f.arguments();
9696
PRECONDITION(f.type()==bool_typet() || f.type().id()==ID_c_bool);
9797
PRECONDITION(args.size() == 2 || args.size() == 3);
98-
const array_string_exprt &s0 = get_string_expr(args[swap_arguments ? 1 : 0]);
99-
const array_string_exprt &s1 = get_string_expr(args[swap_arguments ? 0 : 1]);
98+
const array_string_exprt &s0 =
99+
get_string_expr(args[swap_arguments ? 1u : 0u]);
100+
const array_string_exprt &s1 =
101+
get_string_expr(args[swap_arguments ? 0u : 1u]);
100102
const exprt offset =
101103
args.size() == 2 ? from_integer(0, s0.length().type()) : args[2];
102104
return typecast_exprt(add_axioms_for_is_prefix(s0, s1, offset), f.type());
@@ -154,8 +156,10 @@ exprt string_constraint_generatort::add_axioms_for_is_suffix(
154156

155157
symbol_exprt issuffix=fresh_boolean("issuffix");
156158
typecast_exprt tc_issuffix(issuffix, f.type());
157-
const array_string_exprt &s0 = get_string_expr(args[swap_arguments ? 1 : 0]);
158-
const array_string_exprt &s1 = get_string_expr(args[swap_arguments ? 0 : 1]);
159+
const array_string_exprt &s0 =
160+
get_string_expr(args[swap_arguments ? 1u : 0u]);
161+
const array_string_exprt &s1 =
162+
get_string_expr(args[swap_arguments ? 0u : 1u]);
159163
const typet &index_type=s0.length().type();
160164

161165
implies_exprt a1(issuffix, s1.axiom_for_length_ge(s0.length()));

src/util/simplify_expr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
503503
const typet &c_enum_type=ns.follow_tag(to_c_enum_tag_type(expr_type));
504504
if(c_enum_type.id()==ID_c_enum) // possibly incomplete
505505
{
506-
unsigned int_value=operand.is_true();
506+
unsigned int_value = operand.is_true() ? 1u : 0u;
507507
exprt tmp=from_integer(int_value, c_enum_type);
508508
tmp.type()=expr_type; // we maintain the tag type
509509
expr=tmp;

src/util/unicode.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -232,27 +232,27 @@ std::wstring utf8_to_utf16(const std::string& in, bool swap_bytes)
232232
// note: if we wanted to make sure that we capture incorrect strings,
233233
// we should check that whatever follows first character starts with
234234
// bits 10.
235-
code=(c & 0x1F) << 6;
235+
code = (c & 0x1Fu) << 6;
236236
c=in[i++];
237-
code+=c & 0x3F;
237+
code += c & 0x3Fu;
238238
}
239239
else if(c<=0xEF && i+1<in.size())
240240
{
241-
code=(c & 0xF) << 12;
241+
code = (c & 0xFu) << 12;
242242
c=in[i++];
243-
code+=(c & 0x3F) << 6;
243+
code += (c & 0x3Fu) << 6;
244244
c=in[i++];
245-
code+=c & 0x3F;
245+
code += c & 0x3Fu;
246246
}
247247
else if(c<=0xF7 && i+2<in.size())
248248
{
249-
code=(c & 0x7) << 18;
249+
code = (c & 0x7u) << 18;
250250
c=in[i++];
251-
code+=(c & 0x3F) << 12;
251+
code += (c & 0x3Fu) << 12;
252252
c=in[i++];
253-
code+=(c & 0x3F) << 6;
253+
code += (c & 0x3Fu) << 6;
254254
c=in[i++];
255-
code+=c & 0x3F;
255+
code += c & 0x3Fu;
256256
}
257257
else
258258
{

0 commit comments

Comments
 (0)