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: PR c++/19148


The patch I installed for c++/16405 (to eliminate certain temporary
objects) caused c++/19148.  The gimplifier had failed to consider the
condition for a COND_EXPR might contain post-increments.  Fixed with
the attached near-obvious patch, tested on x86_64-unknown-linux-gnu,
applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2004-12-27  Mark Mitchell  <mark@codesourcery.com>

	PR c++/19148
	* gimplify.c (gimplify_cond_expr): Add post_p parameter.
	(gimplify_modify_expr_rhs): Adjust call to gimplify_cond_expr.
	(gimplify_expr): Likewise.

2004-12-27  Mark Mitchell  <mark@codesourcery.com>

	PR c++/19148
	* g++.dg/expr/cond7.C: New test.

Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimplify.c,v
retrieving revision 2.98
diff -c -5 -p -r2.98 gimplify.c
*** gimplify.c	23 Dec 2004 21:55:09 -0000	2.98
--- gimplify.c	27 Dec 2004 16:04:31 -0000
*************** gimple_boolify (tree expr)
*** 2091,2104 ****
      The second form is used when *EXPR_P is of type void.
  
      TARGET is the tree for T1 above.
  
      PRE_P points to the list where side effects that must happen before
! 	*EXPR_P should be stored.  */
  
  static enum gimplify_status
! gimplify_cond_expr (tree *expr_p, tree *pre_p, tree target)
  {
    tree expr = *expr_p;
    tree tmp, tmp2, type;
    enum gimplify_status ret;
  
--- 2091,2107 ----
      The second form is used when *EXPR_P is of type void.
  
      TARGET is the tree for T1 above.
  
      PRE_P points to the list where side effects that must happen before
! 	*EXPR_P should be stored.
! 
!    POST_P points to the list where side effects that must happen after
!      *EXPR_P should be stored.  */
  
  static enum gimplify_status
! gimplify_cond_expr (tree *expr_p, tree *pre_p, tree *post_p, tree target)
  {
    tree expr = *expr_p;
    tree tmp, tmp2, type;
    enum gimplify_status ret;
  
*************** gimplify_cond_expr (tree *expr_p, tree *
*** 2110,2120 ****
       the arms.  */
    else if (! VOID_TYPE_P (type))
      {
        if (target)
  	{
! 	  ret = gimplify_expr (&target, pre_p, NULL,
  			       is_gimple_min_lval, fb_lvalue);
  	  if (ret != GS_ERROR)
  	    ret = GS_OK;
  	  tmp = target;
  	  tmp2 = unshare_expr (target);
--- 2113,2123 ----
       the arms.  */
    else if (! VOID_TYPE_P (type))
      {
        if (target)
  	{
! 	  ret = gimplify_expr (&target, pre_p, post_p,
  			       is_gimple_min_lval, fb_lvalue);
  	  if (ret != GS_ERROR)
  	    ret = GS_OK;
  	  tmp = target;
  	  tmp2 = unshare_expr (target);
*************** gimplify_modify_expr_rhs (tree *expr_p, 
*** 2871,2881 ****
  	   since we cannot generate temporaries for such, but it saves a
  	   copy in other cases as well.  */
  	if (!is_gimple_reg_type (TREE_TYPE (*from_p)))
  	  {
  	    *expr_p = *from_p;
! 	    return gimplify_cond_expr (expr_p, pre_p, *to_p);
  	  }
  	else
  	  ret = GS_UNHANDLED;
  	break;
  
--- 2874,2884 ----
  	   since we cannot generate temporaries for such, but it saves a
  	   copy in other cases as well.  */
  	if (!is_gimple_reg_type (TREE_TYPE (*from_p)))
  	  {
  	    *expr_p = *from_p;
! 	    return gimplify_cond_expr (expr_p, pre_p, post_p, *to_p);
  	  }
  	else
  	  ret = GS_UNHANDLED;
  	break;
  
*************** gimplify_expr (tree *expr_p, tree *pre_p
*** 3689,3699 ****
  	  ret = gimplify_compound_lval (expr_p, pre_p, post_p,
  					fallback ? fallback : fb_rvalue);
  	  break;
  
  	case COND_EXPR:
! 	  ret = gimplify_cond_expr (expr_p, pre_p, NULL_TREE);
  	  break;
  
  	case CALL_EXPR:
  	  ret = gimplify_call_expr (expr_p, pre_p, fallback != fb_none);
  	  break;
--- 3692,3702 ----
  	  ret = gimplify_compound_lval (expr_p, pre_p, post_p,
  					fallback ? fallback : fb_rvalue);
  	  break;
  
  	case COND_EXPR:
! 	  ret = gimplify_cond_expr (expr_p, pre_p, post_p, NULL_TREE);
  	  break;
  
  	case CALL_EXPR:
  	  ret = gimplify_call_expr (expr_p, pre_p, fallback != fb_none);
  	  break;
Index: testsuite/g++.dg/expr/cond7.C
===================================================================
RCS file: testsuite/g++.dg/expr/cond7.C
diff -N testsuite/g++.dg/expr/cond7.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/expr/cond7.C	27 Dec 2004 16:12:37 -0000
***************
*** 0 ****
--- 1,12 ----
+ // PR c++/19148
+ 
+ struct QChar {
+   QChar (char c);
+   QChar (const QChar &);
+   unsigned short ucs;
+ };
+ 
+ void f(QChar *uc, unsigned short ch, QChar replacement)
+ {
+   *uc++ = ((ch) ? QChar((1)) : replacement);
+ }


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