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]

[C++] PATCH to build_modify_expr for c++/13371


PR 13371 was caused by reusing the lhs of an assignment without properly
stabilizing it.  The particular failure in 13371 was exposed by the patch
mentioned in the PR, but the underlying bug goes back at least to 3.0; we
were stabilizing lhs without updating the copy in olhs, so the
stabilization didn't really work properly.  Fixed thus.

Tested i686-pc-linux-gnu, applied to trunk and 3.3.  Test in
g++.dg/init/bitfield2.C.

2003-12-19  Jason Merrill  <jason@redhat.com>

	PR c++/13371
	* typeck.c (build_modify_expr): Stabilize lhs if we're narrowing.

*** typeck.c.~1~	2003-12-18 16:03:42.000000000 -0500
--- typeck.c	2003-12-19 00:20:14.000000000 -0500
*************** build_modify_expr (lhs, modifycode, rhs)
*** 5210,5216 ****
    tree newrhs = rhs;
    tree lhstype = TREE_TYPE (lhs);
    tree olhstype = lhstype;
!   tree olhs = lhs;
  
    /* Avoid duplicate error messages from operands that had errors.  */
    if (lhs == error_mark_node || rhs == error_mark_node)
--- 5210,5216 ----
    tree newrhs = rhs;
    tree lhstype = TREE_TYPE (lhs);
    tree olhstype = lhstype;
!   tree olhs = NULL_TREE;
  
    /* Avoid duplicate error messages from operands that had errors.  */
    if (lhs == error_mark_node || rhs == error_mark_node)
*************** build_modify_expr (lhs, modifycode, rhs)
*** 5446,5451 ****
--- 5446,5460 ----
  
        if (lhstype != TREE_TYPE (lhs))
  	{
+ 	  /* Avoid warnings converting integral types back into enums for
+ 	     enum bit fields.  */
+ 	  if (TREE_CODE (lhstype) == INTEGER_TYPE
+ 	      && TREE_CODE (olhstype) == ENUMERAL_TYPE)
+ 	    {
+ 	      if (TREE_SIDE_EFFECTS (lhs))
+ 		lhs = stabilize_reference (lhs);
+ 	      olhs = lhs;
+ 	    }
  	  lhs = copy_node (lhs);
  	  TREE_TYPE (lhs) = lhstype;
  	}
*************** build_modify_expr (lhs, modifycode, rhs)
*** 5518,5527 ****
  
    if (olhstype == TREE_TYPE (result))
      return result;
!   /* Avoid warnings converting integral types back into enums
!      for enum bit fields.  */
!   if (TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE
!       && TREE_CODE (olhstype) == ENUMERAL_TYPE)
      {
        result = build (COMPOUND_EXPR, olhstype, result, olhs);
        TREE_NO_UNUSED_WARNING (result) = 1;
--- 5527,5533 ----
  
    if (olhstype == TREE_TYPE (result))
      return result;
!   if (olhs)
      {
        result = build (COMPOUND_EXPR, olhstype, result, olhs);
        TREE_NO_UNUSED_WARNING (result) = 1;

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