Using the pre or post increment or decrement operator on floating-point values mix the addition of a floating-point value with an *integral* constant 1 or -1. Fix this by checking if we're dealing with fp or not and using the proper fp constants (1.0 or -1.0) if it is the case. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- linearize.c | 18 ++++++++++++++++-- validation/inc-dec-float.c | 13 +++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 validation/inc-dec-float.c diff --git a/linearize.c b/linearize.c index 209bd2bf3..ed649a86a 100644 --- a/linearize.c +++ b/linearize.c @@ -991,6 +991,18 @@ static pseudo_t add_setval(struct entrypoint *ep, struct symbol *ctype, struct e return target; } +static pseudo_t add_setfval(struct entrypoint *ep, struct symbol *ctype, long double fval) +{ + struct instruction *insn = alloc_typed_instruction(OP_SETVAL, ctype); + struct expression *expr = alloc_expression(insn->pos, EXPR_FVALUE); + pseudo_t target = alloc_pseudo(insn); + insn->target = target; + insn->val = expr; + expr->fvalue = fval; + add_one_insn(ep, insn); + return target; +} + static pseudo_t add_symbol_address(struct entrypoint *ep, struct symbol *sym) { struct instruction *insn = alloc_instruction(OP_SYMADDR, bits_in_pointer); @@ -1028,7 +1040,6 @@ static pseudo_t linearize_access(struct entrypoint *ep, struct expression *expr) return value; } -/* FIXME: FP */ static pseudo_t linearize_inc_dec(struct entrypoint *ep, struct expression *expr, int postop) { struct access_data ad = { NULL, }; @@ -1039,7 +1050,10 @@ static pseudo_t linearize_inc_dec(struct entrypoint *ep, struct expression *expr return VOID; old = linearize_load_gen(ep, &ad); - one = value_pseudo(expr->op_value); + if (is_float_type(expr->ctype)) + one = add_setfval(ep, expr->ctype, expr->op_value); + else + one = value_pseudo(expr->op_value); new = add_binary_op(ep, expr->ctype, op, old, one); linearize_store_gen(ep, new, &ad); finish_address_gen(ep, &ad); diff --git a/validation/inc-dec-float.c b/validation/inc-dec-float.c new file mode 100644 index 000000000..3cac8f3ee --- /dev/null +++ b/validation/inc-dec-float.c @@ -0,0 +1,13 @@ +double fincpre(double a) { ++a; return a; } +double fdecpre(double a) { --a; return a; } +double fincpost(double a) { a++; return a; } +double fdecpost(double a) { a--; return a; } + +/* + * check-name: float inc & dec + * check-command: test-linearize -Wno-decl $file + * check-output-ignore + * + * check-output-excludes: \\$1$ + * check-output-excludes: \\$-1$ + */ -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html