Skip to content

Mark integer constants as unsigned when lhs is unsigned #2539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2018
Merged
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
2 changes: 1 addition & 1 deletion jbmc/src/java_bytecode/java_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ unsigned java_local_variable_slots(const typet &t)
"all types constructed in java_types.cpp encode JVM types "
"with these bit widths");

return bitwidth==64 ? 2 : 1;
return bitwidth == 64 ? 2u : 1u;
}

unsigned java_method_parameter_slots(const code_typet &t)
Expand Down
27 changes: 17 additions & 10 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2694,20 +2694,27 @@ exprt c_typecheck_baset::do_special_functions(
// clang returns 4 for _Bool, gcc treats these as 'int'.
type_number =
config.ansi_c.preprocessor == configt::ansi_ct::preprocessort::CLANG
? 4
: 1;
? 4u
: 1u;
}
else
{
type_number =
type.id() == ID_empty ? 0
: (type.id() == ID_bool || type.id() == ID_c_bool) ? 4
: (type.id() == ID_pointer || type.id() == ID_array) ? 5
: type.id() == ID_floatbv ? 8
: (type.id() == ID_complex && type.subtype().id() == ID_floatbv) ? 9
: type.id() == ID_struct ? 12
: type.id() == ID_union ? 13
: 1; // int, short, char, enum_tag
type.id() == ID_empty
? 0u
: (type.id() == ID_bool || type.id() == ID_c_bool)
? 4u
: (type.id() == ID_pointer || type.id() == ID_array)
? 5u
: type.id() == ID_floatbv
? 8u
: (type.id() == ID_complex && type.subtype().id() == ID_floatbv)
? 9u
: type.id() == ID_struct
? 12u
: type.id() == ID_union
? 13u
: 1u; // int, short, char, enum_tag
}

exprt tmp=from_integer(type_number, expr.type());
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/literals/unescape_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ std::basic_string<T> unescape_string_templ(const std::string &src)
{
std::string hex;

const unsigned digits=(ch=='u')?4:8;
const unsigned digits = (ch == 'u') ? 4u : 8u;
hex.reserve(digits);

for(unsigned count=digits;
Expand Down
2 changes: 1 addition & 1 deletion src/goto-cc/gcc_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ int gcc_modet::doit()

config.ansi_c.Float128_type =
gcc_version.flavor == gcc_versiont::flavort::GCC &&
gcc_version.is_at_least(4, gcc_float128_minor_version);
gcc_version.is_at_least(4u, gcc_float128_minor_version);

// -fshort-double makes double the same as float
if(cmdline.isset("fshort-double"))
Expand Down
12 changes: 8 additions & 4 deletions src/solvers/refinement/string_constraint_generator_testing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ exprt string_constraint_generatort::add_axioms_for_is_prefix(
const function_application_exprt::argumentst &args=f.arguments();
PRECONDITION(f.type()==bool_typet() || f.type().id()==ID_c_bool);
PRECONDITION(args.size() == 2 || args.size() == 3);
const array_string_exprt &s0 = get_string_expr(args[swap_arguments ? 1 : 0]);
const array_string_exprt &s1 = get_string_expr(args[swap_arguments ? 0 : 1]);
const array_string_exprt &s0 =
get_string_expr(args[swap_arguments ? 1u : 0u]);
const array_string_exprt &s1 =
get_string_expr(args[swap_arguments ? 0u : 1u]);
const exprt offset =
args.size() == 2 ? from_integer(0, s0.length().type()) : args[2];
return typecast_exprt(add_axioms_for_is_prefix(s0, s1, offset), f.type());
Expand Down Expand Up @@ -154,8 +156,10 @@ exprt string_constraint_generatort::add_axioms_for_is_suffix(

symbol_exprt issuffix=fresh_boolean("issuffix");
typecast_exprt tc_issuffix(issuffix, f.type());
const array_string_exprt &s0 = get_string_expr(args[swap_arguments ? 1 : 0]);
const array_string_exprt &s1 = get_string_expr(args[swap_arguments ? 0 : 1]);
const array_string_exprt &s0 =
get_string_expr(args[swap_arguments ? 1u : 0u]);
const array_string_exprt &s1 =
get_string_expr(args[swap_arguments ? 0u : 1u]);
const typet &index_type=s0.length().type();

implies_exprt a1(issuffix, s1.axiom_for_length_ge(s0.length()));
Expand Down
2 changes: 1 addition & 1 deletion src/util/simplify_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
const typet &c_enum_type=ns.follow_tag(to_c_enum_tag_type(expr_type));
if(c_enum_type.id()==ID_c_enum) // possibly incomplete
{
unsigned int_value=operand.is_true();
unsigned int_value = operand.is_true() ? 1u : 0u;
exprt tmp=from_integer(int_value, c_enum_type);
tmp.type()=expr_type; // we maintain the tag type
expr=tmp;
Expand Down
18 changes: 9 additions & 9 deletions src/util/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,27 +232,27 @@ std::wstring utf8_to_utf16(const std::string& in, bool swap_bytes)
// note: if we wanted to make sure that we capture incorrect strings,
// we should check that whatever follows first character starts with
// bits 10.
code=(c & 0x1F) << 6;
code = (c & 0x1Fu) << 6;
c=in[i++];
code+=c & 0x3F;
code += c & 0x3Fu;
}
else if(c<=0xEF && i+1<in.size())
{
code=(c & 0xF) << 12;
code = (c & 0xFu) << 12;
c=in[i++];
code+=(c & 0x3F) << 6;
code += (c & 0x3Fu) << 6;
c=in[i++];
code+=c & 0x3F;
code += c & 0x3Fu;
}
else if(c<=0xF7 && i+2<in.size())
{
code=(c & 0x7) << 18;
code = (c & 0x7u) << 18;
c=in[i++];
code+=(c & 0x3F) << 12;
code += (c & 0x3Fu) << 12;
c=in[i++];
code+=(c & 0x3F) << 6;
code += (c & 0x3Fu) << 6;
c=in[i++];
code+=c & 0x3F;
code += c & 0x3Fu;
}
else
{
Expand Down