[lno & tree-ssa] PATCH: Fix memory corruption

Devang Patel dpatel@apple.com
Thu Mar 18 19:35:00 GMT 2004


This patch fixes another memory corruption because memory is allocated
using n_basic_blocks count and accessed using bb->index.  Basic block
index can be higher than n_basic_blocks count when basic blocks are 
removed.

2003-03-18  Devang Patel  <dpatel@apple.com>

         * tree-ssa-live.c (new_tree_live_info): Set num_blocks to
         last_basic_block instead of n_basic_blocks.
         (calculate_live_on_entry): Use last_basic_block instead of
         n_basic_blocks.
         (calculate_live_on_exit): Same.

Bootstrapped on powerpc-darwin.

OK for tree-ssa also ?

--
Devang


Index: tree-ssa-live.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-live.c,v
retrieving revision 1.1.2.33.2.3
diff -Idpatel.pbxuser -c -3 -p -r1.1.2.33.2.3 tree-ssa-live.c
*** tree-ssa-live.c     4 Mar 2004 11:57:05 -0000       1.1.2.33.2.3
--- tree-ssa-live.c     18 Mar 2004 19:21:15 -0000
*************** new_tree_live_info (var_map map)
*** 450,456 ****

     live = (tree_live_info_p) xmalloc (sizeof (struct 
tree_live_info_d));
     live->map = map;
!   live->num_blocks = n_basic_blocks;

     live->global = BITMAP_XMALLOC ();

--- 450,456 ----

     live = (tree_live_info_p) xmalloc (sizeof (struct 
tree_live_info_d));
     live->map = map;
!   live->num_blocks = last_basic_block;

     live->global = BITMAP_XMALLOC ();

*************** calculate_live_on_entry (var_map map)
*** 662,668 ****
         }
       }

!   VARRAY_INT_INIT (stack, n_basic_blocks, "stack");
     EXECUTE_IF_SET_IN_BITMAP (live->global, 0, i,
       {
         live_worklist (live, stack, i);
--- 662,668 ----
         }
       }

!   VARRAY_INT_INIT (stack, last_basic_block, "stack");
     EXECUTE_IF_SET_IN_BITMAP (live->global, 0, i,
       {
         live_worklist (live, stack, i);
*************** calculate_live_on_exit (tree_live_info_p
*** 771,778 ****
     bitmap on_entry;
     var_map map = liveinfo->map;

!   on_exit = (bitmap *)xmalloc (n_basic_blocks * sizeof (bitmap));
!   for (x = 0; x < n_basic_blocks; x++)
       on_exit[x] = BITMAP_XMALLOC ();

     /* Set all the live-on-exit bits for uses in PHIs.  */
--- 771,778 ----
     bitmap on_entry;
     var_map map = liveinfo->map;

!   on_exit = (bitmap *)xmalloc (last_basic_block * sizeof (bitmap));
!   for (x = 0; x < last_basic_block; x++)
       on_exit[x] = BITMAP_XMALLOC ();

     /* Set all the live-on-exit bits for uses in PHIs.  */



More information about the Gcc-patches mailing list