Fixed name mangling of implicitly declared functions (especially on Win32)
authorMoritz Kroll <Moritz.Kroll@gmx.de>
Mon, 8 Dec 2008 20:44:13 +0000 (20:44 +0000)
committerMoritz Kroll <Moritz.Kroll@gmx.de>
Mon, 8 Dec 2008 20:44:13 +0000 (20:44 +0000)
[r24408]

mangle.c
parser.c

index b7d2bec..1eb6a16 100644 (file)
--- a/mangle.c
+++ b/mangle.c
@@ -281,7 +281,7 @@ ident *create_name_win32(entity_t *entity)
 
                switch (entity->declaration.type->function.linkage) {
                        case LINKAGE_INVALID:
-                               break;
+                               panic("linkage type of function is invalid");
 
                        case LINKAGE_C:
                                obstack_printf(o, "%s", entity->base.symbol->string);
@@ -331,7 +331,9 @@ ident *create_name_linux_elf(entity_t *entity)
 
        if (entity->kind == ENTITY_FUNCTION) {
                switch (entity->declaration.type->function.linkage) {
-                       case LINKAGE_INVALID: break;
+                       case LINKAGE_INVALID:
+                               panic("linkage type of function is invalid");
+
                        case LINKAGE_C:       break;
                        case LINKAGE_CXX:     needs_mangling = true; break;
                }
@@ -353,6 +355,9 @@ ident *create_name_linux_elf(entity_t *entity)
  */
 ident *create_name_macho(entity_t *entity)
 {
+       if (entity->kind == ENTITY_FUNCTION && entity->declaration.type->function.linkage == LINKAGE_INVALID)
+               panic("linkage type of function is invalid");
+
        obstack_printf(&obst, "_%s", entity->base.symbol->string);
        return make_id_from_obst();
 }
index 598f61c..ae84beb 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -6762,6 +6762,7 @@ static entity_t *create_implicit_function(symbol_t *symbol,
        type_t *ntype                          = allocate_type_zero(TYPE_FUNCTION);
        ntype->function.return_type            = type_int;
        ntype->function.unspecified_parameters = true;
+       ntype->function.linkage                = current_linkage;
 
        type_t *type = typehash_insert(ntype);
        if (type != ntype) {