aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/expand.c
diff options
Diffstat (limited to 'expand.c')
-rw-r--r--expand.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/expand.c b/expand.c
index c4f806de..f14e7181 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;
@@ -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 */
@@ -872,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;