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] Fix m32c issues


This should fix the m32c issues with its mismatch in the precision of
pointer and sizetype.  The patch makes sure we always sign-extend the
offset in a POINTER_PLUS_EXPR when expanding - consistent with what
we do for constants.

Bootstrap and regtest on x86_64-unknown-linux-gnu running - DJ, can you
re-check this on m32c?

Thanks,
Richard.

2008-11-14  Richard Guenther  <rguenther@suse.de>

	* tree.c (build2_stat): Allow non-POINTER_PLUS_EXPRs with
	non-sizetype offsets if their precision matches that of
	the pointer.
	* expr.c (expand_expr_real_1): Always sign-extend the offset
	operand of a POINTER_PLUS_EXPR.

Index: gcc/tree.c
===================================================================
*** gcc/tree.c	(revision 141714)
--- gcc/tree.c	(working copy)
*************** build2_stat (enum tree_code code, tree t
*** 3289,3296 ****
    gcc_assert (TREE_CODE_LENGTH (code) == 2);
  
    if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
!       && arg0 && arg1 && tt && POINTER_TYPE_P (tt))
!     gcc_assert (TREE_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) == INTEGER_CST);
  
    if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
      gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
--- 3289,3301 ----
    gcc_assert (TREE_CODE_LENGTH (code) == 2);
  
    if ((code == MINUS_EXPR || code == PLUS_EXPR || code == MULT_EXPR)
!       && arg0 && arg1 && tt && POINTER_TYPE_P (tt)
!       /* When sizetype precision doesn't match that of pointers
!          we need to be able to build explicit extensions or truncations
! 	 of the offset argument.  */
!       && TYPE_PRECISION (sizetype) == TYPE_PRECISION (tt))
!     gcc_assert (TREE_CODE (arg0) == INTEGER_CST
! 		&& TREE_CODE (arg1) == INTEGER_CST);
  
    if (code == POINTER_PLUS_EXPR && arg0 && arg1 && tt)
      gcc_assert (POINTER_TYPE_P (tt) && POINTER_TYPE_P (TREE_TYPE (arg0))
Index: gcc/expr.c
===================================================================
*** gcc/expr.c	(revision 141714)
--- gcc/expr.c	(working copy)
*************** expand_expr_real_1 (tree exp, rtx target
*** 8324,8329 ****
--- 8324,8337 ----
        /* Even though the sizetype mode and the pointer's mode can be different
           expand is able to handle this correctly and get the correct result out 
           of the PLUS_EXPR code.  */
+       /* Make sure to sign-extend the sizetype offset in a POINTER_PLUS_EXPR
+          if sizetype precision is smaller than pointer precision.  */
+       if (TYPE_PRECISION (sizetype) < TYPE_PRECISION (type))
+ 	exp = build2 (PLUS_EXPR, type,
+ 		      TREE_OPERAND (exp, 0),
+ 		      fold_convert (type,
+ 				    fold_convert (ssizetype,
+ 						  TREE_OPERAND (exp, 1))));
      case PLUS_EXPR:
  
        /* Check if this is a case for multiplication and addition.  */


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