This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: vector garbaged collected while still in use
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Xinliang David Li <davidxl at google dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 7 Nov 2011 10:56:20 +0100
- Subject: Re: vector garbaged collected while still in use
- References: <CAAkRFZ+BxS0WrUa37cGSN1SBzSfa3w8c-MdxzyVrWZCL0Ct0tw@mail.gmail.com>
On Mon, Nov 7, 2011 at 8:53 AM, Xinliang David Li <davidxl@google.com> wrote:
> I have seen compiler build error (segmentation fault) in libstdc++-v3.
> It turns out that a vector allocated in gc memory is GCed before the
> vector is released. The gc call is from a call to synethesize_method
> from cp_finish_decl.
>
> The following patch fixes the problem. Compiler bootstraps and tested
> on linux/x86-64. Ok for trunk (or better fix suggested)?
The context looks different on trunk. Do you have a backtrace on where
we ggc collect from a frame starting at cp_finish_decl?
> thanks,
>
> David
>
> 2011-11-05 ?Xinliang David Li ?<davidxl@google.com>
>
> ? ? ? ?* cp/decl.c (cp_finish_decl): Prevent cleanups from
> ? ? ? ?being garbage collected before being released.
>
>
> Index: cp/decl.c
> ===================================================================
> --- cp/decl.c ? (revision 181013)
> +++ cp/decl.c ? (working copy)
> @@ -5902,6 +5902,8 @@ value_dependent_init_p (tree init)
> ? ?FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
> ? ?if the (init) syntax was used. ?*/
>
> +static GTY (()) VEC(tree,gc) *cleanups_vec;
> +
> ?void
> ?cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
> ? ? ? ? ? ? ? ?tree asmspec_tree, int flags)
> @@ -5914,6 +5916,7 @@ cp_finish_decl (tree decl, tree init, bo
> ? bool var_definition_p = false;
> ? tree auto_node;
>
> + ?cleanups_vec = cleanups;
> ? if (decl == error_mark_node)
> ? ? return;
> ? else if (! decl)
> @@ -6319,6 +6322,7 @@ cp_finish_decl (tree decl, tree init, bo
> ? FOR_EACH_VEC_ELT (tree, cleanups, i, t)
> ? ? push_cleanup (decl, t, false);
> ? release_tree_vector (cleanups);
> + ?cleanups_vec = NULL;
>
> ? if (was_readonly)
> ? ? TREE_READONLY (decl) = 1;
>