Fix C/folderror
authorAndreas Zwinkau <zwinkau@kit.edu>
Thu, 11 Aug 2011 09:18:45 +0000 (11:18 +0200)
committerAndreas Zwinkau <zwinkau@kit.edu>
Thu, 11 Aug 2011 09:20:14 +0000 (11:20 +0200)
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.

ast.h
ast2firm.c
parser.c

diff --git a/ast.h b/ast.h
index 9223ca2..cd00cdc 100644 (file)
--- a/ast.h
+++ b/ast.h
@@ -138,6 +138,7 @@ expression_classification_t is_linker_constant(const expression_t *expression);
 
 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.
index a6658fc..9dd2a57 100644 (file)
@@ -3099,6 +3099,14 @@ static ir_tarval *fold_constant_to_tarval(const expression_t *expression)
        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)
index 68e36c3..e8997b4 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -8208,7 +8208,7 @@ static bool maybe_negative(expression_t const *const expr)
 {
        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;
        }
 }