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]

[Committed] Only allow INTEGER_CSTs of integral/pointer types.


In my on-going battle with middle-end type safety, I've recently been
investigating changing a lot of uses of fold_convert of constant integer
nodes to the more efficient build_int_cst.  I'm fairly sure I'd only
done this in integer contexts, but to be sure I hadn't accidently
modified anywhere where type could be a floating point type, I thought
it might be a good idea to add an appropriate assertion to tree.c's
build_int_cst infrastructure.

Sure enough no sooner did I add this sanity test than it immediately
failed in the testsuite (from a pre-existing issue) where we try to
construct an INTEGER_CST of vector type!

The patch below breaks out the new assertion (which happens to be
very easy to implement as we already switch on the tree code of the
type), and the correction for the current violation.  Turns out
that in gcc.c-torture/compile/simd-[15].c, we use make_tree to
convert an RTL CONST_VECTOR into a tree.  A minor mistake in this
code attempts to construct each element with the "outer" vector
type, instead of the "inner" component type.  The fix is obvious.


The patch below has been tested on i686-pc-linux-gnu, with a full
"make bootstrap", all default languages including Ada and regression
tested with a top-level "make -k check" with no new failures.

Committed to mainline as revision 118678.



2006-11-10  Roger Sayle  <roger@eyesopen.com>

	* tree.c (build_int_cst_wide): Add an assertion (gcc_unreachable)
	when attempting to build INTEGER_CSTs of non-integral types.
	* expmed.c (make_tree): Use the correct type, i.e. the inner
	type, when constructing the individual elements of a CONST_VECTOR.

Index: tree.c
===================================================================
*** tree.c	(revision 118593)
--- tree.c	(working copy)
*************** build_int_cst_wide (tree type, unsigned
*** 844,851 ****
  	    ix = 0;
  	}
        break;
!     default:
        break;
      }

    if (ix >= 0)
--- 844,855 ----
  	    ix = 0;
  	}
        break;
!
!     case ENUMERAL_TYPE:
        break;
+
+     default:
+       gcc_unreachable ();
      }

    if (ix >= 0)
Index: expmed.c
===================================================================
*** expmed.c	(revision 118593)
--- expmed.c	(working copy)
*************** make_tree (tree type, rtx x)
*** 4976,4992 ****

      case CONST_VECTOR:
        {
! 	int i, units;
! 	rtx elt;
  	tree t = NULL_TREE;

- 	units = CONST_VECTOR_NUNITS (x);

  	/* Build a tree with vector elements.  */
  	for (i = units - 1; i >= 0; --i)
  	  {
! 	    elt = CONST_VECTOR_ELT (x, i);
! 	    t = tree_cons (NULL_TREE, make_tree (type, elt), t);
  	  }

  	return build_vector (type, t);
--- 4976,4992 ----

      case CONST_VECTOR:
        {
! 	int units = CONST_VECTOR_NUNITS (x);
! 	tree itype = TREE_TYPE (type);
  	tree t = NULL_TREE;
+ 	int i;


  	/* Build a tree with vector elements.  */
  	for (i = units - 1; i >= 0; --i)
  	  {
! 	    rtx elt = CONST_VECTOR_ELT (x, i);
! 	    t = tree_cons (NULL_TREE, make_tree (itype, elt), t);
  	  }

  	return build_vector (type, t);


Roger
--


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