C front end patch for ICE on invalid vector code

James E Wilson wilson@specifixinc.com
Fri Sep 10 04:31:00 GMT 2004


This simple testcase triggers an ICE.
  typedef float v2sf __attribute__ ((vector_size (8)));
  v2sf a = 0.0; 

The problem is that vector_types_convertible_p requires two vector
types, however, we are passing it in one vector type and one scalar
type.  It then ICEs when looking at TREE_TYPE (scalar_type) which is
NULL.  There are two places where it is called, and both need to be
fixed for this testcase to work.

There is an additional problem that the testcase emits two errors after
the ICE is fixed.  The second error complains that the initializer isn't
constant, which is clearly is.  This happens because we check for
TREE_CONSTANT without first checking for error_mark_node.

The attached patches fixes all of these problems, and adds the testcase
to the testsuite.

This was tested with an x86_64-linux bootstrap and make check.  There
were no regressions.

I have checked in this patch.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com

-------------- next part --------------
gcc/ChangeLog
2004-09-09  James E Wilson  <wilson@specifixinc.com>

	* c-typeck.c (convert_for_assignment): Check that rhs has VECTOR_TYPE
	before calling vector_types_convertible_p.
	(digest_init): Check that inside_init has VECTOR_TYPE before calling
	vector_types_convertible_p.  Don't give another error if
	convert_for_assignment returns error_mark_node.

gcc/testsuite/ChangeLog
2004-09-09  James E Wilson  <wilson@specifixinc.com>

	* gcc.dg/init-vec-1.c: New test.

Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.365
diff -p -p -r1.365 c-typeck.c
*** c-typeck.c	1 Sep 2004 07:55:38 -0000	1.365
--- c-typeck.c	10 Sep 2004 00:34:36 -0000
*************** convert_for_assignment (tree type, tree 
*** 3313,3319 ****
        return rhs;
      }
    /* Some types can interconvert without explicit casts.  */
!   else if (codel == VECTOR_TYPE
             && vector_types_convertible_p (type, TREE_TYPE (rhs)))
      return convert (type, rhs);
    /* Arithmetic types all interconvert, and enum is treated like int.  */
--- 3313,3319 ----
        return rhs;
      }
    /* Some types can interconvert without explicit casts.  */
!   else if (codel == VECTOR_TYPE && coder == VECTOR_TYPE
             && vector_types_convertible_p (type, TREE_TYPE (rhs)))
      return convert (type, rhs);
    /* Arithmetic types all interconvert, and enum is treated like int.  */
*************** digest_init (tree type, tree init, bool 
*** 3989,3994 ****
--- 3989,3995 ----
       vector constructor is not constant (e.g. {1,2,3,foo()}) then punt
       below and handle as a constructor.  */
      if (code == VECTOR_TYPE
+ 	&& TREE_CODE (TREE_TYPE (inside_init)) == VECTOR_TYPE
          && vector_types_convertible_p (TREE_TYPE (inside_init), type)
          && TREE_CONSTANT (inside_init))
        {
*************** digest_init (tree type, tree init, bool 
*** 4103,4109 ****
  	= convert_for_assignment (type, init, _("initialization"),
  				  NULL_TREE, NULL_TREE, 0);
  
!       if (require_constant && ! TREE_CONSTANT (inside_init))
  	{
  	  error_init ("initializer element is not constant");
  	  inside_init = error_mark_node;
--- 4104,4113 ----
  	= convert_for_assignment (type, init, _("initialization"),
  				  NULL_TREE, NULL_TREE, 0);
  
!       /* Check to see if we have already given an error message.  */
!       if (inside_init == error_mark_node)
! 	;
!       else if (require_constant && ! TREE_CONSTANT (inside_init))
  	{
  	  error_init ("initializer element is not constant");
  	  inside_init = error_mark_node;
Index: testsuite/gcc.dg/init-vec-1.c
===================================================================
RCS file: testsuite/gcc.dg/init-vec-1.c
diff -N testsuite/gcc.dg/init-vec-1.c
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.dg/init-vec-1.c	10 Sep 2004 00:34:36 -0000
***************
*** 0 ****
--- 1,4 ----
+ /* Don't ICE or emit spurious errors when init a vector with a scalar.  */
+ /* { dg-do compile } */
+ typedef float v2sf __attribute__ ((vector_size (8)));
+ v2sf a = 0.0;  /* { dg-error "incompatible types" } */


More information about the Gcc-patches mailing list