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]

[PATCH] Clean-up TREE_OVERFLOW usage in the C front-end


This patch is a repost of the C front-end bits of my previous patch
http://gcc.gnu.org/ml/gcc-patches/2005-04/msg02412.html to clean-up
the use of TREE_OVERFLOW in the compiler.  Currently, TREE_OVERFLOW
is only ever set for constant class tree codes, such as INTEGER_CST.
By restricting the testing of TREE_OVERFLOW to the appropriate tree
nodes, we can introduce stricter checking in the middle-end.


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

Ok for mainline?



2005-06-06  Roger Sayle  <roger@eyesopen.com>

	* c-decl.c (grokdeclarator): Only check TREE_OVERFLOW on
	INTEGER_CST nodes.
	* c-typeck.c (build_c_cast): Only preserve TREE_OVERFLOW on
	CONSTANT_CLASS_P nodes.


Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.661
diff -c -3 -p -r1.661 c-decl.c
*** c-decl.c	3 Jun 2005 22:25:13 -0000	1.661
--- c-decl.c	6 Jun 2005 03:03:18 -0000
*************** grokdeclarator (const struct c_declarato
*** 4192,4198 ****
  		       index_type, before the subtraction.  Handling
  		       this case seems like an unnecessary
  		       complication.  */
! 		    if (TREE_OVERFLOW (itype))
  		      {
  			error ("size of array %qs is too large", name);
  			type = error_mark_node;
--- 4192,4199 ----
  		       index_type, before the subtraction.  Handling
  		       this case seems like an unnecessary
  		       complication.  */
! 		    if (TREE_CODE (itype) == INTEGER_CST
! 			&& TREE_OVERFLOW (itype))
  		      {
  			error ("size of array %qs is too large", name);
  			type = error_mark_node;
*************** grokdeclarator (const struct c_declarato
*** 4357,4362 ****
--- 4358,4364 ----

    if (TREE_CODE (type) == ARRAY_TYPE
        && COMPLETE_TYPE_P (type)
+       && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
        && TREE_OVERFLOW (TYPE_SIZE (type)))
      {
        error ("size of array %qs is too large", name);
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.448
diff -c -3 -p -r1.448 c-typeck.c
*** c-typeck.c	4 Jun 2005 01:34:44 -0000	1.448
--- c-typeck.c	6 Jun 2005 03:03:20 -0000
*************** build_c_cast (tree type, tree expr)
*** 3353,3369 ****
        /* Ignore any integer overflow caused by the cast.  */
        if (TREE_CODE (value) == INTEGER_CST)
  	{
! 	  if (EXPR_P (ovalue))
! 	    /* If OVALUE had overflow set, then so will VALUE, so it
! 	       is safe to overwrite.  */
! 	    TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
  	  else
  	    TREE_OVERFLOW (value) = 0;
-
- 	  if (CONSTANT_CLASS_P (ovalue))
- 	    /* Similarly, constant_overflow cannot have become
- 	       cleared.  */
- 	    TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
  	}
      }

--- 3353,3368 ----
        /* Ignore any integer overflow caused by the cast.  */
        if (TREE_CODE (value) == INTEGER_CST)
  	{
! 	  /* If OVALUE had overflow set, then so will VALUE, so it
! 	     is safe to overwrite.  */
! 	  if (CONSTANT_CLASS_P (ovalue))
! 	    {
! 	      TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
! 	      /* Similarly, constant_overflow cannot have become cleared.  */
! 	      TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
! 	    }
  	  else
  	    TREE_OVERFLOW (value) = 0;
  	}
      }


Roger
--


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