Skip to content

Commit 698360c

Browse files
committed
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>
1 parent 3d1d65b commit 698360c

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

‎expand.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,13 @@ void cast_value(struct expression *expr, struct symbol *newtype,
110110
expr->taint = old->taint;
111111
if (old_size == new_size) {
112112
expr->value = old->value;
113+
expr->ctype = newtype;
113114
return;
114115
}
115116

116117
// expand it to the full "long long" value
117118
value = get_longlong(old);
119+
expr->ctype = newtype;
118120

119121
Int:
120122
// _Bool requires a zero test rather than truncation.
@@ -153,6 +155,7 @@ void cast_value(struct expression *expr, struct symbol *newtype,
153155
value = (long long)old->fvalue;
154156
expr->type = EXPR_VALUE;
155157
expr->taint = 0;
158+
expr->ctype = newtype;
156159
goto Int;
157160
}
158161

@@ -168,6 +171,7 @@ void cast_value(struct expression *expr, struct symbol *newtype,
168171
expr->fvalue = (float)expr->fvalue;
169172
}
170173
expr->type = EXPR_FVALUE;
174+
expr->ctype = newtype;
171175
}
172176

173177
/* Return true if constant shift size is valid */

‎expression.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ struct token *primary_expression(struct token *token, struct expression **tree)
433433
if (token_type(token) < TOKEN_WIDE_CHAR) {
434434
expr->ctype = &char_ctype;
435435
cast_value(expr, &int_ctype, expr, expr->ctype);
436-
expr->ctype = &int_ctype;
437436
} else {
438437
expr->ctype = wchar_ctype;
439438
}

‎parse.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,6 @@ static void cast_enum_list(struct symbol_list *list, struct symbol *base_type)
904904
continue;
905905
}
906906
cast_value(expr, base_type, expr, ctype);
907-
expr->ctype = base_type;
908907
} END_FOR_EACH_PTR(sym);
909908
}
910909

0 commit comments

Comments
 (0)