This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] PATCH to fix va_start warning
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 21 May 2003 11:30:14 -0400
- Subject: [tree-ssa] PATCH to fix va_start warning
This patch causes simplify_builtin to strip any NOPs and whatnot from the
second argument to va_start, so that subsequent gimplification doesn't
replace it with a temporary. This fixes more of the spurious bootstrap
warnings.
I also simplified simplify_call_expr; if the expression changes,
simplify_expr will re-gimplify it anyway, so we can just return
immediately.
Booted and tested i686-pc-linux-gnu, applied tree-ssa.
2003-05-21 Jason Merrill <jason@redhat.com>
* builtins.c (simplify_builtin_next_arg): Split out from...
(expand_builtin_next_arg): ...here.
(simplify_builtin_va_start): Split out from...
(expand_builtin_va_start): ...here.
(simplify_builtin): Call it.
* gimplify.c (simplify_call_expr): If simplify_builtin worked,
just return.
*** builtins.c.~1~ 2003-05-20 16:47:04.000000000 -0400
--- builtins.c 2003-05-20 18:06:39.000000000 -0400
*************** static rtx expand_builtin_mathfn PARAMS
*** 104,111 ****
static rtx expand_builtin_mathfn_2 PARAMS ((tree, rtx, rtx));
static rtx expand_builtin_constant_p PARAMS ((tree, enum machine_mode));
static rtx expand_builtin_args_info PARAMS ((tree));
! static rtx expand_builtin_next_arg PARAMS ((tree));
static rtx expand_builtin_va_start PARAMS ((tree));
static rtx expand_builtin_va_end PARAMS ((tree));
static rtx expand_builtin_va_copy PARAMS ((tree));
static rtx expand_builtin_memcmp PARAMS ((tree, tree, rtx,
--- 104,113 ----
static rtx expand_builtin_mathfn_2 PARAMS ((tree, rtx, rtx));
static rtx expand_builtin_constant_p PARAMS ((tree, enum machine_mode));
static rtx expand_builtin_args_info PARAMS ((tree));
! static rtx expand_builtin_next_arg PARAMS ((void));
! static void simplify_builtin_next_arg PARAMS ((tree));
static rtx expand_builtin_va_start PARAMS ((tree));
+ static void simplify_builtin_va_start PARAMS ((tree));
static rtx expand_builtin_va_end PARAMS ((tree));
static rtx expand_builtin_va_copy PARAMS ((tree));
static rtx expand_builtin_memcmp PARAMS ((tree, tree, rtx,
*************** expand_builtin_args_info (arglist)
*** 2782,2802 ****
/* Expand ARGLIST, from a call to __builtin_next_arg. */
! static rtx
! expand_builtin_next_arg (arglist)
! tree arglist;
{
tree fntype = TREE_TYPE (current_function_decl);
if (TYPE_ARG_TYPES (fntype) == 0
|| (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
== void_type_node))
! {
! error ("`va_start' used in function with fixed args");
! return const0_rtx;
! }
!
! if (arglist)
{
tree last_parm = tree_last (DECL_ARGUMENTS (current_function_decl));
tree arg = TREE_VALUE (arglist);
--- 2784,2799 ----
/* Expand ARGLIST, from a call to __builtin_next_arg. */
! static void
! simplify_builtin_next_arg (tree arglist)
{
tree fntype = TREE_TYPE (current_function_decl);
if (TYPE_ARG_TYPES (fntype) == 0
|| (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
== void_type_node))
! error ("`va_start' used in function with fixed args");
! else if (arglist)
{
tree last_parm = tree_last (DECL_ARGUMENTS (current_function_decl));
tree arg = TREE_VALUE (arglist);
*************** expand_builtin_next_arg (arglist)
*** 2812,2823 ****
--- 2809,2825 ----
arg = TREE_OPERAND (arg, 0);
if (arg != last_parm)
warning ("second parameter of `va_start' not last named argument");
+ TREE_VALUE (arglist) = arg;
}
else
/* Evidently an out of date version of <stdarg.h>; can't validate
va_start's second argument, but can still work as intended. */
warning ("`__builtin_next_arg' called without an argument");
+ }
+ static rtx
+ expand_builtin_next_arg ()
+ {
return expand_binop (Pmode, add_optab,
current_function_internal_arg_pointer,
current_function_arg_offset_rtx,
*************** std_expand_builtin_va_start (valist, nex
*** 2892,2910 ****
/* Expand ARGLIST, from a call to __builtin_va_start. */
static rtx
expand_builtin_va_start (arglist)
tree arglist;
{
rtx nextarg;
! tree chain, valist;
! chain = TREE_CHAIN (arglist);
!
! if (TREE_CHAIN (chain))
! error ("too many arguments to function `va_start'");
!
! nextarg = expand_builtin_next_arg (chain);
valist = stabilize_va_list (TREE_VALUE (arglist), 1);
#ifdef EXPAND_BUILTIN_VA_START
--- 2894,2919 ----
/* Expand ARGLIST, from a call to __builtin_va_start. */
+ static void
+ simplify_builtin_va_start (tree arglist)
+ {
+ tree chain = TREE_CHAIN (arglist);
+
+ if (TREE_CHAIN (chain))
+ error ("too many arguments to function `va_start'");
+
+ simplify_builtin_next_arg (chain);
+ }
+
static rtx
expand_builtin_va_start (arglist)
tree arglist;
{
rtx nextarg;
! tree valist;
! simplify_builtin_va_start (arglist);
! nextarg = expand_builtin_next_arg ();
valist = stabilize_va_list (TREE_VALUE (arglist), 1);
#ifdef EXPAND_BUILTIN_VA_START
*************** expand_builtin (exp, target, subtarget,
*** 3710,3716 ****
/* Return the address of the first anonymous stack arg. */
case BUILT_IN_NEXT_ARG:
! return expand_builtin_next_arg (arglist);
case BUILT_IN_CLASSIFY_TYPE:
return expand_builtin_classify_type (arglist);
--- 3719,3726 ----
/* Return the address of the first anonymous stack arg. */
case BUILT_IN_NEXT_ARG:
! simplify_builtin_next_arg (arglist);
! return expand_builtin_next_arg ();
case BUILT_IN_CLASSIFY_TYPE:
return expand_builtin_classify_type (arglist);
*************** simplify_builtin (exp, ignore)
*** 4693,4698 ****
--- 4703,4711 ----
case BUILT_IN_BCMP:
case BUILT_IN_MEMCMP:
return simplify_builtin_memcmp (arglist);
+ case BUILT_IN_VA_START:
+ simplify_builtin_va_start (arglist);
+ return NULL_TREE;
default:
return NULL_TREE;
}
*** gimplify.c.~1~ 2003-05-20 16:47:04.000000000 -0400
--- gimplify.c 2003-05-20 18:21:19.000000000 -0400
*************** simplify_call_expr (expr_p, pre_p, post_
*** 1366,1372 ****
/* This may be a call to a builtin function.
! Builtin funtion calls may be transformed into different
(and more efficient) builtin function calls under certain
circumstances. Unfortunately, gimplification can muck things
up enough that the builtin expanders are not aware that certain
--- 1366,1372 ----
/* This may be a call to a builtin function.
! Builtin function calls may be transformed into different
(and more efficient) builtin function calls under certain
circumstances. Unfortunately, gimplification can muck things
up enough that the builtin expanders are not aware that certain
*************** simplify_call_expr (expr_p, pre_p, post_
*** 1381,1416 ****
{
tree new = simplify_builtin (*expr_p, simple_test_f == is_simple_stmt);
! if (new)
! {
/* There was a transformation of this call which computes the
! same value, but in a more efficient way.
!
! There may be arguments to the original function call which
! must be evaluated to catch their side effects. They will
! appear on the LHS of any COMPOUND_EXPRs from simplify_builtin. */
! while (TREE_CODE (new) == COMPOUND_EXPR)
! {
! /* Expand an argument and add it to the pre-queue. */
! simplify_expr (&TREE_OPERAND (new, 0), pre_p, post_p,
! is_simple_rhs, fb_rvalue);
! add_tree (TREE_OPERAND (new, 0), pre_p);
! new = TREE_OPERAND (new, 1);
! }
!
! /* NEW now contains the transformed builtin call. It may be
! another call or an arbitrary expression. If it was not
! a call, then we do a recursive simplification on the
! expression as a whole. */
! if (new && TREE_CODE (new) != CALL_EXPR)
! {
! simplify_expr (&new, pre_p, post_p, is_simple_rhs, fb_rvalue);
! *expr_p = new;
! return;
! }
!
! /* NEW is another CALL_EXPR. Fall through. */
! *expr_p = new;
}
}
--- 1381,1393 ----
{
tree new = simplify_builtin (*expr_p, simple_test_f == is_simple_stmt);
! if (new && new != *expr_p)
! {
/* There was a transformation of this call which computes the
! same value, but in a more efficient way. Return and try
! again. */
! *expr_p = new;
! return;
}
}