Patchwork use stdarg_p more

login
register
mail settings
Submitter Nathan Froyd
Date Aug. 9, 2010, 4 a.m.
Message ID <20100809040003.GH4130@codesourcery.com>
Download mbox | patch
Permalink /patch/61247/
State New
Headers show

Comments

Nathan Froyd - Aug. 9, 2010, 4 a.m.
The patch below converts several places that poke directly at the
internal representation of TYPE_ARG_TYPES to determine varargs-ness to
use stdarg_p instead.  The old LTO branch did this, but it didn't touch
all the backends.  I identified relevant backends by grep'ing for '[=!]=
void_type_node' and starting at the matches found.  I did the same thing
for *.[ch] in gcc/, but there weren't any other likely candidates other
than the places already identified.  It's possible that I missed some.

Tested on x86_64-unknown-linux-gnu and cross to
arm-eabi/powerpc-eabispe.  OK to commit?

-Nathan

	* builtins.c (fold_builtin_next_arg): Use stdarg_p.
	* config/arm/arm.c (arm_get_pcs_model): Likewise.
	* config/avr/avr.c (init_cumulative_args): Likewise.
	* config/iq2000/iq2000.c (iq2000_expand_prologue): Likewise.
	* config/lm32/lm32.c (lm32_setup_incoming_varargs): Likewise.
	* config/m68k/m68k.c (m68k_return_pops_args): Likewise.
	* config/mn10300/mn10300.c (mn10300_builtin_saveregs): Likewise.
	* config/pa/pa.c (hppa_builtin_saveregs): Likewise.
	* config/pa/som.h (ASM_DECLARE_FUNCTION_NAME): Likewise.
	* config/rs6000/rs6000.c (init_cumulative_args): Likewise.
	* dwarf2out.c (gen_subprogram_die): Likewise.
	* function.c (allocate_struct_function): Likewise.
	* c-aux-info.c (gen_formal_list_for_func_dec): Likewise.
	(deserves_ellipsis): Delete.
Richard Guenther - Aug. 9, 2010, 9:41 a.m.
On Mon, Aug 9, 2010 at 6:00 AM, Nathan Froyd <froydnj@codesourcery.com> wrote:
> The patch below converts several places that poke directly at the
> internal representation of TYPE_ARG_TYPES to determine varargs-ness to
> use stdarg_p instead.  The old LTO branch did this, but it didn't touch
> all the backends.  I identified relevant backends by grep'ing for '[=!]=
> void_type_node' and starting at the matches found.  I did the same thing
> for *.[ch] in gcc/, but there weren't any other likely candidates other
> than the places already identified.  It's possible that I missed some.
>
> Tested on x86_64-unknown-linux-gnu and cross to
> arm-eabi/powerpc-eabispe.  OK to commit?

Ok.

Thanks,
Richard.

> -Nathan
>
>        * builtins.c (fold_builtin_next_arg): Use stdarg_p.
>        * config/arm/arm.c (arm_get_pcs_model): Likewise.
>        * config/avr/avr.c (init_cumulative_args): Likewise.
>        * config/iq2000/iq2000.c (iq2000_expand_prologue): Likewise.
>        * config/lm32/lm32.c (lm32_setup_incoming_varargs): Likewise.
>        * config/m68k/m68k.c (m68k_return_pops_args): Likewise.
>        * config/mn10300/mn10300.c (mn10300_builtin_saveregs): Likewise.
>        * config/pa/pa.c (hppa_builtin_saveregs): Likewise.
>        * config/pa/som.h (ASM_DECLARE_FUNCTION_NAME): Likewise.
>        * config/rs6000/rs6000.c (init_cumulative_args): Likewise.
>        * dwarf2out.c (gen_subprogram_die): Likewise.
>        * function.c (allocate_struct_function): Likewise.
>        * c-aux-info.c (gen_formal_list_for_func_dec): Likewise.
>        (deserves_ellipsis): Delete.
>
> diff --git a/gcc/builtins.c b/gcc/builtins.c
> index 096fec6..3b9ca5a 100644
> --- a/gcc/builtins.c
> +++ b/gcc/builtins.c
> @@ -11526,9 +11526,7 @@ fold_builtin_next_arg (tree exp, bool va_start_p)
>   int nargs = call_expr_nargs (exp);
>   tree arg;
>
> -  if (TYPE_ARG_TYPES (fntype) == 0
> -      || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
> -         == void_type_node))
> +  if (!stdarg_p (fntype))
>     {
>       error ("%<va_start%> used in function with fixed args");
>       return true;
> diff --git a/gcc/c-aux-info.c b/gcc/c-aux-info.c
> index 28da8e0..8ec6a13 100644
> --- a/gcc/c-aux-info.c
> +++ b/gcc/c-aux-info.c
> @@ -42,7 +42,6 @@ static const char *data_type;
>
>  static char *affix_data_type (const char *) ATTRIBUTE_MALLOC;
>  static const char *gen_formal_list_for_type (tree, formals_style);
> -static int   deserves_ellipsis (tree);
>  static const char *gen_formal_list_for_func_def (tree, formals_style);
>  static const char *gen_type (const char *, tree, formals_style);
>  static const char *gen_decl (tree, int, formals_style);
> @@ -183,28 +182,6 @@ gen_formal_list_for_type (tree fntype, formals_style style)
>   return concat (" (", formal_list, ")", NULL);
>  }
>
> -/* For the generation of an ANSI prototype for a function definition, we have
> -   to look at the formal parameter list of the function's own "type" to
> -   determine if the function's formal parameter list should end with an
> -   ellipsis.  Given a tree node, the following function will return nonzero
> -   if the "function type" parameter list should end with an ellipsis.  */
> -
> -static int
> -deserves_ellipsis (tree fntype)
> -{
> -  tree formal_type;
> -
> -  formal_type = TYPE_ARG_TYPES (fntype);
> -  while (formal_type && TREE_VALUE (formal_type) != void_type_node)
> -    formal_type = TREE_CHAIN (formal_type);
> -
> -  /* If there were at least some parameters, and if the formals-types-list
> -     petered out to a NULL (i.e. without being terminated by a void_type_node)
> -     then we need to tack on an ellipsis.  */
> -
> -  return (!formal_type && TYPE_ARG_TYPES (fntype));
> -}
> -
>  /* Generate a parameter list for a function definition (in some given style).
>
>    Note that this routine has to be separate (and different) from the code that
> @@ -248,7 +225,7 @@ gen_formal_list_for_func_def (tree fndecl, formals_style style)
>     {
>       if (!DECL_ARGUMENTS (fndecl))
>        formal_list = concat (formal_list, "void", NULL);
> -      if (deserves_ellipsis (TREE_TYPE (fndecl)))
> +      if (stdarg_p (TREE_TYPE (fndecl)))
>        formal_list = concat (formal_list, ", ...", NULL);
>     }
>   if ((style == ansi) || (style == k_and_r_names))
> diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
> index a406c29..d0ea6e1 100644
> --- a/gcc/config/arm/arm.c
> +++ b/gcc/config/arm/arm.c
> @@ -3717,9 +3717,7 @@ arm_get_pcs_model (const_tree type, const_tree decl)
>       /* Detect varargs functions.  These always use the base rules
>         (no argument is ever a candidate for a co-processor
>         register).  */
> -      bool base_rules = (TYPE_ARG_TYPES (type) != 0
> -                        && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (type)))
> -                            != void_type_node));
> +      bool base_rules = stdarg_p (type);
>
>       if (user_convention)
>        {
> diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
> index 87393f2..e8d6fa3 100644
> --- a/gcc/config/avr/avr.c
> +++ b/gcc/config/avr/avr.c
> @@ -1530,14 +1530,8 @@ init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype, rtx libname,
>  {
>   cum->nregs = 18;
>   cum->regno = FIRST_CUM_REG;
> -  if (!libname && fntype)
> -    {
> -      int stdarg = (TYPE_ARG_TYPES (fntype) != 0
> -                    && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
> -                        != void_type_node));
> -      if (stdarg)
> -        cum->nregs = 0;
> -    }
> +  if (!libname && stdarg_p (fntype))
> +    cum->nregs = 0;
>  }
>
>  /* Returns the number of registers to allocate for a function argument.  */
> diff --git a/gcc/config/iq2000/iq2000.c b/gcc/config/iq2000/iq2000.c
> index 7164209..b152d1a 100644
> --- a/gcc/config/iq2000/iq2000.c
> +++ b/gcc/config/iq2000/iq2000.c
> @@ -1996,9 +1996,7 @@ iq2000_expand_prologue (void)
>   /* If this function is a varargs function, store any registers that
>      would normally hold arguments ($4 - $7) on the stack.  */
>   if (store_args_on_stack
> -      && ((TYPE_ARG_TYPES (fntype) != 0
> -          && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
> -              != void_type_node))
> +      && (stdarg_p (fntype)
>          || last_arg_is_vararg_marker))
>     {
>       int offset = (regno - GP_ARG_FIRST) * UNITS_PER_WORD;
> diff --git a/gcc/config/lm32/lm32.c b/gcc/config/lm32/lm32.c
> index 2bcbe67..e601693 100644
> --- a/gcc/config/lm32/lm32.c
> +++ b/gcc/config/lm32/lm32.c
> @@ -656,14 +656,10 @@ lm32_setup_incoming_varargs (CUMULATIVE_ARGS * cum, enum machine_mode mode,
>  {
>   int first_anon_arg;
>   tree fntype;
> -  int stdarg_p;
>
>   fntype = TREE_TYPE (current_function_decl);
> -  stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
> -             && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
> -                 != void_type_node));
>
> -  if (stdarg_p)
> +  if (stdarg_p (fntype))
>     first_anon_arg = *cum + LM32_FIRST_ARG_REG;
>   else
>     {
> diff --git a/gcc/config/m68k/m68k.c b/gcc/config/m68k/m68k.c
> index 566b8d2..d903246 100644
> --- a/gcc/config/m68k/m68k.c
> +++ b/gcc/config/m68k/m68k.c
> @@ -6540,9 +6540,7 @@ m68k_return_pops_args (tree fundecl, tree funtype, int size)
>   return ((TARGET_RTD
>           && (!fundecl
>               || TREE_CODE (fundecl) != IDENTIFIER_NODE)
> -          && (TYPE_ARG_TYPES (funtype) == 0
> -              || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (funtype)))
> -                  == void_type_node)))
> +          && (!stdarg_p (funtype)))
>          ? size : 0);
>  }
>
> diff --git a/gcc/config/mn10300/mn10300.c b/gcc/config/mn10300/mn10300.c
> index 1243a33..b55ca37 100644
> --- a/gcc/config/mn10300/mn10300.c
> +++ b/gcc/config/mn10300/mn10300.c
> @@ -1493,9 +1493,7 @@ mn10300_builtin_saveregs (void)
>  {
>   rtx offset, mem;
>   tree fntype = TREE_TYPE (current_function_decl);
> -  int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
> -                   && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
> -                       != void_type_node)))
> +  int argadj = ((!stdarg_p (fntype))
>                 ? UNITS_PER_WORD : 0);
>   alias_set_type set = get_varargs_alias_set ();
>
> diff --git a/gcc/config/pa/pa.c b/gcc/config/pa/pa.c
> index 96acecb..6593e53 100644
> --- a/gcc/config/pa/pa.c
> +++ b/gcc/config/pa/pa.c
> @@ -5944,9 +5944,7 @@ hppa_builtin_saveregs (void)
>  {
>   rtx offset, dest;
>   tree fntype = TREE_TYPE (current_function_decl);
> -  int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
> -                  && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
> -                      != void_type_node)))
> +  int argadj = ((!stdarg_p (fntype))
>                ? UNITS_PER_WORD : 0);
>
>   if (argadj)
> diff --git a/gcc/config/pa/som.h b/gcc/config/pa/som.h
> index 8be8def..53dddb7 100644
> --- a/gcc/config/pa/som.h
> +++ b/gcc/config/pa/som.h
> @@ -157,9 +157,7 @@ do {                                                                \
>                   }                                                    \
>               }                                                        \
>             /* anonymous args */                                       \
> -            if (TYPE_ARG_TYPES (tree_type) != 0                        \
> -                && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (tree_type)))\
> -                    != void_type_node))                                \
> +            if (stdarg_p (tree_type))                                  \
>               {                                                        \
>                 for (; i < 4; i++)                                     \
>                   fprintf (FILE, ",ARGW%d=GR", i);                     \
> diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
> index 0f1f040..a57c00d 100644
> --- a/gcc/config/rs6000/rs6000.c
> +++ b/gcc/config/rs6000/rs6000.c
> @@ -7369,10 +7369,7 @@ init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
>   cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
>                      ? CALL_LIBCALL : CALL_NORMAL);
>   cum->sysv_gregno = GP_ARG_MIN_REG;
> -  cum->stdarg = fntype
> -    && (TYPE_ARG_TYPES (fntype) != 0
> -       && (TREE_VALUE (tree_last  (TYPE_ARG_TYPES (fntype)))
> -           != void_type_node));
> +  cum->stdarg = stdarg_p (fntype);
>
>   cum->nargs_prototype = 0;
>   if (incoming || cum->prototype)
> diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
> index 5441448..af5a82f 100644
> --- a/gcc/cp/tree.c
> +++ b/gcc/cp/tree.c
> @@ -2284,11 +2284,7 @@ error_type (tree arg)
>  int
>  varargs_function_p (const_tree function)
>  {
> -  const_tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
> -  for (; parm; parm = TREE_CHAIN (parm))
> -    if (TREE_VALUE (parm) == void_type_node)
> -      return 0;
> -  return 1;
> +  return stdarg_p (TREE_TYPE (function));
>  }
>
>  /* Returns 1 if decl is a member of a class.  */
> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
> index 8e6f94f..0f3bea8 100644
> --- a/gcc/dwarf2out.c
> +++ b/gcc/dwarf2out.c
> @@ -18927,7 +18927,7 @@ gen_subprogram_die (tree decl, dw_die_ref context_die)
>       if (fn_arg_types != NULL)
>        {
>          /* This is the prototyped case, check for....  */
> -         if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
> +         if (stdarg_p (TREE_TYPE (decl)))
>            gen_unspecified_parameters_die (decl, subr_die);
>        }
>       else if (DECL_INITIAL (decl) == NULL_TREE)
> diff --git a/gcc/function.c b/gcc/function.c
> index e89a5c9..6ee8b78 100644
> --- a/gcc/function.c
> +++ b/gcc/function.c
> @@ -4295,11 +4295,7 @@ allocate_struct_function (tree fndecl, bool abstract_p)
>          cfun->returns_struct = 1;
>        }
>
> -      cfun->stdarg
> -       = (fntype
> -          && TYPE_ARG_TYPES (fntype) != 0
> -          && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
> -              != void_type_node));
> +      cfun->stdarg = stdarg_p (fntype);
>
>       /* Assume all registers in stdarg functions need to be saved.  */
>       cfun->va_list_gpr_size = VA_LIST_MAX_GPR_SIZE;
>

Patch

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 096fec6..3b9ca5a 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -11526,9 +11526,7 @@  fold_builtin_next_arg (tree exp, bool va_start_p)
   int nargs = call_expr_nargs (exp);
   tree arg;
 
-  if (TYPE_ARG_TYPES (fntype) == 0
-      || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
-	  == void_type_node))
+  if (!stdarg_p (fntype))
     {
       error ("%<va_start%> used in function with fixed args");
       return true;
diff --git a/gcc/c-aux-info.c b/gcc/c-aux-info.c
index 28da8e0..8ec6a13 100644
--- a/gcc/c-aux-info.c
+++ b/gcc/c-aux-info.c
@@ -42,7 +42,6 @@  static const char *data_type;
 
 static char *affix_data_type (const char *) ATTRIBUTE_MALLOC;
 static const char *gen_formal_list_for_type (tree, formals_style);
-static int   deserves_ellipsis (tree);
 static const char *gen_formal_list_for_func_def (tree, formals_style);
 static const char *gen_type (const char *, tree, formals_style);
 static const char *gen_decl (tree, int, formals_style);
@@ -183,28 +182,6 @@  gen_formal_list_for_type (tree fntype, formals_style style)
   return concat (" (", formal_list, ")", NULL);
 }
 
-/* For the generation of an ANSI prototype for a function definition, we have
-   to look at the formal parameter list of the function's own "type" to
-   determine if the function's formal parameter list should end with an
-   ellipsis.  Given a tree node, the following function will return nonzero
-   if the "function type" parameter list should end with an ellipsis.  */
-
-static int
-deserves_ellipsis (tree fntype)
-{
-  tree formal_type;
-
-  formal_type = TYPE_ARG_TYPES (fntype);
-  while (formal_type && TREE_VALUE (formal_type) != void_type_node)
-    formal_type = TREE_CHAIN (formal_type);
-
-  /* If there were at least some parameters, and if the formals-types-list
-     petered out to a NULL (i.e. without being terminated by a void_type_node)
-     then we need to tack on an ellipsis.  */
-
-  return (!formal_type && TYPE_ARG_TYPES (fntype));
-}
-
 /* Generate a parameter list for a function definition (in some given style).
 
    Note that this routine has to be separate (and different) from the code that
@@ -248,7 +225,7 @@  gen_formal_list_for_func_def (tree fndecl, formals_style style)
     {
       if (!DECL_ARGUMENTS (fndecl))
 	formal_list = concat (formal_list, "void", NULL);
-      if (deserves_ellipsis (TREE_TYPE (fndecl)))
+      if (stdarg_p (TREE_TYPE (fndecl)))
 	formal_list = concat (formal_list, ", ...", NULL);
     }
   if ((style == ansi) || (style == k_and_r_names))
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index a406c29..d0ea6e1 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -3717,9 +3717,7 @@  arm_get_pcs_model (const_tree type, const_tree decl)
       /* Detect varargs functions.  These always use the base rules
 	 (no argument is ever a candidate for a co-processor
 	 register).  */
-      bool base_rules = (TYPE_ARG_TYPES (type) != 0
-			 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (type)))
-			     != void_type_node));
+      bool base_rules = stdarg_p (type);
       
       if (user_convention)
 	{
diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
index 87393f2..e8d6fa3 100644
--- a/gcc/config/avr/avr.c
+++ b/gcc/config/avr/avr.c
@@ -1530,14 +1530,8 @@  init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype, rtx libname,
 {
   cum->nregs = 18;
   cum->regno = FIRST_CUM_REG;
-  if (!libname && fntype)
-    {
-      int stdarg = (TYPE_ARG_TYPES (fntype) != 0
-                    && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
-                        != void_type_node));
-      if (stdarg)
-        cum->nregs = 0;
-    }
+  if (!libname && stdarg_p (fntype))
+    cum->nregs = 0;
 }
 
 /* Returns the number of registers to allocate for a function argument.  */
diff --git a/gcc/config/iq2000/iq2000.c b/gcc/config/iq2000/iq2000.c
index 7164209..b152d1a 100644
--- a/gcc/config/iq2000/iq2000.c
+++ b/gcc/config/iq2000/iq2000.c
@@ -1996,9 +1996,7 @@  iq2000_expand_prologue (void)
   /* If this function is a varargs function, store any registers that
      would normally hold arguments ($4 - $7) on the stack.  */
   if (store_args_on_stack
-      && ((TYPE_ARG_TYPES (fntype) != 0
-	   && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
-	       != void_type_node))
+      && (stdarg_p (fntype)
 	  || last_arg_is_vararg_marker))
     {
       int offset = (regno - GP_ARG_FIRST) * UNITS_PER_WORD;
diff --git a/gcc/config/lm32/lm32.c b/gcc/config/lm32/lm32.c
index 2bcbe67..e601693 100644
--- a/gcc/config/lm32/lm32.c
+++ b/gcc/config/lm32/lm32.c
@@ -656,14 +656,10 @@  lm32_setup_incoming_varargs (CUMULATIVE_ARGS * cum, enum machine_mode mode,
 {
   int first_anon_arg;
   tree fntype;
-  int stdarg_p;
 
   fntype = TREE_TYPE (current_function_decl);
-  stdarg_p = (TYPE_ARG_TYPES (fntype) != 0
-	      && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
-		  != void_type_node));
 
-  if (stdarg_p)
+  if (stdarg_p (fntype))
     first_anon_arg = *cum + LM32_FIRST_ARG_REG;
   else
     {
diff --git a/gcc/config/m68k/m68k.c b/gcc/config/m68k/m68k.c
index 566b8d2..d903246 100644
--- a/gcc/config/m68k/m68k.c
+++ b/gcc/config/m68k/m68k.c
@@ -6540,9 +6540,7 @@  m68k_return_pops_args (tree fundecl, tree funtype, int size)
   return ((TARGET_RTD
 	   && (!fundecl
 	       || TREE_CODE (fundecl) != IDENTIFIER_NODE)
-	   && (TYPE_ARG_TYPES (funtype) == 0
-	       || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (funtype)))
-		   == void_type_node)))
+	   && (!stdarg_p (funtype)))
 	  ? size : 0);
 }
 
diff --git a/gcc/config/mn10300/mn10300.c b/gcc/config/mn10300/mn10300.c
index 1243a33..b55ca37 100644
--- a/gcc/config/mn10300/mn10300.c
+++ b/gcc/config/mn10300/mn10300.c
@@ -1493,9 +1493,7 @@  mn10300_builtin_saveregs (void)
 {
   rtx offset, mem;
   tree fntype = TREE_TYPE (current_function_decl);
-  int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
-                   && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
-                       != void_type_node)))
+  int argadj = ((!stdarg_p (fntype))
                 ? UNITS_PER_WORD : 0);
   alias_set_type set = get_varargs_alias_set ();
 
diff --git a/gcc/config/pa/pa.c b/gcc/config/pa/pa.c
index 96acecb..6593e53 100644
--- a/gcc/config/pa/pa.c
+++ b/gcc/config/pa/pa.c
@@ -5944,9 +5944,7 @@  hppa_builtin_saveregs (void)
 {
   rtx offset, dest;
   tree fntype = TREE_TYPE (current_function_decl);
-  int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
-		   && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
-		       != void_type_node)))
+  int argadj = ((!stdarg_p (fntype))
 		? UNITS_PER_WORD : 0);
 
   if (argadj)
diff --git a/gcc/config/pa/som.h b/gcc/config/pa/som.h
index 8be8def..53dddb7 100644
--- a/gcc/config/pa/som.h
+++ b/gcc/config/pa/som.h
@@ -157,9 +157,7 @@  do {								\
 		   }							\
 	       }							\
 	     /* anonymous args */					\
-	     if (TYPE_ARG_TYPES (tree_type) != 0			\
-		 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (tree_type)))\
-		     != void_type_node))				\
+	     if (stdarg_p (tree_type))					\
 	       {							\
 		 for (; i < 4; i++)					\
 		   fprintf (FILE, ",ARGW%d=GR", i);			\
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 0f1f040..a57c00d 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -7369,10 +7369,7 @@  init_cumulative_args (CUMULATIVE_ARGS *cum, tree fntype,
   cum->call_cookie = ((DEFAULT_ABI == ABI_V4 && libcall)
 		      ? CALL_LIBCALL : CALL_NORMAL);
   cum->sysv_gregno = GP_ARG_MIN_REG;
-  cum->stdarg = fntype
-    && (TYPE_ARG_TYPES (fntype) != 0
-	&& (TREE_VALUE (tree_last  (TYPE_ARG_TYPES (fntype)))
-	    != void_type_node));
+  cum->stdarg = stdarg_p (fntype);
 
   cum->nargs_prototype = 0;
   if (incoming || cum->prototype)
diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 5441448..af5a82f 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2284,11 +2284,7 @@  error_type (tree arg)
 int
 varargs_function_p (const_tree function)
 {
-  const_tree parm = TYPE_ARG_TYPES (TREE_TYPE (function));
-  for (; parm; parm = TREE_CHAIN (parm))
-    if (TREE_VALUE (parm) == void_type_node)
-      return 0;
-  return 1;
+  return stdarg_p (TREE_TYPE (function));
 }
 
 /* Returns 1 if decl is a member of a class.  */
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 8e6f94f..0f3bea8 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -18927,7 +18927,7 @@  gen_subprogram_die (tree decl, dw_die_ref context_die)
       if (fn_arg_types != NULL)
 	{
 	  /* This is the prototyped case, check for....  */
-	  if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node)
+	  if (stdarg_p (TREE_TYPE (decl)))
 	    gen_unspecified_parameters_die (decl, subr_die);
 	}
       else if (DECL_INITIAL (decl) == NULL_TREE)
diff --git a/gcc/function.c b/gcc/function.c
index e89a5c9..6ee8b78 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -4295,11 +4295,7 @@  allocate_struct_function (tree fndecl, bool abstract_p)
 	  cfun->returns_struct = 1;
 	}
 
-      cfun->stdarg
-	= (fntype
-	   && TYPE_ARG_TYPES (fntype) != 0
-	   && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
-	       != void_type_node));
+      cfun->stdarg = stdarg_p (fntype);
 
       /* Assume all registers in stdarg functions need to be saved.  */
       cfun->va_list_gpr_size = VA_LIST_MAX_GPR_SIZE;