This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [trunk][patch] Avoid sharing DECL_ARGUMENTS
- From: Rafael Espindola <espindola at google dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Diego Novillo <dnovillo at google dot com>
- Date: Thu, 2 Apr 2009 16:19:25 +0100
- Subject: Re: [trunk][patch] Avoid sharing DECL_ARGUMENTS
- References: <38a0d8450904020804v7f363d1fx60fede18b4c8324f@mail.gmail.com>
Now with the patch
2009/4/2 Rafael Espindola <espindola@google.com>:
> Normally a function argument points back to the function DECL via
> DECL_CONTEXT. If two FUNCTION_DECLs share DECL_ARGUMENTS, the
> DECL_CONTEXT of the arguments must be incorrect for at least one of
> the functions.
>
> This patch fixes one case where this was happening.
>
> 2009-04-02 ÂRafael Avila de Espindola Â<espindola@google.com>
>
> Â Â Â Â* c-decl.c (merge_decls): Make sure newdecl and olddecl don't
> Â Â Â Âshare the argument list.
>
> Cheers,
> --
> Rafael Avila de Espindola
>
> Google | Gordon House | Barrow Street | Dublin 4 | Ireland
> Registered in Dublin, Ireland | Registration Number: 368047
>
--
Rafael Avila de Espindola
Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 3c1c277..17d6849 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -1853,12 +1853,15 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
/* Also preserve various other info from the definition. */
if (!new_is_definition)
{
+ tree t;
DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
gimple_set_body (newdecl, gimple_body (olddecl));
- DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
+ DECL_ARGUMENTS (newdecl) = copy_list (DECL_ARGUMENTS (olddecl));
+ for (t = DECL_ARGUMENTS (newdecl); t ; t = TREE_CHAIN (t))
+ DECL_CONTEXT (t) = newdecl;
/* See if we've got a function to instantiate from. */
if (DECL_SAVED_TREE (olddecl))
@@ -1880,6 +1883,9 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
{
unsigned olddecl_uid = DECL_UID (olddecl);
tree olddecl_context = DECL_CONTEXT (olddecl);
+ tree olddecl_arguments = NULL;
+ if (TREE_CODE (olddecl) == FUNCTION_DECL)
+ olddecl_arguments = DECL_ARGUMENTS (olddecl);
memcpy ((char *) olddecl + sizeof (struct tree_common),
(char *) newdecl + sizeof (struct tree_common),
@@ -1910,6 +1916,8 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype)
}
DECL_UID (olddecl) = olddecl_uid;
DECL_CONTEXT (olddecl) = olddecl_context;
+ if (TREE_CODE (olddecl) == FUNCTION_DECL)
+ DECL_ARGUMENTS (olddecl) = olddecl_arguments;
}
/* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl