X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ast2firm.c;h=c30463cc7690e3654355d9ef37cd362efabd01f0;hb=ed1ed2b5fb813fd8de24b2eaa6fffce033246a8c;hp=21d29494af16d7bc3bbee0d3f4f971660b450f41;hpb=728c7d0d3f96b2a0aa74eeabd4537ba61b1d42c4;p=cparser diff --git a/ast2firm.c b/ast2firm.c index 21d2949..c30463c 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -279,17 +279,22 @@ static unsigned get_type_size_const(type_t *type) panic("Trying to determine size of invalid type"); } +static ir_node *get_vla_size(array_type_t *const type) +{ + ir_node *size_node = type->size_node; + if (size_node == NULL) { + size_node = expression_to_firm(type->size_expression); + type->size_node = size_node; + } + return size_node; +} + static ir_node *get_type_size(type_t *type) { type = skip_typeref(type); if (is_type_array(type) && type->array.is_vla) { - ir_node *size_node = type->array.size_node; - if (size_node == NULL) { - size_node = expression_to_firm(type->array.size_expression); - type->array.size_node = size_node; - } - + ir_node *size_node = get_vla_size(&type->array); ir_node *elem_size = get_type_size(type->array.element_type); ir_mode *mode = get_irn_mode(size_node); ir_node *real_size = new_d_Mul(NULL, size_node, elem_size, mode); @@ -2220,10 +2225,12 @@ static ir_node *produce_condition_result(const expression_t *expression, ir_node *cur_block = get_cur_block(); ir_node *one_block = new_immBlock(); + set_cur_block(one_block); ir_node *one = new_Const(get_mode_one(mode)); ir_node *jmp_one = new_d_Jmp(dbgi); ir_node *zero_block = new_immBlock(); + set_cur_block(zero_block); ir_node *zero = new_Const(get_mode_null(mode)); ir_node *jmp_zero = new_d_Jmp(dbgi); @@ -2724,6 +2731,7 @@ static ir_node *conditional_to_firm(const conditional_expression_t *expression) /* create the true block */ ir_node *true_block = new_immBlock(); + set_cur_block(true_block); ir_node *true_val = expression->true_expression != NULL ? expression_to_firm(expression->true_expression) : NULL; @@ -2731,6 +2739,7 @@ static ir_node *conditional_to_firm(const conditional_expression_t *expression) /* create the false block */ ir_node *false_block = new_immBlock(); + set_cur_block(false_block); ir_node *false_val = expression_to_firm(expression->false_expression); ir_node *false_jmp = new_Jmp(); @@ -3052,9 +3061,7 @@ static ir_node *get_label_block(label_t *label) ir_graph *rem = current_ir_graph; current_ir_graph = current_function; - ir_node *old_cur_block = get_cur_block(); - ir_node *block = new_immBlock(); - set_cur_block(old_cur_block); + ir_node *block = new_immBlock(); label->block = block; @@ -3264,9 +3271,7 @@ static ir_node *create_condition_evaluation(const expression_t *expression, case EXPR_BINARY_LOGICAL_AND: { const binary_expression_t *binary_expression = &expression->binary; - ir_node *cur_block = get_cur_block(); ir_node *extra_block = new_immBlock(); - set_cur_block(cur_block); create_condition_evaluation(binary_expression->left, extra_block, false_block); mature_immBlock(extra_block); @@ -3278,9 +3283,7 @@ static ir_node *create_condition_evaluation(const expression_t *expression, case EXPR_BINARY_LOGICAL_OR: { const binary_expression_t *binary_expression = &expression->binary; - ir_node *cur_block = get_cur_block(); ir_node *extra_block = new_immBlock(); - set_cur_block(cur_block); create_condition_evaluation(binary_expression->left, true_block, extra_block); mature_immBlock(extra_block); @@ -4322,8 +4325,13 @@ static void declaration_statement_to_firm(declaration_statement_t *statement) entity_t *const last = statement->declarations_end; if (entity != NULL) { for ( ;; entity = entity->base.next) { - if (is_declaration(entity)) + if (is_declaration(entity)) { initialize_local_declaration(entity); + } else if (entity->kind == ENTITY_TYPEDEF) { + type_t *const type = entity->typedefe.type; + if (is_type_array(type) && type->array.is_vla) + get_vla_size(&type->array); + } if (entity == last) break; } @@ -4340,6 +4348,7 @@ static void if_statement_to_firm(if_statement_t *statement) ir_node *true_block = NULL; if (statement->true_statement != NULL) { true_block = new_immBlock(); + set_cur_block(true_block); statement_to_firm(statement->true_statement); if (get_cur_block() != NULL) { ir_node *jmp = new_Jmp(); @@ -4353,6 +4362,7 @@ static void if_statement_to_firm(if_statement_t *statement) ir_node *false_block = NULL; if (statement->false_statement != NULL) { false_block = new_immBlock(); + set_cur_block(false_block); statement_to_firm(statement->false_statement); if (get_cur_block() != NULL) { @@ -4410,6 +4420,7 @@ static void while_statement_to_firm(while_statement_t *statement) break_label = NULL; ir_node *body_block = new_immBlock(); + set_cur_block(body_block); statement_to_firm(statement->body); ir_node *false_block = break_label; @@ -4474,6 +4485,7 @@ static void do_while_statement_to_firm(do_while_statement_t *statement) continue_label = header_block; break_label = NULL; + set_cur_block(body_block); statement_to_firm(statement->body); ir_node *false_block = break_label; @@ -4534,6 +4546,7 @@ static void for_statement_to_firm(for_statement_t *statement) /* create the step block */ ir_node *const step_block = new_immBlock(); + set_cur_block(step_block); if (statement->step != NULL) { expression_to_firm(statement->step); } @@ -4541,6 +4554,7 @@ static void for_statement_to_firm(for_statement_t *statement) /* create the header block */ ir_node *const header_block = new_immBlock(); + set_cur_block(header_block); if (jmp != NULL) { add_immBlock_pred(header_block, jmp); } @@ -4558,6 +4572,7 @@ static void for_statement_to_firm(for_statement_t *statement) break_label = false_block; body_block = new_immBlock(); + set_cur_block(body_block); statement_to_firm(statement->body); assert(continue_label == step_block); @@ -4610,9 +4625,7 @@ static void create_jump_statement(const statement_t *statement, static ir_node *get_break_label(void) { if (break_label == NULL) { - ir_node *cur_block = get_cur_block(); break_label = new_immBlock(); - set_cur_block(cur_block); } return break_label; } @@ -4726,10 +4739,9 @@ static void case_label_to_firm(const case_label_statement_t *statement) ir_node *const fallthrough = (get_cur_block() == NULL ? NULL : new_Jmp()); ir_node *proj; - ir_node *old_block = get_nodes_block(current_switch_cond); ir_node *block = new_immBlock(); - set_cur_block(old_block); + set_cur_block(get_nodes_block(current_switch_cond)); if (statement->expression != NULL) { long pn = statement->first_case; long end_pn = statement->last_case; @@ -5103,10 +5115,6 @@ static void statement_to_firm(statement_t *statement) case STATEMENT_LABEL: label_to_firm(&statement->label); return; - case STATEMENT_LOCAL_LABEL: - /* local labels transform the semantics of labels while parsing - * they don't need any special treatment here */ - return; case STATEMENT_GOTO: goto_to_firm(&statement->gotos); return; @@ -5244,6 +5252,10 @@ static void initialize_function_parameters(entity_t *entity) */ static void handle_decl_modifier_irg(ir_graph_ptr irg, decl_modifiers_t decl_modifiers) { + if (decl_modifiers & DM_RETURNS_TWICE) { + /* TRUE if the declaration includes __attribute__((returns_twice)) */ + set_irg_additional_property(irg, mtp_property_returns_twice); + } if (decl_modifiers & DM_NORETURN) { /* TRUE if the declaration includes the Microsoft __declspec(noreturn) specifier. */