Skip to content

Commit

Permalink
is_null_pointer_constant(): replace magic constant by enum
Browse files Browse the repository at this point in the history
Replace the constants 0, 1 & 2 returned by is_null_pointer_constant()
with self-describing enums.

Signed-off-by: Aurelien Aptel <aaptel@suse.com>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
  • Loading branch information
aaptel authored and lucvoo committed Jan 9, 2019
1 parent ddd82b9 commit f601a2e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions evaluate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,13 +1027,19 @@ static int modify_for_unsigned(int op)
return op;
}

enum null_constant_type {
NON_NULL,
NULL_PTR,
NULL_ZERO,
};

static inline int is_null_pointer_constant(struct expression *e)
{
if (e->ctype == &null_ctype)
return 1;
return NULL_PTR;
if (!(e->flags & CEF_ICE))
return 0;
return is_zero_constant(e) ? 2 : 0;
return NON_NULL;
return is_zero_constant(e) ? NULL_ZERO : NON_NULL;
}

static struct symbol *evaluate_compare(struct expression *expr)
Expand Down Expand Up @@ -1079,9 +1085,9 @@ static struct symbol *evaluate_compare(struct expression *expr)
if (expr->op == SPECIAL_EQUAL || expr->op == SPECIAL_NOTEQUAL) {
int is_null1 = is_null_pointer_constant(left);
int is_null2 = is_null_pointer_constant(right);
if (is_null1 == 2)
if (is_null1 == NULL_ZERO)
bad_null(left);
if (is_null2 == 2)
if (is_null2 == NULL_ZERO)
bad_null(right);
if (is_null1 && is_null2) {
int positive = expr->op == SPECIAL_EQUAL;
Expand Down Expand Up @@ -1206,14 +1212,14 @@ static struct symbol *evaluate_conditional_expression(struct expression *expr)
goto out;
}
if (is_null1 && (rclass & TYPE_PTR)) {
if (is_null1 == 2)
if (is_null1 == NULL_ZERO)
bad_null(*cond);
*cond = cast_to(*cond, rtype);
ctype = rtype;
goto out;
}
if (is_null2 && (lclass & TYPE_PTR)) {
if (is_null2 == 2)
if (is_null2 == NULL_ZERO)
bad_null(expr->cond_false);
expr->cond_false = cast_to(expr->cond_false, ltype);
ctype = ltype;
Expand Down Expand Up @@ -1421,7 +1427,7 @@ static int check_assignment_types(struct symbol *target, struct expression **rp,
// NULL pointer is always OK
int is_null = is_null_pointer_constant(*rp);
if (is_null) {
if (is_null == 2)
if (is_null == NULL_ZERO)
bad_null(*rp);
goto Cast;
}
Expand Down

0 comments on commit f601a2e

Please sign in to comment.