Handle forcing the LINKAGE_C for main() in the parser, not ast2firm.
authorChristoph Mallon <christoph.mallon@gmx.de>
Sun, 6 May 2012 09:45:50 +0000 (11:45 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sun, 6 May 2012 09:45:50 +0000 (11:45 +0200)
ast2firm.c
parser.c

index 741954a..264b023 100644 (file)
@@ -941,18 +941,6 @@ static ir_entity *get_function_entity(entity_t *entity, ir_type *owner_type)
                return NULL;
        }
 
-       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);
 
index 6aa18f1..e50693b 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5397,8 +5397,19 @@ static void parse_external_declaration(void)
                        }
                }
 
-               if (is_main(entity) && enable_main_collect2_hack)
-                       prepare_main_collect2(entity);
+               if (is_main(entity)) {
+                       /* Force main to C linkage. */
+                       type_t *const 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;
+                               entity->declaration.type   = identify_new_type(new_type);
+                       }
+
+                       if (enable_main_collect2_hack)
+                               prepare_main_collect2(entity);
+               }
 
                POP_CURRENT_ENTITY();
                POP_PARENT();