X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ast2firm.c;h=829a4d28d86b5552e2e6ed9dac76f92644531e61;hb=6f412788b166fc65c92444c7aedbeaeeabc67f43;hp=8550148d1a23b3910f0d86fa7183516b0975364a;hpb=6d73a010bb951a4cc7cdd05a006216dd143ed5ba;p=cparser diff --git a/ast2firm.c b/ast2firm.c index 8550148..829a4d2 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -2524,6 +2524,11 @@ static ir_node *create_cast(dbg_info *dbgi, ir_node *value_node, type_t *from_type, type_t *type) { type = skip_typeref(type); + if (type == type_void) { + /* make sure firm type is constructed */ + (void) get_ir_type(type); + return NULL; + } if (!is_type_scalar(type)) { /* make sure firm type is constructed */ (void) get_ir_type(type); @@ -4052,7 +4057,7 @@ static void advance_current_object(type_path_t *path) /* we're past the last member of the current sub-aggregate, try if we * can ascend in the type hierarchy and continue with another subobject */ - size_t len = ARR_LEN(path->path); + size_t len = ARR_LEN(path->path); if (len > 1) { ascend_from_subtype(path); @@ -4244,32 +4249,68 @@ static ir_initializer_t *create_ir_initializer( panic("unknown initializer"); } -static void create_dynamic_initializer_sub(ir_initializer_t *initializer, - ir_entity *entity, ir_type *type, dbg_info *dbgi, ir_node *base_addr) +/** ANSI C §6.7.8:21: If there are fewer initializers [..] than there + * are elements [...] the remainder of the aggregate shall be initialized + * implicitly the same as objects that have static storage duration. */ +static void create_dynamic_null_initializer(ir_entity *entity, dbg_info *dbgi, + ir_node *base_addr) { - switch(get_initializer_kind(initializer)) { - case IR_INITIALIZER_NULL: { - /* ANSI C §6.7.8:21: If there are fewer initializers [..] than there - are elements [...] the remainder of the aggregate shall be initialized - implicitly the same as objects that have static storage duration. */ - ir_type *ent_type = get_entity_type(entity); - ir_mode *value_mode = get_type_mode(ent_type); - ir_node *node = new_Const_long(value_mode, 0); + /* for unions we must NOT do anything for null initializers */ + ir_type *owner = get_entity_owner(entity); + if (is_Union_type(owner)) { + return; + } - /* is it a bitfield type? */ - if (is_Primitive_type(ent_type) && - get_primitive_base_type(ent_type) != NULL) { - bitfield_store_to_firm(dbgi, entity, base_addr, node, false); - return; + ir_type *ent_type = get_entity_type(entity); + /* create sub-initializers for a compound type */ + if (is_compound_type(ent_type)) { + unsigned n_members = get_compound_n_members(ent_type); + for (unsigned n = 0; n < n_members; ++n) { + ir_entity *member = get_compound_member(ent_type, n); + ir_node *addr = new_d_simpleSel(dbgi, new_NoMem(), base_addr, + member); + create_dynamic_null_initializer(member, dbgi, addr); } + return; + } + if (is_Array_type(ent_type)) { + assert(has_array_upper_bound(ent_type, 0)); + long n = get_array_upper_bound_int(ent_type, 0); + for (long i = 0; i < n; ++i) { + ir_tarval *index_tv = new_tarval_from_long(i, mode_uint); + ir_node *cnst = new_d_Const(dbgi, index_tv); + ir_node *in[1] = { cnst }; + ir_entity *arrent = get_array_element_entity(ent_type); + ir_node *addr = new_d_Sel(dbgi, new_NoMem(), base_addr, 1, in, + arrent); + create_dynamic_null_initializer(arrent, dbgi, addr); + } + return; + } - assert(get_type_mode(type) == get_irn_mode(node)); - ir_node *mem = get_store(); - ir_node *store = new_d_Store(dbgi, mem, base_addr, node, cons_none); - ir_node *proj_m = new_Proj(store, mode_M, pn_Store_M); - set_store(proj_m); + ir_mode *value_mode = get_type_mode(ent_type); + ir_node *node = new_Const_long(value_mode, 0); + + /* is it a bitfield type? */ + if (is_Primitive_type(ent_type) && + get_primitive_base_type(ent_type) != NULL) { + bitfield_store_to_firm(dbgi, entity, base_addr, node, false); return; } + + ir_node *mem = get_store(); + ir_node *store = new_d_Store(dbgi, mem, base_addr, node, cons_none); + ir_node *proj_m = new_Proj(store, mode_M, pn_Store_M); + set_store(proj_m); +} + +static void create_dynamic_initializer_sub(ir_initializer_t *initializer, + ir_entity *entity, ir_type *type, dbg_info *dbgi, ir_node *base_addr) +{ + switch(get_initializer_kind(initializer)) { + case IR_INITIALIZER_NULL: + create_dynamic_null_initializer(entity, dbgi, base_addr); + return; case IR_INITIALIZER_CONST: { ir_node *node = get_initializer_const_value(initializer); ir_type *ent_type = get_entity_type(entity); @@ -4830,17 +4871,14 @@ static void if_statement_to_firm(if_statement_t *statement) ir_node *fallthrough_block = NULL; /* the true (blocks) */ - 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(); - if (fallthrough_block == NULL) - fallthrough_block = new_immBlock(); - add_immBlock_pred(fallthrough_block, jmp); - } + ir_node *const 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(); + if (fallthrough_block == NULL) + fallthrough_block = new_immBlock(); + add_immBlock_pred(fallthrough_block, jmp); } /* the false (blocks) */ @@ -4860,13 +4898,10 @@ static void if_statement_to_firm(if_statement_t *statement) /* create the condition */ if (cur_block != NULL) { - if (true_block == NULL || false_block == NULL) { + if (false_block == NULL) { if (fallthrough_block == NULL) fallthrough_block = new_immBlock(); - if (true_block == NULL) - true_block = fallthrough_block; - if (false_block == NULL) - false_block = fallthrough_block; + false_block = fallthrough_block; } set_cur_block(cur_block); @@ -4887,14 +4922,10 @@ static void if_statement_to_firm(if_statement_t *statement) static void while_statement_to_firm(while_statement_t *statement) { - ir_node *jmp = NULL; - if (get_cur_block() != NULL) { - jmp = new_Jmp(); - } - /* create the header block */ ir_node *header_block = new_immBlock(); - if (jmp != NULL) { + if (get_cur_block() != NULL) { + ir_node *const jmp = new_Jmp(); add_immBlock_pred(header_block, jmp); } @@ -4914,7 +4945,7 @@ static void while_statement_to_firm(while_statement_t *statement) break_label = old_break_label; if (get_cur_block() != NULL) { - jmp = new_Jmp(); + ir_node *const jmp = new_Jmp(); add_immBlock_pred(header_block, jmp); } @@ -5049,28 +5080,23 @@ static void for_statement_to_firm(for_statement_t *statement) ir_node *const false_block = new_immBlock(); /* the loop body */ - ir_node *body_block; - if (statement->body != NULL) { - ir_node *const old_continue_label = continue_label; - ir_node *const old_break_label = break_label; - continue_label = step_block; - break_label = false_block; + ir_node *const old_continue_label = continue_label; + ir_node *const old_break_label = break_label; + continue_label = step_block; + break_label = false_block; - body_block = new_immBlock(); - set_cur_block(body_block); - statement_to_firm(statement->body); + ir_node *const body_block = new_immBlock(); + set_cur_block(body_block); + statement_to_firm(statement->body); - assert(continue_label == step_block); - assert(break_label == false_block); - continue_label = old_continue_label; - break_label = old_break_label; + assert(continue_label == step_block); + assert(break_label == false_block); + continue_label = old_continue_label; + break_label = old_break_label; - if (get_cur_block() != NULL) { - jmp = new_Jmp(); - add_immBlock_pred(step_block, jmp); - } - } else { - body_block = step_block; + if (get_cur_block() != NULL) { + jmp = new_Jmp(); + add_immBlock_pred(step_block, jmp); } /* create the condition */ @@ -5811,7 +5837,7 @@ static void add_function_pointer(ir_type *segment, ir_entity *method, set_entity_ld_ident(ptr, new_id_from_chars("", 0)); set_entity_compiler_generated(ptr, 1); - set_entity_visibility(ptr, ir_visibility_local); + set_entity_visibility(ptr, ir_visibility_private); add_entity_linkage(ptr, IR_LINKAGE_CONSTANT|IR_LINKAGE_HIDDEN_USER); set_atomic_ent_value(ptr, val); }