From: Christoph Mallon Date: Mon, 15 Sep 2008 07:56:36 +0000 (+0000) Subject: Fix warn_div_by_zero(): The result of the division might be int and the divisor non... X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=9db031bc0264ac7cb20df07d86a285f15873ba3b;p=cparser Fix warn_div_by_zero(): The result of the division might be int and the divisor non-int for /=. [r21956] --- diff --git a/ast2firm.c b/ast2firm.c index 670c483..09ec8e7 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -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; diff --git a/parser.c b/parser.c index e824a7c..a4a016a 100644 --- 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"); } }