fix local array allocation
authorMatthias Braun <matze@braunis.de>
Fri, 16 Nov 2007 15:47:13 +0000 (15:47 +0000)
committerMatthias Braun <matze@braunis.de>
Fri, 16 Nov 2007 15:47:13 +0000 (15:47 +0000)
[r18413]

TODO
ast2firm.c

diff --git a/TODO b/TODO
index 3d3fd70..e5a2b11 100644 (file)
--- 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
index a7aacd1..752b69d 100644 (file)
@@ -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,