Fix warn_div_by_zero(): The result of the division might be int and the divisor non...
authorChristoph Mallon <christoph.mallon@gmx.de>
Mon, 15 Sep 2008 07:56:36 +0000 (07:56 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Mon, 15 Sep 2008 07:56:36 +0000 (07:56 +0000)
[r21956]

ast2firm.c
parser.c

index 670c483..09ec8e7 100644 (file)
@@ -807,7 +807,9 @@ static ir_type *get_ir_type(type_t *type)
        ir_type *firm_type = NULL;
        switch (type->kind) {
        case TYPE_ERROR:
-               panic("error type occurred");
+               /* Happens while constant folding, when there was an error */
+               return create_atomic_type(&type_void->atomic);
+
        case TYPE_ATOMIC:
                firm_type = create_atomic_type(&type->atomic);
                break;
index e824a7c..a4a016a 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -7684,10 +7684,15 @@ static void semantic_binexpr_arithmetic(binary_expression_t *expression)
 
 static void warn_div_by_zero(binary_expression_t const *const expression)
 {
-       if (warning.div_by_zero                       &&
-           is_type_integer(expression->base.type)    &&
-           is_constant_expression(expression->right) &&
-           fold_constant(expression->right) == 0) {
+       if (!warning.div_by_zero ||
+           !is_type_integer(expression->base.type))
+               return;
+
+       expression_t const *const right = expression->right;
+       /* The type of the right operand can be different for /= */
+       if (is_type_integer(right->base.type) &&
+           is_constant_expression(right)     &&
+           fold_constant(right) == 0) {
                warningf(&expression->base.source_position, "division by zero");
        }
 }