diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2022-05-31 14:56:21 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2022-05-31 15:49:05 +0200 |
commit | 698360ca020e8ce4bc84eb44233dba9dbc9b598c (patch) | |
tree | c0cbb6e320bd29c91abf490651546f19ddda9ab9 | |
parent | 3d1d65bfe6dad089b9c2a8d69f36ba5301a9509c (diff) | |
download | sparse-698360ca020e8ce4bc84eb44233dba9dbc9b598c.tar.gz |
cast_value: assign the new type
The first two arguments of cast_value() are the new expression and the
type wanted for it. This type is then used to calculate the new value.
But the type of the expression must be assigned separately (usually
after the cast because the old and the new expression can refer to
the same object).
To avoid any possible inconsistencies, assign the new type during the
casting itself.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | expand.c | 4 | ||||
-rw-r--r-- | expression.c | 1 | ||||
-rw-r--r-- | parse.c | 1 |
3 files changed, 4 insertions, 2 deletions
@@ -110,11 +110,13 @@ void cast_value(struct expression *expr, struct symbol *newtype, expr->taint = old->taint; if (old_size == new_size) { expr->value = old->value; + expr->ctype = newtype; return; } // expand it to the full "long long" value value = get_longlong(old); + expr->ctype = newtype; Int: // _Bool requires a zero test rather than truncation. @@ -153,6 +155,7 @@ Float: value = (long long)old->fvalue; expr->type = EXPR_VALUE; expr->taint = 0; + expr->ctype = newtype; goto Int; } @@ -168,6 +171,7 @@ Float: expr->fvalue = (float)expr->fvalue; } expr->type = EXPR_FVALUE; + expr->ctype = newtype; } /* Return true if constant shift size is valid */ diff --git a/expression.c b/expression.c index efdaa367..bead007f 100644 --- a/expression.c +++ b/expression.c @@ -433,7 +433,6 @@ struct token *primary_expression(struct token *token, struct expression **tree) if (token_type(token) < TOKEN_WIDE_CHAR) { expr->ctype = &char_ctype; cast_value(expr, &int_ctype, expr, expr->ctype); - expr->ctype = &int_ctype; } else { expr->ctype = wchar_ctype; } @@ -904,7 +904,6 @@ static void cast_enum_list(struct symbol_list *list, struct symbol *base_type) continue; } cast_value(expr, base_type, expr, ctype); - expr->ctype = base_type; } END_FOR_EACH_PTR(sym); } |