aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimplify.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@gcc.gnu.org>2007-09-05 22:45:27 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2007-09-05 22:45:27 +0200
commit6ef5231bdf52aba0854491d24ab30bebd8f2ab0a (patch)
tree0065cd65b39b8419a3be598915506370819405f7 /gcc/gimplify.c
parente050d7958c2fc910926d046fe1e72a513a580489 (diff)
downloadgcc-6ef5231bdf52aba0854491d24ab30bebd8f2ab0a.zip
gcc-6ef5231bdf52aba0854491d24ab30bebd8f2ab0a.tar.gz
gcc-6ef5231bdf52aba0854491d24ab30bebd8f2ab0a.tar.bz2
builtins.def (BUILT_IN_VA_ARG_PACK): New built-in.
* 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. From-SVN: r128150
Diffstat (limited to 'gcc/gimplify.c')
-rw-r--r--gcc/gimplify.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 5c376ac..ee8ef09 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -2170,8 +2170,50 @@ gimplify_call_expr (tree *expr_p, tree *pre_p, bool want_value)
}
}
}
- else if (nargs != 0)
- CALL_CANNOT_INLINE_P (*expr_p) = 1;
+ else
+ {
+ if (nargs != 0)
+ CALL_CANNOT_INLINE_P (*expr_p) = 1;
+ i = 0;
+ p = NULL_TREE;
+ }
+
+ /* If the last argument is __builtin_va_arg_pack () and it is not
+ passed as a named argument, decrease the number of CALL_EXPR
+ arguments and set instead the CALL_EXPR_VA_ARG_PACK flag. */
+ if (!p
+ && i < nargs
+ && TREE_CODE (CALL_EXPR_ARG (*expr_p, nargs - 1)) == CALL_EXPR)
+ {
+ tree last_arg = CALL_EXPR_ARG (*expr_p, nargs - 1);
+ tree last_arg_fndecl = get_callee_fndecl (last_arg);
+
+ if (last_arg_fndecl
+ && TREE_CODE (last_arg_fndecl) == FUNCTION_DECL
+ && DECL_BUILT_IN_CLASS (last_arg_fndecl) == BUILT_IN_NORMAL
+ && DECL_FUNCTION_CODE (last_arg_fndecl) == BUILT_IN_VA_ARG_PACK)
+ {
+ tree call = *expr_p;
+
+ --nargs;
+ *expr_p = build_call_array (TREE_TYPE (call), CALL_EXPR_FN (call),
+ nargs, CALL_EXPR_ARGP (call));
+ /* Copy all CALL_EXPR flags, locus and block, except
+ CALL_EXPR_VA_ARG_PACK flag. */
+ CALL_EXPR_STATIC_CHAIN (*expr_p) = CALL_EXPR_STATIC_CHAIN (call);
+ CALL_EXPR_TAILCALL (*expr_p) = CALL_EXPR_TAILCALL (call);
+ CALL_EXPR_RETURN_SLOT_OPT (*expr_p)
+ = CALL_EXPR_RETURN_SLOT_OPT (call);
+ CALL_FROM_THUNK_P (*expr_p) = CALL_FROM_THUNK_P (call);
+ CALL_CANNOT_INLINE_P (*expr_p)
+ = CALL_CANNOT_INLINE_P (call);
+ TREE_NOTHROW (*expr_p) = TREE_NOTHROW (call);
+ SET_EXPR_LOCUS (*expr_p, EXPR_LOCUS (call));
+ TREE_BLOCK (*expr_p) = TREE_BLOCK (call);
+ /* Set CALL_EXPR_VA_ARG_PACK. */
+ CALL_EXPR_VA_ARG_PACK (*expr_p) = 1;
+ }
+ }
/* Finally, gimplify the function arguments. */
for (i = (PUSH_ARGS_REVERSED ? nargs - 1 : 0);