simple support for __attribute__((alias("symbol")))
[cparser] / ast2firm.c
index fb4e53b..8d24dd7 100644 (file)
@@ -193,9 +193,7 @@ static unsigned decide_modulo_shift(unsigned type_size)
 {
        if (architecture_modulo_shift == 0)
                return 0;
-       if (type_size < architecture_modulo_shift)
-               return architecture_modulo_shift;
-       return type_size;
+       return MAX(type_size, architecture_modulo_shift);
 }
 
 static ir_mode *init_atomic_ir_mode(atomic_type_kind_t kind)
@@ -896,6 +894,8 @@ static bool declaration_is_definition(const entity_t *entity)
        switch (entity->kind) {
        case ENTITY_VARIABLE:
                return entity->declaration.storage_class != STORAGE_CLASS_EXTERN;
+// TODO: alias provides a definition
+//                    || entity->variable.alias != NULL;
        case ENTITY_FUNCTION:
                return entity->function.body != NULL;
        case ENTITY_PARAMETER:
@@ -941,8 +941,10 @@ static void handle_decl_modifiers(ir_entity *irentity, entity_t *entity)
        if ((modifiers & DM_USED) && declaration_is_definition(entity)) {
                add_entity_linkage(irentity, IR_LINKAGE_HIDDEN_USER);
        }
-       if ((modifiers & DM_WEAK) && declaration_is_definition(entity)
-           && entity->declaration.storage_class != STORAGE_CLASS_EXTERN) {
+// TODO: i dont understand this logic
+//     if ((modifiers & DM_WEAK) && declaration_is_definition(entity)
+//         && entity->declaration.storage_class != STORAGE_CLASS_EXTERN) {
+       if (modifiers & DM_WEAK) {
                add_entity_linkage(irentity, IR_LINKAGE_WEAK);
        }
 }
@@ -4677,6 +4679,18 @@ static void create_variable_initializer(entity_t *entity)
 {
        assert(entity->kind == ENTITY_VARIABLE);
        initializer_t *initializer = entity->variable.initializer;
+       if (entity->variable.alias != NULL) {
+               const namespace_tag_t namespc = (namespace_tag_t)entity->base.namespc;
+               entity_t *a = entity->variable.alias->entity;
+               for (; a != NULL; a = a->base.symbol_next) {
+                       if ((namespace_tag_t)a->base.namespc == namespc)
+                               break;
+               }
+               assert(a != NULL && a->kind == ENTITY_VARIABLE && a->variable.v.entity != NULL);
+               set_entity_alias(entity->variable.v.entity, a->variable.v.entity);
+               /* prevent usage assumption to be made about aliased variables */
+               add_entity_linkage(a->variable.v.entity, IR_LINKAGE_HIDDEN_USER);
+       }
        if (initializer == NULL)
                return;
 
@@ -5797,6 +5811,21 @@ static void create_function(entity_t *entity)
        assert(entity->kind == ENTITY_FUNCTION);
        ir_entity *function_entity = get_function_entity(entity, current_outer_frame);
 
+       if (entity->function.alias != NULL) {
+               const namespace_tag_t namespc = (namespace_tag_t)entity->base.namespc;
+               entity_t *a = entity->function.alias->entity;
+               for (; a != NULL; a = a->base.symbol_next) {
+                       if ((namespace_tag_t)a->base.namespc == namespc)
+                               break;
+               }
+// TODO: or use entitymap
+//             ir_entity *a = entitymap_get(&entitymap, entity->function.alias);
+               assert(a != NULL && a->kind == ENTITY_VARIABLE && a->function.irentity != NULL);
+               set_entity_alias(entity->function.irentity, a->function.irentity);
+               /* prevent usage assumption to be made about aliased functions */
+               add_entity_linkage(a->function.irentity, IR_LINKAGE_HIDDEN_USER);
+       }
+
        if (entity->function.body == NULL)
                return;