ada/8358: Ada accesses freed memory

Graham Stott graham.stott@btinternet.com
Fri Oct 25 12:06:00 GMT 2002


The following reply was made to PR ada/8358; it has been noted by GNATS.

From: Graham Stott <graham.stott@btinternet.com>
To: aj@suse.de
Cc: gcc-gnats@gcc.gnu.org,  gcc-patches@gcc.gnu.org
Subject: Re: ada/8358: Ada accesses freed memory
Date: Fri, 25 Oct 2002 19:59:05 +0100

 Andreas,
 
 Here's a patch which I have bootstraped i686-linux-gnu-pc with
 all checking enabled.
 
 This patch introduces a new GC root which is used to prevent
 the pending eleaborations from being GC collected while they
 are being enumerated by build_unit_elab.
 
 Ok for mainline?
 
 Graham
 
 ada/ChangeLog
 
         * trans.c (gnu_pending_elaboration_lists): New GC root.
         (build_unit_elab): Use..
 
 --------------------------------------------------------------------------
 Index: trans.c
 ===================================================================
 RCS file: /cvs/gcc/gcc/gcc/ada/trans.c,v
 retrieving revision 1.21
 diff -c -p -r1.21 trans.c
 *** trans.c     23 Oct 2002 07:33:34 -0000      1.21
 --- trans.c     25 Oct 2002 18:52:50 -0000
 *************** tree gnu_block_stack;
 *** 88,93 ****
 --- 88,97 ----
       handler.  Not used in the zero-cost case.  */
    static GTY(()) tree gnu_except_ptr_stack;
 
 + /* List of TREE_LIST nodes containing pending elaborations lists.
 +    used to prevent the elaborations being reclaimed by GC.  */
 + static GTY(()) tree gnu_pending_elaboration_lists;
 +
    /* Map GNAT tree codes to GCC tree codes for simple expressions.  */
    static enum tree_code gnu_codes[Number_Node_Kinds];
 
 *************** build_unit_elab (gnat_unit, body_p, gnu_
 *** 5298,5303 ****
 --- 5302,5311 ----
      if (gnu_elab_list == 0)
        return 1;
 
 +   /* Prevent the elaboration list from being reclaimed by the GC.  */
 +   gnu_pending_elaboration_lists = chainon (gnu_pending_elaboration_lists,
 +                                          gnu_elab_list);
 +
      /* Set our file and line number to that of the object and set up the
         elaboration routine.  */
      gnu_decl = create_subprog_decl (create_concat_name (gnat_unit,
 *************** build_unit_elab (gnat_unit, body_p, gnu_
 *** 5357,5362 ****
 --- 5365,5373 ----
      poplevel (kept_level_p (), 1, 0);
      gnu_block_stack = TREE_CHAIN (gnu_block_stack);
      end_subprog_body ();
 +
 +   /* We are finished with the elaboration list it can now be discarded.  */
 +   gnu_pending_elaboration_lists = TREE_CHAIN (gnu_pending_elaboration_lists);
 
      /* If there were no insns, we don't need an elab routine.  It would
         be nice to not output this one, but there's no good way to do that.  */
 ------------------------------------------------------------------------------
 



More information about the Gcc-prs mailing list