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]: Fix 11957


Hi,
I've installed this patch for 11957, a regression caused by my 11512 fix.
It showed a problem I introduced by separating out the statement-expression
extension, and a latent problem with the array assignment extension --
we'd have the type of the resultant assignment incorrect.

booted & tested on i686-pc-linux-gnu.

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
         The voices in my head said this was stupid too
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2003-08-18  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/11957
	* cp-tree.h (finish_stmt_expr): Add bool parameter.
	* init.c (finish_init_stmts): Pass true to finish_stmt_expr. Don't
	adjust the stmt_expr here.
	(build_vec_init): Use finish_stmt_expr_expr, convert result to
	array type.
	* parser.c (cp_parser_primar_expression): Adjust finish_stmt_expr
	call.
	* pt.c (tsubst_copy): Likewise.
	* semantics.c (finish_stmt_expr): Add parameter.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.902
diff -c -3 -p -r1.902 cp-tree.h
*** cp/cp-tree.h	15 Aug 2003 11:14:01 -0000	1.902
--- cp/cp-tree.h	18 Aug 2003 12:29:08 -0000
*************** extern tree finish_parenthesized_expr   
*** 4102,4108 ****
  extern tree finish_non_static_data_member       (tree, tree, tree);
  extern tree begin_stmt_expr                     (void);
  extern tree finish_stmt_expr_expr 		(tree);
! extern tree finish_stmt_expr                    (tree);
  extern tree perform_koenig_lookup               (tree, tree);
  extern tree finish_call_expr                    (tree, tree, bool);
  extern tree finish_increment_expr               (tree, enum tree_code);
--- 4102,4108 ----
  extern tree finish_non_static_data_member       (tree, tree, tree);
  extern tree begin_stmt_expr                     (void);
  extern tree finish_stmt_expr_expr 		(tree);
! extern tree finish_stmt_expr                    (tree, bool);
  extern tree perform_koenig_lookup               (tree, tree);
  extern tree finish_call_expr                    (tree, tree, bool);
  extern tree finish_increment_expr               (tree, enum tree_code);
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.338
diff -c -3 -p -r1.338 init.c
*** cp/init.c	16 Aug 2003 13:32:09 -0000	1.338
--- cp/init.c	18 Aug 2003 12:29:46 -0000
*************** finish_init_stmts (bool is_global, tree 
*** 85,93 ****
  {  
    finish_compound_stmt (compound_stmt);
    
!   stmt_expr = finish_stmt_expr (stmt_expr);
!   STMT_EXPR_NO_SCOPE (stmt_expr) = true;
!   TREE_USED (stmt_expr) = 1;
  
    my_friendly_assert (!building_stmt_tree () == is_global, 20030726);
    
--- 85,91 ----
  {  
    finish_compound_stmt (compound_stmt);
    
!   stmt_expr = finish_stmt_expr (stmt_expr, true);
  
    my_friendly_assert (!building_stmt_tree () == is_global, 20030726);
    
*************** build_vec_init (tree base, tree maxindex
*** 2478,2484 ****
      base = cp_convert (ptype, decay_conversion (base));
  
    /* The code we are generating looks like:
! 
         T* t1 = (T*) base;
         T* rval = t1;
         ptrdiff_t iterator = maxindex;
--- 2476,2482 ----
      base = cp_convert (ptype, decay_conversion (base));
  
    /* The code we are generating looks like:
!      ({
         T* t1 = (T*) base;
         T* rval = t1;
         ptrdiff_t iterator = maxindex;
*************** build_vec_init (tree base, tree maxindex
*** 2490,2496 ****
         } catch (...) {
           ... destroy elements that were constructed ...
         }
!        return rval;
         
       We can omit the try and catch blocks if we know that the
       initialization will never throw an exception, or if the array
--- 2488,2495 ----
         } catch (...) {
           ... destroy elements that were constructed ...
         }
!        rval;
!      })
         
       We can omit the try and catch blocks if we know that the
       initialization will never throw an exception, or if the array
*************** build_vec_init (tree base, tree maxindex
*** 2662,2679 ****
  
        finish_compound_stmt (try_body);
        finish_cleanup_try_block (try_block);
!       e = build_vec_delete_1 (rval, m,
! 			      type,
! 			      sfk_base_destructor,
  			      /*use_global_delete=*/0);
        finish_cleanup (e, try_block);
      }
  
!   /* The value of the array initialization is the address of the
!      first element in the array.  */
!   finish_expr_stmt (rval);
  
    stmt_expr = finish_init_stmts (is_global, stmt_expr, compound_stmt);
    current_stmt_tree ()->stmts_are_full_exprs_p = destroy_temps;
    return stmt_expr;
  }
--- 2661,2682 ----
  
        finish_compound_stmt (try_body);
        finish_cleanup_try_block (try_block);
!       e = build_vec_delete_1 (rval, m, type, sfk_base_destructor,
  			      /*use_global_delete=*/0);
        finish_cleanup (e, try_block);
      }
  
!   /* The value of the array initialization is the array itself, RVAL
!      is a pointer to the first element.  */
!   finish_stmt_expr_expr (rval);
  
    stmt_expr = finish_init_stmts (is_global, stmt_expr, compound_stmt);
+ 
+   /* Now convert make the result have the correct type. */
+   atype = build_pointer_type (atype);
+   stmt_expr = build1 (NOP_EXPR, atype, stmt_expr);
+   stmt_expr = build_indirect_ref (stmt_expr, NULL);
+   
    current_stmt_tree ()->stmts_are_full_exprs_p = destroy_temps;
    return stmt_expr;
  }
Index: cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.100
diff -c -3 -p -r1.100 parser.c
*** cp/parser.c	12 Aug 2003 22:26:22 -0000	1.100
--- cp/parser.c	18 Aug 2003 12:30:16 -0000
*************** cp_parser_primary_expression (cp_parser 
*** 2270,2276 ****
  	    /* Parse the compound-statement.  */
  	    cp_parser_compound_statement (parser, true);
  	    /* Finish up.  */
! 	    expr = finish_stmt_expr (expr);
  	  }
  	else
  	  {
--- 2270,2276 ----
  	    /* Parse the compound-statement.  */
  	    cp_parser_compound_statement (parser, true);
  	    /* Finish up.  */
! 	    expr = finish_stmt_expr (expr, false);
  	  }
  	else
  	  {
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.758
diff -c -3 -p -r1.758 pt.c
*** cp/pt.c	15 Aug 2003 12:15:56 -0000	1.758
--- cp/pt.c	18 Aug 2003 12:30:40 -0000
*************** tsubst_copy (tree t, tree args, tsubst_f
*** 7335,7341 ****
  	  
  	  tsubst_expr (STMT_EXPR_STMT (t), args,
  		       complain | tf_stmt_expr_cmpd, in_decl);
! 	  return finish_stmt_expr (stmt_expr);
  	}
        
        return t;
--- 7343,7349 ----
  	  
  	  tsubst_expr (STMT_EXPR_STMT (t), args,
  		       complain | tf_stmt_expr_cmpd, in_decl);
! 	  return finish_stmt_expr (stmt_expr, false);
  	}
        
        return t;
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.347
diff -c -3 -p -r1.347 semantics.c
*** cp/semantics.c	17 Aug 2003 08:07:27 -0000	1.347
--- cp/semantics.c	18 Aug 2003 12:30:46 -0000
*************** finish_stmt_expr_expr (tree expr)
*** 1469,1481 ****
    return result;
  }
  
! /* Finish a statement-expression.  RTL_EXPR should be the value
!    returned by the previous begin_stmt_expr; EXPR is the
!    statement-expression.  Returns an expression representing the
!    statement-expression.  */
  
  tree 
! finish_stmt_expr (tree rtl_expr)
  {
    tree result;
    tree result_stmt = last_expr_type;
--- 1469,1480 ----
    return result;
  }
  
! /* Finish a statement-expression.  EXPR should be the value returned
!    by the previous begin_stmt_expr.  Returns an expression
!    representing the statement-expression.  */
  
  tree 
! finish_stmt_expr (tree rtl_expr, bool has_no_scope)
  {
    tree result;
    tree result_stmt = last_expr_type;
*************** finish_stmt_expr (tree rtl_expr)
*** 1496,1501 ****
--- 1495,1501 ----
    
    result = build_min (STMT_EXPR, type, last_tree);
    TREE_SIDE_EFFECTS (result) = 1;
+   STMT_EXPR_NO_SCOPE (result) = has_no_scope;
    
    last_expr_type = NULL_TREE;
    
// { dg-do compile }
// { dg-options "-Wall" }

// Copyright (C) 2003 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 18 Aug 2003 <nathan@codesourcery.com>

// PR 11957 Extra warning

struct A
{
  A (int = 0);
  A (A const &);
  A &operator=(A const &);
};

const A a[1] = {1};

void foo (A *ptr)
{
  A b[1];
  A c[1];

  c = b = a; // { dg-warning "assignment of arrays" "" }
}

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