public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [lto] handle function types without argument types
@ 2007-12-06 22:04 Nathan Froyd
  2007-12-06 22:24 ` Joseph S. Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Froyd @ 2007-12-06 22:04 UTC (permalink / raw)
  To: gcc-patches; +Cc: joseph

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
type regardless.

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.

-Nathan

2007-12-06  Nathan Froyd  <froydnj@codesourcery.com>

	* lto-symtab.c (lto_symtab_merge_decl): Handle FUNCTION_DECLs without
	argument type information.

Index: lto-symtab.c
===================================================================
--- 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);
+	  else
+	    merged_type = TREE_TYPE (new_decl);
+	}
+
       if (!merged_type)
 	{
 	  error ("type of %qD does not match original declaration",

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [lto] handle function types without argument types
  2007-12-06 22:04 [lto] handle function types without argument types Nathan Froyd
@ 2007-12-06 22:24 ` Joseph S. Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2007-12-06 22:24 UTC (permalink / raw)
  To: Nathan Froyd; +Cc: gcc-patches

On Thu, 6 Dec 2007, Nathan Froyd wrote:

> 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)?

In C terms, argument types from an old-style declaration (in 
DECL_ARGUMENTS, not TYPE_ARG_TYPES) are not part of the function type.  I 
don't know enough about DWARF to judge if including them in the type in 
debug info nevertheless, but not marking that declaration with 
DW_AT_prototyped, would be incorrect or cause problems with DWARF 
consumers.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-12-06 22:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-06 22:04 [lto] handle function types without argument types Nathan Froyd
2007-12-06 22:24 ` Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).