diff mbox

Fix miscompilation with -fprofile-use (PR gcov-profile/50127)

Message ID 20120106163614.GR18937@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Jan. 6, 2012, 4:36 p.m. UTC
Hi!

When tree-prof/bb-reorg.c is compiled with 32-bit host cc1 with
-fprofile-use, it is miscompiled.  The problem is
that partition_hot_cold_basic_blocks leaves garbage (other bb
pointers) in bb->aux of some basic blocks and df_analyze
assumes (like other passes) that it is cleared and uses
->aux cast to ptrdiff_t as age value.
If the bb pointer is in the second half of address space (likely
on 32-bit, unlikely on 64-bit hosts), they are treated as negative age.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
ok for trunk?

We really should have some
#ifdef ENABLE_CHECKING
  FOR_ALL_BB (bb)
    gcc_assert (bb->aux == NULL);
#endif
somewhere in the pass manager and early in df_analyze.

2012-01-06  Jakub Jelinek  <jakub@redhat.com>

	PR gcov-profile/50127
	* bb-reorder.c (partition_hot_cold_basic_blocks): Clear
	bb->aux before running df_analyze.


	Jakub

Comments

Richard Henderson Jan. 6, 2012, 9:54 p.m. UTC | #1
On 01/07/2012 03:36 AM, Jakub Jelinek wrote:
> 	PR gcov-profile/50127
> 	* bb-reorder.c (partition_hot_cold_basic_blocks): Clear
> 	bb->aux before running df_analyze.

Ok except,

> +  /* Clear bb->aux fields that the above routines were using.  */
> +  FOR_EACH_BB (bb)
> +    bb->aux = NULL;

clear_aux_for_blocks


r~
diff mbox

Patch

--- gcc/bb-reorder.c.jj	2011-11-10 18:09:12.000000000 +0100
+++ gcc/bb-reorder.c	2012-01-06 13:47:39.619401395 +0100
@@ -2219,6 +2219,7 @@  static unsigned
 partition_hot_cold_basic_blocks (void)
 {
   VEC(edge, heap) *crossing_edges;
+  basic_block bb;
 
   if (n_basic_blocks <= NUM_FIXED_BLOCKS + 1)
     return 0;
@@ -2254,6 +2255,10 @@  partition_hot_cold_basic_blocks (void)
 
   add_reg_crossing_jump_notes ();
 
+  /* Clear bb->aux fields that the above routines were using.  */
+  FOR_EACH_BB (bb)
+    bb->aux = NULL;
+
   VEC_free (edge, heap, crossing_edges);
 
   /* ??? FIXME: DF generates the bb info for a block immediately.