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 to avoid incorrect uses of build


While playing around with another patch, I noticed that we were calling
build() for a number of non-expressions.  This is wrong.

I tried requiring that the code be for an expression, but ran into some
issues.

One, PLACEHOLDER_EXPR doesn't have an expression tree code class.
It probably should.

Two, the C++ frontend uses build (ERROR_MARK, type) in cp_fname_init.  This
is horrible, but I haven't gotten around to fixing it yet.  Nathan, what is
the point of doing that rather than just leaving DECL_INITIAL null?

In any case, fixing some of the incorrect uses is an improvement.  Tested
x86_64-pc-linux-gnu, applied to trunk.

2003-10-09  Jason Merrill  <jason@redhat.com>

	* coverage.c (build_ctr_info_value): Use build_decl to make a
	VAR_DECL.
	(create_coverage): Likewise.

	* tree.c (build_cplus_new): Use build_decl to create a VAR_DECL.
	(build_target_expr_with_type): Likewise.

	* parse.y (patch_assignment): Use make_node to create a BLOCK.
	* parse.h (BUILD_PTR_FROM_NAME): Use make_node to create a
	POINTER_TYPE.

*** ./cp/tree.c.~1~	2003-09-25 17:21:53.000000000 -0400
--- ./cp/tree.c	2003-09-23 17:25:36.000000000 -0400
*************** build_cplus_new (tree type, tree init)
*** 269,275 ****
  	     && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
  	     && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
  
!   slot = build (VAR_DECL, type);
    DECL_ARTIFICIAL (slot) = 1;
    DECL_CONTEXT (slot) = current_function_decl;
    layout_decl (slot, 0);
--- 269,275 ----
  	     && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
  	     && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0)));
  
!   slot = build_decl (VAR_DECL, NULL_TREE, type);
    DECL_ARTIFICIAL (slot) = 1;
    DECL_CONTEXT (slot) = current_function_decl;
    layout_decl (slot, 0);
*************** build_target_expr_with_type (tree init, 
*** 311,317 ****
    if (TREE_CODE (init) == TARGET_EXPR)
      return init;
  
!   slot = build (VAR_DECL, type);
    DECL_ARTIFICIAL (slot) = 1;
    DECL_CONTEXT (slot) = current_function_decl;
    layout_decl (slot, 0);
--- 311,317 ----
    if (TREE_CODE (init) == TARGET_EXPR)
      return init;
  
!   slot = build_decl (VAR_DECL, NULL_TREE, type);
    DECL_ARTIFICIAL (slot) = 1;
    DECL_CONTEXT (slot) = current_function_decl;
    layout_decl (slot, 0);
*** ./java/parse.h.~1~	2003-09-25 17:21:53.000000000 -0400
--- ./java/parse.h	2003-09-23 17:25:36.000000000 -0400
*************** extern tree stabilize_reference (tree);
*** 154,160 ****
  /* Quickly build a temporary pointer on hypothetical type NAME. */
  #define BUILD_PTR_FROM_NAME(ptr, name)		\
    do {						\
!     ptr = build (POINTER_TYPE, NULL_TREE);	\
      TYPE_NAME (ptr) = name;			\
    } while (0)
  
--- 154,160 ----
  /* Quickly build a temporary pointer on hypothetical type NAME. */
  #define BUILD_PTR_FROM_NAME(ptr, name)		\
    do {						\
!     ptr = make_node (POINTER_TYPE);		\
      TYPE_NAME (ptr) = name;			\
    } while (0)
  
*** ./java/parse.y.~1~	2003-09-25 17:21:53.000000000 -0400
--- ./java/parse.y	2003-09-23 17:26:37.000000000 -0400
*************** patch_assignment (tree node, tree wfl_op
*** 12928,12937 ****
  	  {
  	    tree tmp = build_decl (VAR_DECL, get_identifier ("<tmp>"), 
  				   TREE_TYPE (new_rhs));
! 	    tree block = build (BLOCK, TREE_TYPE (new_rhs), NULL);
  	    tree assignment 
  	      = build (MODIFY_EXPR, TREE_TYPE (new_rhs), tmp, fold (new_rhs));
  	    DECL_CONTEXT (tmp) = current_function_decl;
  	    BLOCK_VARS (block) = tmp;
  	    BLOCK_EXPR_BODY (block) 
  	      = build (COMPOUND_EXPR, TREE_TYPE (new_rhs), assignment, tmp);
--- 12928,12938 ----
  	  {
  	    tree tmp = build_decl (VAR_DECL, get_identifier ("<tmp>"), 
  				   TREE_TYPE (new_rhs));
! 	    tree block = make_node (BLOCK);
  	    tree assignment 
  	      = build (MODIFY_EXPR, TREE_TYPE (new_rhs), tmp, fold (new_rhs));
  	    DECL_CONTEXT (tmp) = current_function_decl;
+ 	    TREE_TYPE (block) = TREE_TYPE (new_rhs);
  	    BLOCK_VARS (block) = tmp;
  	    BLOCK_EXPR_BODY (block) 
  	      = build (COMPOUND_EXPR, TREE_TYPE (new_rhs), assignment, tmp);
*** ./coverage.c.~1~	2003-09-25 17:21:53.000000000 -0400
--- ./coverage.c	2003-09-23 17:25:42.000000000 -0400
*************** build_ctr_info_value (unsigned int count
*** 637,643 ****
        array_type = build_array_type (TREE_TYPE (TREE_TYPE (fields)),
  				     array_type);
  
!       array = build (VAR_DECL, array_type, NULL_TREE, NULL_TREE);
        TREE_STATIC (array) = 1;
        DECL_NAME (array) = get_identifier (XSTR (ctr_labels[counter], 0));
        assemble_variable (array, 0, 0, 0);
--- 637,643 ----
        array_type = build_array_type (TREE_TYPE (TREE_TYPE (fields)),
  				     array_type);
  
!       array = build_decl (VAR_DECL, NULL_TREE, array_type);
        TREE_STATIC (array) = 1;
        DECL_NAME (array) = get_identifier (XSTR (ctr_labels[counter], 0));
        assemble_variable (array, 0, 0, 0);
*************** create_coverage (void)
*** 824,831 ****
  
    gcov_info_value = build_gcov_info ();
  
!   gcov_info = build (VAR_DECL, TREE_TYPE (gcov_info_value),
! 		     NULL_TREE, NULL_TREE);
    DECL_INITIAL (gcov_info) = gcov_info_value;
  
    TREE_STATIC (gcov_info) = 1;
--- 824,830 ----
  
    gcov_info_value = build_gcov_info ();
  
!   gcov_info = build_decl (VAR_DECL, NULL_TREE, TREE_TYPE (gcov_info_value));
    DECL_INITIAL (gcov_info) = gcov_info_value;
  
    TREE_STATIC (gcov_info) = 1;

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