diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-05 22:14:04 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-10-08 13:44:48 +0200 |
| commit | b6a937a18d3bb80bce3b96dcdd7753032132852e (patch) | |
| tree | d738db36c79f1a585bd595a936a2e826a552a51c | |
| parent | 24bdaac6682c36f5f7878321e8f9eb02c0993572 (diff) | |
| download | sparse-dev-b6a937a18d3bb80bce3b96dcdd7753032132852e.tar.gz | |
fix evaluation of pointer to bool conversions
The pointer to bool conversion used an indirect intermediate
conversion to an int because the pointer was compared to 0
and not to a null pointer. The final result is the same
but the intermediate conversion generated an unneeded OP_PTRTOU
instruction which made some tests to fail.
Fix this by directly comparing to a null pointer of the same
type as the type to convert.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | evaluate.c | 2 | ||||
| -rw-r--r-- | validation/linear/bool-cast-lp32.c | 1 |
2 files changed, 2 insertions, 1 deletions
@@ -2883,6 +2883,8 @@ static struct symbol *cast_to_bool(struct expression *expr) return NULL; zero = alloc_const_expression(expr->pos, 0); + if (oclass & TYPE_PTR) + zero->ctype = otype; expr->op = SPECIAL_NOTEQUAL; ctype = usual_conversions(expr->op, old, zero, oclass, TYPE_NUM, otype, zero->ctype); diff --git a/validation/linear/bool-cast-lp32.c b/validation/linear/bool-cast-lp32.c index 44a650f4..7aab31dd 100644 --- a/validation/linear/bool-cast-lp32.c +++ b/validation/linear/bool-cast-lp32.c @@ -12,7 +12,6 @@ static _Bool ffun_e(void) { return (_Bool)ffun; } /* * check-name: bool-cast-pointer * check-command: test-linearize -m32 -fdump-ir $file - * check-known-to-fail * * check-output-ignore * check-output-excludes: ptrtu\\. |
