[PATCH][4/n] Fix build_int_cst callers with NULL type

Richard Guenther rguenther@suse.de
Fri Apr 29 15:00:00 GMT 2011


Another round.  Missing is now tree-data-ref.c which better should
use double_ints.  Frontends also need a look, so do backends.

Bootstrap & regtest running on x86_64-unknown-linux-gnu, will apply
after that succeeded.

Richard.

2011-04-29  Richard Guenther  <rguenther@suse.de>

	* builtins.c (fold_builtin_classify_type): Use integer_type_node
	for the type of the result.
	(fold_builtin_isascii): Likewise.
	(fold_builtin_toascii): Use integer_type_node where appropriate.
	(fold_builtin_logb): Likewise.
	(fold_builtin_frexp): Likewise.
	(fold_builtin_strstr): Likewise.
	(fold_builtin_strpbrk): Likewise.
	(fold_builtin_fputs): Likewise.
	(fold_builtin_sprintf): Likewise.
	(fold_builtin_snprintf): Likewise.
	(fold_builtin_printf): Likewise.
	(do_mpfr_remquo): Use a proper type for the assigned constant.
	(do_mpfr_lgamma_r): Likewise.
	* dwarf2out.c (resolve_one_addr): Use size_int.
	* except.c (init_eh): Likewise.
	(assign_filter_values): Use integer_type_node for filter values.
	(sjlj_emit_dispatch_table): Use integer_type_node for dispatch
	indices.
	* tree-cfg.c (move_stmt_eh_region_tree_nr): Use integer_type_node
	for EH region numbers.
	* tree-vrp.c (simplify_div_or_mod_using_ranges): Use integer_type_node
	for the shift amount.

Index: gcc/builtins.c
===================================================================
*** gcc/builtins.c	(revision 173155)
--- gcc/builtins.c	(working copy)
*************** static tree
*** 6774,6782 ****
  fold_builtin_classify_type (tree arg)
  {
    if (arg == 0)
!     return build_int_cst (NULL_TREE, no_type_class);
  
!   return build_int_cst (NULL_TREE, type_to_class (TREE_TYPE (arg)));
  }
  
  /* Fold a call to __builtin_strlen with argument ARG.  */
--- 6774,6782 ----
  fold_builtin_classify_type (tree arg)
  {
    if (arg == 0)
!     return build_int_cst (integer_type_node, no_type_class);
  
!   return build_int_cst (integer_type_node, type_to_class (TREE_TYPE (arg)));
  }
  
  /* Fold a call to __builtin_strlen with argument ARG.  */
*************** fold_builtin_isascii (location_t loc, tr
*** 9134,9143 ****
      {
        /* Transform isascii(c) -> ((c & ~0x7f) == 0).  */
        arg = fold_build2 (BIT_AND_EXPR, integer_type_node, arg,
! 			 build_int_cst (NULL_TREE,
  					~ (unsigned HOST_WIDE_INT) 0x7f));
        return fold_build2_loc (loc, EQ_EXPR, integer_type_node,
! 			  arg, integer_zero_node);
      }
  }
  
--- 9134,9143 ----
      {
        /* Transform isascii(c) -> ((c & ~0x7f) == 0).  */
        arg = fold_build2 (BIT_AND_EXPR, integer_type_node, arg,
! 			 build_int_cst (integer_type_node,
  					~ (unsigned HOST_WIDE_INT) 0x7f));
        return fold_build2_loc (loc, EQ_EXPR, integer_type_node,
! 			      arg, integer_zero_node);
      }
  }
  
*************** fold_builtin_toascii (location_t loc, tr
*** 9151,9157 ****
  
    /* Transform toascii(c) -> (c & 0x7f).  */
    return fold_build2_loc (loc, BIT_AND_EXPR, integer_type_node, arg,
! 		      build_int_cst (NULL_TREE, 0x7f));
  }
  
  /* Fold a call to builtin isdigit with argument ARG.  */
--- 9151,9157 ----
  
    /* Transform toascii(c) -> (c & 0x7f).  */
    return fold_build2_loc (loc, BIT_AND_EXPR, integer_type_node, arg,
! 			  build_int_cst (integer_type_node, 0x7f));
  }
  
  /* Fold a call to builtin isdigit with argument ARG.  */
*************** fold_builtin_logb (location_t loc, tree
*** 9342,9348 ****
  	   exponent and subtract 1.  */
  	if (REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (arg)))->b == 2)
  	  return fold_convert_loc (loc, rettype,
! 				   build_int_cst (NULL_TREE,
  						  REAL_EXP (value)-1));
  	break;
        }
--- 9342,9348 ----
  	   exponent and subtract 1.  */
  	if (REAL_MODE_FORMAT (TYPE_MODE (TREE_TYPE (arg)))->b == 2)
  	  return fold_convert_loc (loc, rettype,
! 				   build_int_cst (integer_type_node,
  						  REAL_EXP (value)-1));
  	break;
        }
*************** fold_builtin_frexp (location_t loc, tree
*** 9430,9436 ****
  	  REAL_VALUE_TYPE frac_rvt = *value;
  	  SET_REAL_EXP (&frac_rvt, 0);
  	  frac = build_real (rettype, frac_rvt);
! 	  exp = build_int_cst (NULL_TREE, REAL_EXP (value));
  	}
  	break;
        default:
--- 9430,9436 ----
  	  REAL_VALUE_TYPE frac_rvt = *value;
  	  SET_REAL_EXP (&frac_rvt, 0);
  	  frac = build_real (rettype, frac_rvt);
! 	  exp = build_int_cst (integer_type_node, REAL_EXP (value));
  	}
  	break;
        default:
*************** fold_builtin_strstr (location_t loc, tre
*** 11215,11221 ****
  
        /* New argument list transforming strstr(s1, s2) to
  	 strchr(s1, s2[0]).  */
!       return build_call_expr_loc (loc, fn, 2, s1, build_int_cst (NULL_TREE, p2[0]));
      }
  }
  
--- 11215,11222 ----
  
        /* New argument list transforming strstr(s1, s2) to
  	 strchr(s1, s2[0]).  */
!       return build_call_expr_loc (loc, fn, 2, s1,
! 				  build_int_cst (integer_type_node, p2[0]));
      }
  }
  
*************** fold_builtin_strpbrk (location_t loc, tr
*** 11401,11407 ****
  
        /* New argument list transforming strpbrk(s1, s2) to
  	 strchr(s1, s2[0]).  */
!       return build_call_expr_loc (loc, fn, 2, s1, build_int_cst (NULL_TREE, p2[0]));
      }
  }
  
--- 11402,11409 ----
  
        /* New argument list transforming strpbrk(s1, s2) to
  	 strchr(s1, s2[0]).  */
!       return build_call_expr_loc (loc, fn, 2, s1,
! 				  build_int_cst (integer_type_node, p2[0]));
      }
  }
  
*************** fold_builtin_fputs (location_t loc, tree
*** 11684,11690 ****
  	  {
   	    if (fn_fputc)
  	      return build_call_expr_loc (loc, fn_fputc, 2,
! 				      build_int_cst (NULL_TREE, p[0]), arg1);
  	    else
  	      return NULL_TREE;
  	  }
--- 11686,11693 ----
  	  {
   	    if (fn_fputc)
  	      return build_call_expr_loc (loc, fn_fputc, 2,
! 					  build_int_cst
! 					    (integer_type_node, p[0]), arg1);
  	    else
  	      return NULL_TREE;
  	  }
*************** fold_builtin_sprintf (location_t loc, tr
*** 11856,11862 ****
  	 'format' is known to contain no % formats.  */
        call = build_call_expr_loc (loc, fn, 2, dest, fmt);
        if (!ignored)
! 	retval = build_int_cst (NULL_TREE, strlen (fmt_str));
      }
  
    /* If the format is "%s", use strcpy if the result isn't used.  */
--- 11859,11865 ----
  	 'format' is known to contain no % formats.  */
        call = build_call_expr_loc (loc, fn, 2, dest, fmt);
        if (!ignored)
! 	retval = build_int_cst (integer_type_node, strlen (fmt_str));
      }
  
    /* If the format is "%s", use strcpy if the result isn't used.  */
*************** fold_builtin_snprintf (location_t loc, t
*** 11964,11970 ****
        call = build_call_expr_loc (loc, fn, 2, dest, fmt);
  
        if (!ignored)
! 	retval = build_int_cst (NULL_TREE, strlen (fmt_str));
      }
  
    /* If the format is "%s", use strcpy if the result isn't used.  */
--- 11967,11973 ----
        call = build_call_expr_loc (loc, fn, 2, dest, fmt);
  
        if (!ignored)
! 	retval = build_int_cst (integer_type_node, strlen (fmt_str));
      }
  
    /* If the format is "%s", use strcpy if the result isn't used.  */
*************** fold_builtin_printf (location_t loc, tre
*** 12948,12954 ****
  	  /* Given printf("c"), (where c is any one character,)
  	     convert "c"[0] to an int and pass that to the replacement
  	     function.  */
! 	  newarg = build_int_cst (NULL_TREE, str[0]);
  	  if (fn_putchar)
  	    call = build_call_expr_loc (loc, fn_putchar, 1, newarg);
  	}
--- 12951,12957 ----
  	  /* Given printf("c"), (where c is any one character,)
  	     convert "c"[0] to an int and pass that to the replacement
  	     function.  */
! 	  newarg = build_int_cst (integer_type_node, str[0]);
  	  if (fn_putchar)
  	    call = build_call_expr_loc (loc, fn_putchar, 1, newarg);
  	}
*************** do_mpfr_remquo (tree arg0, tree arg1, tr
*** 13550,13558 ****
  	      if (TYPE_MAIN_VARIANT (TREE_TYPE (arg_quo)) == integer_type_node)
  	        {
  		  /* Set the value. */
! 		  tree result_quo = fold_build2 (MODIFY_EXPR,
! 						 TREE_TYPE (arg_quo), arg_quo,
! 						 build_int_cst (NULL, integer_quo));
  		  TREE_SIDE_EFFECTS (result_quo) = 1;
  		  /* Combine the quo assignment with the rem.  */
  		  result = non_lvalue (fold_build2 (COMPOUND_EXPR, type,
--- 13553,13562 ----
  	      if (TYPE_MAIN_VARIANT (TREE_TYPE (arg_quo)) == integer_type_node)
  	        {
  		  /* Set the value. */
! 		  tree result_quo
! 		    = fold_build2 (MODIFY_EXPR, TREE_TYPE (arg_quo), arg_quo,
! 				   build_int_cst (TREE_TYPE (arg_quo),
! 						  integer_quo));
  		  TREE_SIDE_EFFECTS (result_quo) = 1;
  		  /* Combine the quo assignment with the rem.  */
  		  result = non_lvalue (fold_build2 (COMPOUND_EXPR, type,
*************** do_mpfr_lgamma_r (tree arg, tree arg_sg,
*** 13617,13623 ****
  	      /* Assign the signgam value into *arg_sg. */
  	      result_sg = fold_build2 (MODIFY_EXPR,
  				       TREE_TYPE (arg_sg), arg_sg,
! 				       build_int_cst (NULL, sg));
  	      TREE_SIDE_EFFECTS (result_sg) = 1;
  	      /* Combine the signgam assignment with the lgamma result.  */
  	      result = non_lvalue (fold_build2 (COMPOUND_EXPR, type,
--- 13621,13627 ----
  	      /* Assign the signgam value into *arg_sg. */
  	      result_sg = fold_build2 (MODIFY_EXPR,
  				       TREE_TYPE (arg_sg), arg_sg,
! 				       build_int_cst (TREE_TYPE (arg_sg), sg));
  	      TREE_SIDE_EFFECTS (result_sg) = 1;
  	      /* Combine the signgam assignment with the lgamma result.  */
  	      result = non_lvalue (fold_build2 (COMPOUND_EXPR, type,
Index: gcc/dwarf2out.c
===================================================================
*** gcc/dwarf2out.c	(revision 173155)
--- gcc/dwarf2out.c	(working copy)
*************** resolve_one_addr (rtx *addr, void *data
*** 22966,22972 ****
      {
        size_t len = strlen (XSTR (rtl, 0)) + 1;
        tree t = build_string (len, XSTR (rtl, 0));
!       tree tlen = build_int_cst (NULL_TREE, len - 1);
        TREE_TYPE (t)
  	= build_array_type (char_type_node, build_index_type (tlen));
        rtl = lookup_constant_def (t);
--- 22966,22972 ----
      {
        size_t len = strlen (XSTR (rtl, 0)) + 1;
        tree t = build_string (len, XSTR (rtl, 0));
!       tree tlen = size_int (len - 1);
        TREE_TYPE (t)
  	= build_array_type (char_type_node, build_index_type (tlen));
        rtl = lookup_constant_def (t);
Index: gcc/except.c
===================================================================
*** gcc/except.c	(revision 173155)
--- gcc/except.c	(working copy)
*************** init_eh (void)
*** 225,231 ****
  			 integer_type_node);
        DECL_FIELD_CONTEXT (f_cs) = sjlj_fc_type_node;
  
!       tmp = build_index_type (build_int_cst (NULL_TREE, 4 - 1));
        tmp = build_array_type (lang_hooks.types.type_for_mode
  				(targetm.unwind_word_mode (), 1),
  			      tmp);
--- 225,231 ----
  			 integer_type_node);
        DECL_FIELD_CONTEXT (f_cs) = sjlj_fc_type_node;
  
!       tmp = build_index_type (size_int (4 - 1));
        tmp = build_array_type (lang_hooks.types.type_for_mode
  				(targetm.unwind_word_mode (), 1),
  			      tmp);
*************** init_eh (void)
*** 245,261 ****
  
  #ifdef DONT_USE_BUILTIN_SETJMP
  #ifdef JMP_BUF_SIZE
!       tmp = build_int_cst (NULL_TREE, JMP_BUF_SIZE - 1);
  #else
        /* Should be large enough for most systems, if it is not,
  	 JMP_BUF_SIZE should be defined with the proper value.  It will
  	 also tend to be larger than necessary for most systems, a more
  	 optimal port will define JMP_BUF_SIZE.  */
!       tmp = build_int_cst (NULL_TREE, FIRST_PSEUDO_REGISTER + 2 - 1);
  #endif
  #else
        /* builtin_setjmp takes a pointer to 5 words.  */
!       tmp = build_int_cst (NULL_TREE, 5 * BITS_PER_WORD / POINTER_SIZE - 1);
  #endif
        tmp = build_index_type (tmp);
        tmp = build_array_type (ptr_type_node, tmp);
--- 245,261 ----
  
  #ifdef DONT_USE_BUILTIN_SETJMP
  #ifdef JMP_BUF_SIZE
!       tmp = size_int (JMP_BUF_SIZE - 1);
  #else
        /* Should be large enough for most systems, if it is not,
  	 JMP_BUF_SIZE should be defined with the proper value.  It will
  	 also tend to be larger than necessary for most systems, a more
  	 optimal port will define JMP_BUF_SIZE.  */
!       tmp = size_int (FIRST_PSEUDO_REGISTER + 2 - 1);
  #endif
  #else
        /* builtin_setjmp takes a pointer to 5 words.  */
!       tmp = size_int (5 * BITS_PER_WORD / POINTER_SIZE - 1);
  #endif
        tmp = build_index_type (tmp);
        tmp = build_array_type (ptr_type_node, tmp);
*************** assign_filter_values (void)
*** 857,863 ****
  		  for ( ; tp_node; tp_node = TREE_CHAIN (tp_node))
  		    {
  		      int flt = add_ttypes_entry (ttypes, TREE_VALUE (tp_node));
! 		      tree flt_node = build_int_cst (NULL_TREE, flt);
  
  		      c->filter_list
  			= tree_cons (NULL_TREE, flt_node, c->filter_list);
--- 857,863 ----
  		  for ( ; tp_node; tp_node = TREE_CHAIN (tp_node))
  		    {
  		      int flt = add_ttypes_entry (ttypes, TREE_VALUE (tp_node));
! 		      tree flt_node = build_int_cst (integer_type_node, flt);
  
  		      c->filter_list
  			= tree_cons (NULL_TREE, flt_node, c->filter_list);
*************** assign_filter_values (void)
*** 868,874 ****
  		  /* Get a filter value for the NULL list also since it
  		     will need an action record anyway.  */
  		  int flt = add_ttypes_entry (ttypes, NULL);
! 		  tree flt_node = build_int_cst (NULL_TREE, flt);
  
  		  c->filter_list
  		    = tree_cons (NULL_TREE, flt_node, NULL);
--- 868,874 ----
  		  /* Get a filter value for the NULL list also since it
  		     will need an action record anyway.  */
  		  int flt = add_ttypes_entry (ttypes, NULL);
! 		  tree flt_node = build_int_cst (integer_type_node, flt);
  
  		  c->filter_list
  		    = tree_cons (NULL_TREE, flt_node, NULL);
*************** sjlj_emit_dispatch_table (rtx dispatch_l
*** 1289,1295 ****
  
  	    t_label = create_artificial_label (UNKNOWN_LOCATION);
  	    case_elt = build3 (CASE_LABEL_EXPR, void_type_node,
! 			       build_int_cst (NULL, disp_index),
  			       NULL, t_label);
  	    gimple_switch_set_label (switch_stmt, disp_index, case_elt);
  
--- 1289,1295 ----
  
  	    t_label = create_artificial_label (UNKNOWN_LOCATION);
  	    case_elt = build3 (CASE_LABEL_EXPR, void_type_node,
! 			       build_int_cst (integer_type_node, disp_index),
  			       NULL, t_label);
  	    gimple_switch_set_label (switch_stmt, disp_index, case_elt);
  
Index: gcc/tree-cfg.c
===================================================================
*** gcc/tree-cfg.c	(revision 173155)
--- gcc/tree-cfg.c	(working copy)
*************** move_stmt_eh_region_tree_nr (tree old_t_
*** 5756,5762 ****
    old_nr = tree_low_cst (old_t_nr, 0);
    new_nr = move_stmt_eh_region_nr (old_nr, p);
  
!   return build_int_cst (NULL, new_nr);
  }
  
  /* Like move_stmt_op, but for gimple statements.
--- 5829,5835 ----
    old_nr = tree_low_cst (old_t_nr, 0);
    new_nr = move_stmt_eh_region_nr (old_nr, p);
  
!   return build_int_cst (integer_type_node, new_nr);
  }
  
  /* Like move_stmt_op, but for gimple statements.
Index: gcc/tree-vrp.c
===================================================================
*** gcc/tree-vrp.c	(revision 173155)
--- gcc/tree-vrp.c	(working copy)
*************** simplify_div_or_mod_using_ranges (gimple
*** 6909,6915 ****
  
        if (rhs_code == TRUNC_DIV_EXPR)
  	{
! 	  t = build_int_cst (NULL_TREE, tree_log2 (op1));
  	  gimple_assign_set_rhs_code (stmt, RSHIFT_EXPR);
  	  gimple_assign_set_rhs1 (stmt, op0);
  	  gimple_assign_set_rhs2 (stmt, t);
--- 6909,6915 ----
  
        if (rhs_code == TRUNC_DIV_EXPR)
  	{
! 	  t = build_int_cst (integer_type_node, tree_log2 (op1));
  	  gimple_assign_set_rhs_code (stmt, RSHIFT_EXPR);
  	  gimple_assign_set_rhs1 (stmt, op0);
  	  gimple_assign_set_rhs2 (stmt, t);



More information about the Gcc-patches mailing list