Instead of converting a tarval to long and check if it is negative,
we must check the tarval itself, because the constant might be too
big for long.
long fold_constant_to_int(const expression_t *expression);
bool fold_constant_to_bool(const expression_t *expression);
+bool constant_is_negative(const expression_t *constant);
/**
* the type of a literal is usually the biggest type that can hold the value.
return get_Const_tarval(cnst);
}
+/* this function is only used in parser.c, but it relies on libfirm functionality */
+bool constant_is_negative(const expression_t *expression)
+{
+ assert(is_constant_expression(expression) == EXPR_CLASS_CONSTANT);
+ ir_tarval *tv = fold_constant_to_tarval(expression);
+ return tarval_is_negative(tv);
+}
+
long fold_constant_to_int(const expression_t *expression)
{
if (expression->kind == EXPR_INVALID)
{
switch (is_constant_expression(expr)) {
case EXPR_CLASS_ERROR: return false;
- case EXPR_CLASS_CONSTANT: return fold_constant_to_int(expr) < 0;
+ case EXPR_CLASS_CONSTANT: return constant_is_negative(expr);
default: return true;
}
}