semantic: Add missing skip_typeref() to avoid adding unnecessary implicit casts.
[cparser] / ast2firm.c
index 74367c6..f651b43 100644 (file)
@@ -2044,12 +2044,6 @@ static ir_node *set_value_for_expression_addr(const expression_t *expression,
        return value;
 }
 
-static void set_value_for_expression(const expression_t *expression,
-                                     ir_node *value)
-{
-       set_value_for_expression_addr(expression, value, NULL);
-}
-
 static ir_node *get_value_from_lvalue(const expression_t *expression,
                                       ir_node *addr)
 {
@@ -2108,8 +2102,8 @@ static ir_node *create_incdec(unary_expression_t const *const expr, bool const i
                ? new_d_Add(dbgi, value, offset, mode)
                : new_d_Sub(dbgi, value, offset, mode);
 
-       set_value_for_expression_addr(value_expr, new_value, addr);
-       return pre ? new_value : value;
+       ir_node *const store_value = set_value_for_expression_addr(value_expr, new_value, addr);
+       return pre ? store_value : value;
 }
 
 static bool is_local_variable(expression_t *expression)
@@ -2237,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);
@@ -2860,21 +2849,16 @@ ir_tarval *fold_constant_to_tarval(const expression_t *expression)
        init_ir_types();
 
        PUSH_IRG(get_const_code_irg());
-       ir_node *const cnst = _expression_to_firm(expression);
+       ir_node *const cnst = expression_to_firm(expression);
        POP_IRG();
 
        set_optimize(old_optimize);
        set_opt_constant_folding(old_constant_folding);
-
-       if (!is_Const(cnst)) {
-               panic("couldn't fold constant");
-       }
-
        constant_folding = constant_folding_old;
 
-       ir_tarval *const tv   = get_Const_tarval(cnst);
-       ir_mode   *const mode = get_ir_mode_arithmetic(skip_typeref(expression->base.type));
-       return tarval_convert_to(tv, mode);
+       if (!is_Const(cnst))
+               panic("couldn't fold constant");
+       return get_Const_tarval(cnst);
 }
 
 /* this function is only used in parser.c, but it relies on libfirm functionality */
@@ -2902,19 +2886,6 @@ bool fold_constant_to_bool(const expression_t *expression)
 
 static ir_node *conditional_to_firm(const conditional_expression_t *expression)
 {
-       /* first try to fold a constant condition */
-       if (is_constant_expression(expression->condition) == EXPR_CLASS_CONSTANT) {
-               bool val = fold_constant_to_bool(expression->condition);
-               if (val) {
-                       expression_t *true_expression = expression->true_expression;
-                       if (true_expression == NULL)
-                               true_expression = expression->condition;
-                       return expression_to_firm(true_expression);
-               } else {
-                       return expression_to_firm(expression->false_expression);
-               }
-       }
-
        jump_target true_target;
        jump_target false_target;
        init_jump_target(&true_target,  NULL);
@@ -3154,7 +3125,7 @@ static ir_node *va_start_expression_to_firm(
        ir_node  *const no_mem  = new_NoMem();
        ir_node  *const arg_sel = new_d_simpleSel(dbgi, no_mem, frame, param_ent);
 
-       set_value_for_expression(expr->ap, arg_sel);
+       set_value_for_expression_addr(expr->ap, arg_sel, NULL);
 
        return NULL;
 }
@@ -3187,7 +3158,7 @@ static ir_node *va_arg_expression_to_firm(const va_arg_expression_t *const expr)
 static ir_node *va_copy_expression_to_firm(const va_copy_expression_t *const expr)
 {
        ir_node *const src = expression_to_firm(expr->src);
-       set_value_for_expression(expr->dst, src);
+       set_value_for_expression_addr(expr->dst, src, NULL);
        return NULL;
 }
 
@@ -3205,8 +3176,6 @@ static ir_node *expression_to_addr(const expression_t *expression)
        switch(expression->kind) {
        case EXPR_ARRAY_ACCESS:
                return array_access_addr(&expression->array_access);
-       case EXPR_CALL:
-               return call_expression_to_firm(&expression->call);
        case EXPR_COMPOUND_LITERAL:
                return compound_literal_addr(&expression->compound_literal);
        case EXPR_REFERENCE:
@@ -3372,10 +3341,6 @@ static ir_node *expression_to_firm(const expression_t *expression)
                return res;
        }
 
-       if (is_constant_expression(expression) == EXPR_CLASS_CONSTANT) {
-               return new_Const(fold_constant_to_tarval(expression));
-       }
-
        /* we have to produce a 0/1 from the mode_b expression */
        dbg_info *dbgi = get_dbg_info(&expression->base.pos);
        ir_mode  *mode = get_ir_mode_arithmetic(expression->base.type);
@@ -4109,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;