This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[vta, vta4.4] avoid crash expanding &r[N] in debug stmt


It may happen (gcc.c-torture/execute/921013-1.c on ppc64 -O3) that
optimizing access to an array make it a non-addressable pseudo, while
addresses of array members survive in debug stmts.

We expand r[i] into a nice subreg when i < N, N being the array length,
but when i == N, we attempted to create an invalid SUBREG, which ICEd.

This patch catches this condition and gives up on computing a
location/value expression for the object that no longer exists.

I'm installing it in the vta and vta4.4 branches.

for  gcc/ChangeLog.vta
from  Alexandre Oliva  <aoliva@redhat.com>

	* cfgexpand.c (expand_debug_expr): Fail gracefully when computing
	address one-past-the-end of array made non-addressable.

Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c.orig	2009-08-04 06:47:20.000000000 -0300
+++ gcc/cfgexpand.c	2009-08-05 04:29:57.000000000 -0300
@@ -2538,10 +2538,26 @@ expand_debug_expr (tree exp)
 
 	if ((bitpos % BITS_PER_UNIT) == 0
 	    && bitsize == GET_MODE_BITSIZE (mode1))
-	  return simplify_gen_subreg (mode, op0,
-				      GET_MODE (op0) != VOIDmode
-				      ? GET_MODE (op0) : mode1,
-				      bitpos / BITS_PER_UNIT);
+	  {
+	    enum machine_mode opmode = GET_MODE (op0);
+
+	    gcc_assert (opmode != BLKmode);
+
+	    if (opmode == VOIDmode)
+	      opmode = mode1;
+
+	    /* This condition may hold if we're expanding the address
+	       right past the end of an array that turned out not to
+	       be addressable (i.e., the address was only computed in
+	       debug stmts).  The gen_subreg below would rightfully
+	       crash, and the address doesn't really exist, so just
+	       drop it.  */
+	    if (bitpos >= GET_MODE_BITSIZE (opmode))
+	      return NULL;
+
+	    return simplify_gen_subreg (mode, op0, opmode,
+					bitpos / BITS_PER_UNIT);
+	  }
 
 	return simplify_gen_ternary (SCALAR_INT_MODE_P (GET_MODE (op0))
 				     && TYPE_UNSIGNED (TREE_TYPE (exp))
-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]