This is the mail archive of the
mailing list for the GCC project.
[lto] handle function types without argument types
- From: Nathan Froyd <froydnj at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: joseph at codesourcery dot com
- Date: Thu, 6 Dec 2007 14:04:00 -0800
- Subject: [lto] handle function types without argument types
The problem this patch solves is that when one uses old-style argument
lists in C function declarations, we don't get any argument type
information in the dwarf. But if the programmer is confused enough to
use both prototypes and old-style argument lists, then when attempting
to merge FUNCTION_DECLs from a use of said function (occurring first and
having a proper type due to the prototype) and a declaration of said
function (occurring later and having an incomplete type), then we
complain that the types are not equal.
The easy fix is to detect this case and simply use the more complete
Joseph, do you know if there's an easy may to ensure that full argument
type information makes it from the C front-end all the way to DWARF? Or
are there problems with doing that (presumably the current approach has
some reason for being the way it is)?
Committed to the LTO branch.
2007-12-06 Nathan Froyd <firstname.lastname@example.org>
* lto-symtab.c (lto_symtab_merge_decl): Handle FUNCTION_DECLs without
argument type information.
--- lto-symtab.c (revision 130658)
+++ lto-symtab.c (working copy)
@@ -308,6 +308,28 @@ lto_symtab_merge_decl (tree new_decl)
lto_same_type_p (candidate, TREE_TYPE (new_decl)) ? candidate : NULL_TREE;
+ if (!merged_type
+ && TREE_CODE (new_decl) == FUNCTION_DECL
+ && lto_same_type_p (TREE_TYPE (TREE_TYPE (old_decl)),
+ TREE_TYPE (TREE_TYPE (new_decl)))
+ /* We want either of the types to have argument types,
+ but not both. */
+ && ((TYPE_ARG_TYPES (TREE_TYPE (old_decl)) != NULL)
+ ^ (TYPE_ARG_TYPES (TREE_TYPE (new_decl)) != NULL)))
+ /* The situation here is that (in C) somebody was smart enough
+ to use proper declarations in a header file, but the actual
+ definition of the function uses non-ANSI-style argument
+ lists. One of the decls will then have a complete function
+ type, whereas the other will only have a result type.
+ Assume that the more complete type is the right one and
+ don't complain. */
+ if (TYPE_ARG_TYPES (TREE_TYPE (old_decl)))
+ merged_type = TREE_TYPE (old_decl);
+ merged_type = TREE_TYPE (new_decl);
error ("type of %qD does not match original declaration",