From: Christoph Mallon Date: Mon, 10 Dec 2012 07:05:00 +0000 (+0100) Subject: semantic: Add missing skip_typeref() to avoid adding unnecessary implicit casts. X-Git-Url: http://nsz.repo.hu/git/?p=cparser;a=commitdiff_plain;h=f50ecba9cfa8caf75729d49f4f350a7e44f2b3d9 semantic: Add missing skip_typeref() to avoid adding unnecessary implicit casts. In particular this avoids insertion of non-scalar nop casts. Therefore some tests, which later skip them, are removed, too. --- diff --git a/ast2firm.c b/ast2firm.c index b092381..f651b43 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -2231,11 +2231,6 @@ static ir_node *create_cast(dbg_info *dbgi, ir_node *value_node, (void) get_ir_type(type); return NULL; } - if (!is_type_scalar(type)) { - /* make sure firm type is constructed */ - (void) get_ir_type(type); - return value_node; - } from_type = skip_typeref(from_type); ir_mode *mode = get_ir_mode_storage(type); @@ -4079,10 +4074,6 @@ static void create_variable_initializer(entity_t *entity) type_t *const init_type = skip_typeref(value->base.type); if (!is_type_scalar(init_type)) { - /* skip convs */ - while (value->kind == EXPR_UNARY_CAST) - value = value->unary.value; - if (value->kind != EXPR_COMPOUND_LITERAL) panic("expected non-scalar initializer to be a compound literal"); initializer = value->compound_literal.initializer; diff --git a/parser.c b/parser.c index af4b6a8..fe3e55f 100644 --- a/parser.c +++ b/parser.c @@ -897,9 +897,8 @@ static bool is_null_pointer_constant(const expression_t *expression) static expression_t *create_implicit_cast(expression_t *expression, type_t *dest_type) { - type_t *const source_type = expression->base.type; - - if (source_type == dest_type) + type_t *const source_type = skip_typeref(expression->base.type); + if (source_type == skip_typeref(dest_type)) return expression; expression_t *cast = allocate_expression_zero(EXPR_UNARY_CAST); @@ -7821,7 +7820,7 @@ static void warn_div_by_zero(binary_expression_t const *const expression) expression_t const *const right = expression->right; /* The type of the right operand can be different for /= */ - if (is_type_integer(right->base.type) && + if (is_type_integer(skip_typeref(right->base.type)) && is_constant_expression(right) == EXPR_CLASS_CONSTANT && !fold_constant_to_bool(right)) { position_t const *const pos = &expression->base.pos; @@ -8874,7 +8873,7 @@ static statement_t *parse_case_statement(void) type_t *type = expression_type; if (current_switch != NULL) { type_t *switch_type = current_switch->expression->base.type; - if (is_type_valid(switch_type)) { + if (is_type_valid(skip_typeref(switch_type))) { expression = create_implicit_cast(expression, switch_type); } }