From: Matthias Braun Date: Fri, 16 Nov 2007 15:47:13 +0000 (+0000) Subject: fix local array allocation X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=3580543da5d0edaa567dd18db6b8c8d69ad6abc4;p=cparser fix local array allocation [r18413] --- diff --git a/TODO b/TODO index 3d3fd70..e5a2b11 100644 --- a/TODO +++ b/TODO @@ -16,3 +16,11 @@ Parser: ast2firm: - output source file positions for panics... - correctly handle pointer ++, -- + + +Coole Warnungen: + + int x = 5; + x = bla(): + + -> dead assignment diff --git a/ast2firm.c b/ast2firm.c index a7aacd1..752b69d 100644 --- a/ast2firm.c +++ b/ast2firm.c @@ -642,7 +642,19 @@ static ir_node *reference_expression_to_firm(const reference_expression_t *ref) return load_from_expression_addr(type, symconst, dbgi); } } - case DECLARATION_TYPE_LOCAL_VARIABLE_ENTITY: + case DECLARATION_TYPE_LOCAL_VARIABLE_ENTITY: { + ir_entity *entity = declaration->v.entity; + ir_node *frame = get_irg_frame(current_ir_graph); + ir_node *store = get_store(); + ir_node *sel = new_d_simpleSel(dbgi, store, frame, entity); + + if(type->type == TYPE_ARRAY) { + return sel; + } else { + return load_from_expression_addr(type, sel, dbgi); + } + } + case DECLARATION_TYPE_COMPOUND_MEMBER: case DECLARATION_TYPE_LABEL_BLOCK: panic("not implemented reference type"); @@ -1633,10 +1645,16 @@ static void create_initializer(declaration_t *declaration) static void create_local_variable(declaration_t *declaration) { - bool needs_entity = declaration->address_taken; - assert(declaration->declaration_type == DECLARATION_TYPE_UNKNOWN); + bool needs_entity = declaration->address_taken; + type_t *type = declaration->type; + if(type->type == TYPE_ARRAY + || type->type == TYPE_COMPOUND_STRUCT + || type->type == TYPE_COMPOUND_UNION) { + needs_entity = true; + } + if(needs_entity) { ir_type *frame_type = get_irg_frame_type(current_ir_graph); create_declaration_entity(declaration,