Merge pull request #2539 from tautschnig/vs-unsigned-constant

Mark integer constants as unsigned when lhs is unsigned
This commit is contained in:
Daniel Kroening 2018-07-07 17:29:14 +01:00 committed by GitHub
commit 41863e775e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 27 deletions

View File

@ -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)

View File

@ -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());

View File

@ -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;

View File

@ -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"))

View File

@ -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());
@ -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()));

View File

@ -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;

View File

@ -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
{