[RFC PATCH] __builtin_va_arg_pack ()

Ian Lance Taylor iant@google.com
Wed Sep 5 17:41:00 GMT 2007


Jakub Jelinek <jakub@redhat.com> writes:

> 2007-08-31  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* builtins.def (BUILT_IN_VA_ARG_PACK): New built-in.
> 	* tree.h (CALL_EXPR_VA_ARG_PACK): Define.
> 	* tree-inline.h (copy_body_data): Add call_expr field.
> 	* tree-inline.c (expand_call_inline): Initialize call_expr.
> 	(copy_bb): Append anonymous inline fn arguments to arguments
> 	when inlining a CALL_EXPR_VA_ARG_PACK call.
> 	* builtins.c (expand_builtin): Issue an error if
> 	BUILT_IN_VA_ARG_PACK is seen during expand.
> 	(fold_call_expr, fold_builtin_call_array): Don't fold
> 	CALL_EXPR_VA_ARG_PACK CALL_EXPRs or calls with
> 	__builtin_va_arg_pack () call as last argument.
> 	* gimplify.c (gimplify_call_expr): If last argument to a vararg
> 	function is __builtin_va_arg_pack (), decrease number of call
> 	arguments and instead set CALL_EXPR_VA_ARG_PACK on the CALL_EXPR.
> 	* expr.c (expand_expr_real_1): Issue an error if
> 	CALL_EXPR_VA_ARG_PACK CALL_EXPR is seen during expand.
> 	* tree-pretty-print.c (dump_generic_node): Handle printing
> 	CALL_EXPR_VA_ARG_PACK bit on CALL_EXPRs.
> 	* doc/extend.texi (__builtin_va_arg_pack): Document.
> 
> 	* gcc.c-torture/execute/va-arg-pack-1.c: New test.
> 	* gcc.dg/va-arg-pack-1.c: New test.


> +  /* CALL_EXPR if va arg parameter packs should be expanded or NULL
> +     ig not.  */

Typo: "ig" -> "is".

> +	{
> +	  CALL_EXPR_ARG (*expr_p, nargs - 1) = NULL_TREE;
> +	  VL_EXP_CHECK (*expr_p)->exp.operands[0]
> +	    = build_int_cst (sizetype, VL_EXP_OPERAND_LENGTH (*expr_p) - 1);
> +	  CALL_EXPR_VA_ARG_PACK (*expr_p) = 1;
> +	  --nargs;
> +	}

Wow, that's, well, ugly.  One approach would be

    --nargs;
    *expr_p = build_call_array (TREE_TYPE (*expr_p), CALL_EXPR_FN (*expr_p),
                                nargs, CALL_EXPR_ARGP (*expr_p));
    CALL_EXPR_VA_ARG_PACK (*expr_p) = 1;n

although then you would have to copy all the flags again.

Alternatively, add a macro or function which adjust the number of
operands in a vl_exp.  I don't think we should have this lingering
reference to exp.operands--note that otherwise exp.operands appears
only in tree.h and tree.c.

Patch is OK with a change along these lines.

Thanks.

Ian



More information about the Gcc-patches mailing list