- dbg_info *const dbgi = get_dbg_info(&declaration->source_position);
- ir_entity *const entity = new_d_entity(global_type, id, ir_type_method, dbgi);
- set_entity_ld_ident(entity, id);
- if(declaration->storage_class == STORAGE_CLASS_STATIC
- || declaration->is_inline) {
- set_entity_visibility(entity, visibility_local);
- } else if(declaration->init.statement != NULL) {
- set_entity_visibility(entity, visibility_external_visible);
+ return true;
+}
+
+/**
+ * Creates an entity representing a function.
+ *
+ * @param declaration the function declaration
+ */
+static ir_entity *get_function_entity(entity_t *entity)
+{
+ assert(entity->kind == ENTITY_FUNCTION);
+ if (entity->function.entity != NULL) {
+ return entity->function.entity;
+ }
+
+ if (is_main(entity)) {
+ /* force main to C linkage */
+ type_t *type = entity->declaration.type;
+ assert(is_type_function(type));
+ if (type->function.linkage != LINKAGE_C) {
+ type_t *new_type = duplicate_type(type);
+ new_type->function.linkage = LINKAGE_C;
+ type = identify_new_type(new_type);
+ entity->declaration.type = type;
+ }
+ }
+
+ symbol_t *symbol = entity->base.symbol;
+ ident *id = new_id_from_str(symbol->string);
+
+ ir_type *global_type = get_glob_type();
+ ir_type *ir_type_method = get_ir_type(entity->declaration.type);
+ bool const has_body = entity->function.statement != NULL;
+
+ /* already an entity defined? */
+ ir_entity *irentity = entitymap_get(&entitymap, symbol);
+ if (irentity != NULL) {
+ if (get_entity_visibility(irentity) == visibility_external_allocated
+ && has_body) {
+ set_entity_visibility(irentity, visibility_external_visible);
+ }
+ goto entity_created;
+ }
+
+ dbg_info *const dbgi = get_dbg_info(&entity->base.source_position);
+ irentity = new_d_entity(global_type, id, ir_type_method, dbgi);
+ set_entity_ld_ident(irentity, create_ld_ident(entity));
+
+ handle_gnu_attributes_ent(irentity, entity);
+
+ /* static inline => local
+ * extern inline => local
+ * inline without definition => local
+ * inline with definition => external_visible */
+ storage_class_tag_t const storage_class
+ = (storage_class_tag_t) entity->declaration.storage_class;
+ bool const is_inline = entity->function.is_inline;
+ if (is_inline && storage_class == STORAGE_CLASS_NONE && has_body) {
+ set_entity_visibility(irentity, visibility_external_visible);
+ } else if (storage_class == STORAGE_CLASS_STATIC ||
+ (is_inline && has_body)) {
+ if (!has_body) {
+ /* this entity was declared, but is defined nowhere */
+ set_entity_peculiarity(irentity, peculiarity_description);
+ }
+ set_entity_visibility(irentity, visibility_local);
+ } else if (has_body) {
+ set_entity_visibility(irentity, visibility_external_visible);