From: Luc Van Oostenryck <lucvoo@kernel.org>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 2/2] cast_value: remove error-prone redundant argument
Date: Tue, 31 May 2022 21:32:26 +0200 [thread overview]
Message-ID: <20220531193226.33399-3-lucvoo@kernel.org> (raw)
In-Reply-To: <20220531193226.33399-1-lucvoo@kernel.org>
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
The last two arguments of cast_value() are the old expression and
the oldtype which suggest that this oldtype can be distinct from the
type of the old expression.
But this is not the case because internally the type used to retrieve
the value of the expression is the type of the expression itself (old->ctype)
the type which is used and the two types must be the same (or at least
be equivalent).
So, remove the error-prone last argument and always us the type of the
expression itself.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
expand.c | 6 +++---
expression.c | 2 +-
expression.h | 3 +--
parse.c | 2 +-
4 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/expand.c b/expand.c
index fb11d77aecbc..f14e718187bc 100644
--- a/expand.c
+++ b/expand.c
@@ -94,9 +94,9 @@ static long long get_longlong(struct expression *expr)
return (value & andmask) | ormask;
}
-void cast_value(struct expression *expr, struct symbol *newtype,
- struct expression *old, struct symbol *oldtype)
+void cast_value(struct expression *expr, struct symbol *newtype, struct expression *old)
{
+ struct symbol *oldtype = old->ctype;
int old_size = oldtype->bit_size;
int new_size = newtype->bit_size;
long long value, mask, signmask;
@@ -876,7 +876,7 @@ static int expand_cast(struct expression *expr)
/* Simplify normal integer casts.. */
if (target->type == EXPR_VALUE || target->type == EXPR_FVALUE) {
- cast_value(expr, expr->ctype, target, target->ctype);
+ cast_value(expr, expr->ctype, target);
return 0;
}
return cost + 1;
diff --git a/expression.c b/expression.c
index bead007f9bda..727e7056e460 100644
--- a/expression.c
+++ b/expression.c
@@ -432,7 +432,7 @@ struct token *primary_expression(struct token *token, struct expression **tree)
// TODO: handle 'u8', 'u' & 'U' prefixes.
if (token_type(token) < TOKEN_WIDE_CHAR) {
expr->ctype = &char_ctype;
- cast_value(expr, &int_ctype, expr, expr->ctype);
+ cast_value(expr, &int_ctype, expr);
} else {
expr->ctype = wchar_ctype;
}
diff --git a/expression.h b/expression.h
index f733c07697c8..8bf40d32e10b 100644
--- a/expression.h
+++ b/expression.h
@@ -337,7 +337,6 @@ struct token *compound_statement(struct token *, struct statement *);
#define constant_expression(token,tree) conditional_expression(token, tree)
/* Cast folding of constant values.. */
-void cast_value(struct expression *expr, struct symbol *newtype,
- struct expression *old, struct symbol *oldtype);
+void cast_value(struct expression *expr, struct symbol *newtype, struct expression *old);
#endif
diff --git a/parse.c b/parse.c
index 0e51b3a33e53..53342c78c108 100644
--- a/parse.c
+++ b/parse.c
@@ -903,7 +903,7 @@ static void cast_enum_list(struct symbol_list *list, struct symbol *base_type)
expr->ctype = &int_ctype;
continue;
}
- cast_value(expr, base_type, expr, ctype);
+ cast_value(expr, base_type, expr);
} END_FOR_EACH_PTR(sym);
}
--
2.36.1
prev parent reply other threads:[~2022-05-31 19:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-31 19:32 [PATCH 0/3] improve cast_value() Luc Van Oostenryck
2022-05-31 19:32 ` [PATCH 1/2] cast_value: assign the new type Luc Van Oostenryck
2022-05-31 19:32 ` Luc Van Oostenryck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220531193226.33399-3-lucvoo@kernel.org \
--to=lucvoo@kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=luc.vanoostenryck@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).