aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Schmid <Thomas.Schmid@br-automation.com>2009-02-06 12:51:34 +0000
committerChristopher Li <sparse@chrisli.org>2009-07-17 23:06:22 +0000
commit801c6d64cae47d0c7ffc55c53a0f3c599bc0dcaf (patch)
tree71b3020dd5aafcc6c66898923d70bd56f0dd5ea7
parentfun with declarations and definitions (diff)
downloadsparse-801c6d64cae47d0c7ffc55c53a0f3c599bc0dcaf.tar.gz
sparse-801c6d64cae47d0c7ffc55c53a0f3c599bc0dcaf.tar.bz2
sparse-801c6d64cae47d0c7ffc55c53a0f3c599bc0dcaf.zip
Fix implicit cast to float
Was:Re: Initializing float variables without type suffix) > cast_to() seems fine. > > In expanding stage, cast_value() did not cast the constant > correctly. You're right, I also noticed this in the meantime. The decision, whether newtype is int_type or fp_type is not made correctly. The following patch seems to work: Fix implicit cast to float Patch modified by Chris. Signed-Off-By: Thomas Schmid <Thomas.Schmid@br-automation.com> Signed-Off-By: Christopher Li <sparse@chrisli.org>
-rw-r--r--evaluate.c31
-rw-r--r--expand.c6
-rw-r--r--symbol.h32
3 files changed, 35 insertions, 34 deletions
diff --git a/evaluate.c b/evaluate.c
index 358842b..5c3812e 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -313,37 +313,6 @@ static struct expression * cast_to(struct expression *old, struct symbol *type)
return expr;
}
-static int is_type_type(struct symbol *type)
-{
- return (type->ctype.modifiers & MOD_TYPE) != 0;
-}
-
-int is_ptr_type(struct symbol *type)
-{
- if (type->type == SYM_NODE)
- type = type->ctype.base_type;
- return type->type == SYM_PTR || type->type == SYM_ARRAY || type->type == SYM_FN;
-}
-
-static inline int is_float_type(struct symbol *type)
-{
- if (type->type == SYM_NODE)
- type = type->ctype.base_type;
- return type->ctype.base_type == &fp_type;
-}
-
-static inline int is_byte_type(struct symbol *type)
-{
- return type->bit_size == bits_in_char && type->type != SYM_BITFIELD;
-}
-
-static inline int is_void_type(struct symbol *type)
-{
- if (type->type == SYM_NODE)
- type = type->ctype.base_type;
- return type == &void_ctype;
-}
-
enum {
TYPE_NUM = 1,
TYPE_BITFIELD = 2,
diff --git a/expand.c b/expand.c
index 3e962d1..82fd62a 100644
--- a/expand.c
+++ b/expand.c
@@ -116,17 +116,17 @@ Int:
return;
Float:
- if (newtype->ctype.base_type != &fp_type) {
+ if (!is_float_type(newtype)) {
value = (long long)old->fvalue;
expr->type = EXPR_VALUE;
expr->taint = 0;
goto Int;
}
- if (oldtype->ctype.base_type != &fp_type)
+ if (!is_float_type(oldtype))
expr->fvalue = (long double)get_longlong(old);
else
- expr->fvalue = old->value;
+ expr->fvalue = old->fvalue;
if (!(newtype->ctype.modifiers & MOD_LONGLONG)) {
if ((newtype->ctype.modifiers & MOD_LONG))
diff --git a/symbol.h b/symbol.h
index f69a0f2..a747128 100644
--- a/symbol.h
+++ b/symbol.h
@@ -10,6 +10,7 @@
*/
#include "token.h"
+#include "target.h"
/*
* An identifier with semantic meaning is a "symbol".
@@ -297,6 +298,37 @@ static inline int is_enum_type(const struct symbol *type)
return (type->type == SYM_ENUM);
}
+static inline int is_type_type(struct symbol *type)
+{
+ return (type->ctype.modifiers & MOD_TYPE) != 0;
+}
+
+static inline int is_ptr_type(struct symbol *type)
+{
+ if (type->type == SYM_NODE)
+ type = type->ctype.base_type;
+ return type->type == SYM_PTR || type->type == SYM_ARRAY || type->type == SYM_FN;
+}
+
+static inline int is_float_type(struct symbol *type)
+{
+ if (type->type == SYM_NODE)
+ type = type->ctype.base_type;
+ return type->ctype.base_type == &fp_type;
+}
+
+static inline int is_byte_type(struct symbol *type)
+{
+ return type->bit_size == bits_in_char && type->type != SYM_BITFIELD;
+}
+
+static inline int is_void_type(struct symbol *type)
+{
+ if (type->type == SYM_NODE)
+ type = type->ctype.base_type;
+ return type == &void_ctype;
+}
+
static inline int get_sym_type(struct symbol *type)
{
if (type->type == SYM_NODE)