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] Preserve TREE_OVERFLOW in convert_to_pointer


The following patch is a minor tweak to the middle-end's
convert_to_pointer function.  In addition to a whitespace fix,
it does three things.  Firstly, it returns early if the argument
is already of the correct type.  Secondly it uses fold_build1
instead of build1 so that the return value is guaranteed to have
been folded.  And finally, it ensures that the TREE_OVERFLOW and
TREE_CONSTANT_OVERFLOW bits are always correctly preserved.

Currently, the code for this last aspect is dead as integer_zerop
always returns false if the TREE_CONSTANT_OVERFLOW bit is set, but
should this ever change in the future this code would be needed to
keep track of the overflow status of NULL pointers.

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

Committed to mainline as revision 112511.



2006-03-29  Roger Sayle  <roger@eyesopen.com>

	* convert.c (convert_to_pointer): Preserve the TREE_OVERFLOW
	and TREE_CONSTANT_OVERFLOW bits of the argument.  Return
	quickly if the argument is already of the correct type.  Call
	fold_build1 instead of build1.  Tidy up blank lines.


Index: convert.c
===================================================================
*** convert.c	(revision 112378)
--- convert.c	(working copy)
*************** Software Foundation, 51 Franklin Street,
*** 33,54 ****
  #include "toplev.h"
  #include "langhooks.h"
  #include "real.h"
- /* Convert EXPR to some pointer or reference type TYPE.

     EXPR must be pointer, reference, integer, enumeral, or literal zero;
     in other cases error is called.  */

  tree
  convert_to_pointer (tree type, tree expr)
  {
    if (integer_zerop (expr))
!     return build_int_cst (type, 0);

    switch (TREE_CODE (TREE_TYPE (expr)))
      {
      case POINTER_TYPE:
      case REFERENCE_TYPE:
!       return build1 (NOP_EXPR, type, expr);

      case INTEGER_TYPE:
      case ENUMERAL_TYPE:
--- 33,63 ----
  #include "toplev.h"
  #include "langhooks.h"
  #include "real.h"

+ /* Convert EXPR to some pointer or reference type TYPE.
     EXPR must be pointer, reference, integer, enumeral, or literal zero;
     in other cases error is called.  */

  tree
  convert_to_pointer (tree type, tree expr)
  {
+   if (TREE_TYPE (expr) == type)
+     return expr;
+
    if (integer_zerop (expr))
!     {
!       tree t = build_int_cst (type, 0);
!       if (TREE_OVERFLOW (expr) || TREE_CONSTANT_OVERFLOW (expr))
! 	t = force_fit_type (t, 0, TREE_OVERFLOW (expr),
! 			    TREE_CONSTANT_OVERFLOW (expr));
!       return t;
!     }

    switch (TREE_CODE (TREE_TYPE (expr)))
      {
      case POINTER_TYPE:
      case REFERENCE_TYPE:
!       return fold_build1 (NOP_EXPR, type, expr);

      case INTEGER_TYPE:
      case ENUMERAL_TYPE:


Roger
--


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