aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-01-06 22:43:42 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-01-26 22:49:08 +0100
commit1cac46932aa290e4192ed178a26b0da6486d8cd3 (patch)
treea32ab9161f11cce5f7b2e031bc9fe4974cfb7ead
parent0fb77bb6e5429575f52b5e26f06db031f93de057 (diff)
downloadsparse-1cac46932aa290e4192ed178a26b0da6486d8cd3.tar.gz
cmps: make clearer we're using the operands' size
When handling compares of an {zero,sign}-extended value, the size of these extended values are used but this size is just the operands' size of the compares. Make this clearer by using a single variable 'size' for it. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/simplify.c b/simplify.c
index bf6397df..2f6f41c2 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1162,7 +1162,8 @@ static int simplify_seteq_setne(struct instruction *insn, long long value)
static int simplify_compare_constant(struct instruction *insn, long long value)
{
- unsigned long long bits = bits_mask(insn->itype->bit_size);
+ unsigned size = insn->itype->bit_size;
+ unsigned long long bits = bits_mask(size);
struct instruction *def;
pseudo_t src1, src2;
unsigned int osize;
@@ -1217,7 +1218,7 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
switch (DEF_OPCODE(def, src1)) {
case OP_SEXT: // sext(x) cmp C --> x cmp trunc(C)
osize = def->orig_type->bit_size;
- if (is_signed_constant(value, osize, def->size)) {
+ if (is_signed_constant(value, osize, size)) {
insn->itype = def->orig_type;
insn->src2 = value_pseudo(zero_extend(value, osize));
return replace_pseudo(insn, &insn->src1, def->src);
@@ -1263,13 +1264,13 @@ static int simplify_compare_constant(struct instruction *insn, long long value)
}
switch (insn->opcode) {
case OP_SET_LT: case OP_SET_LE:
- if (sign_extend(value, def->size) > (long long)bits)
+ if (sign_extend(value, size) > (long long)bits)
return replace_with_value(insn, 1);
else
return replace_with_value(insn, 0);
break;
case OP_SET_GE: case OP_SET_GT:
- if (sign_extend(value, def->size) > (long long)bits)
+ if (sign_extend(value, size) > (long long)bits)
return replace_with_value(insn, 0);
else
return replace_with_value(insn, 1);