summaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4>2008-07-06 14:51:58 +0000
committerktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4>2008-07-06 14:51:58 +0000
commit5f57a8b18d88161a5674ef7f36a6b24ae73a6cdf (patch)
tree62ff1d086ba0f6eecd1677d770c67586ca43fdd0 /gcc/builtins.c
parent3e3353969850d98ff5b0e4aeeb2d1e9e83a84ccd (diff)
downloadgcc-5f57a8b18d88161a5674ef7f36a6b24ae73a6cdf.tar.gz
2008-07-06 Kai Tietz <kai.tietz@onevision.com>
* config.gcc (extra_headers): Add cross-stdarg.h for target x86_64-*-* and i?86-*-*. * config/i386/cross-stdarg.h: New. * builtins.c (std_fn_abi_va_list): New. (std_canonical_va_list_type): New. (stabilize_va_list): Replace va_list_type_node use by mtarget.canonical_va_list_type. (gimplify_va_arg_expr): Likewise. (expand_builtin_va_copy): Replace va_list_type_node use by mtarget.fn_abi_va_list. * tree-sra.c (is_va_list_type): New helper. (decl_can_be_decomposed_p): Replace va_list_type_node use by is_va_list_type. * tree-ssa-ccp.c (optimize_stdarg_builtin): Likewise. * tree-stdarg.c (execute_optimize_stdarg): Likewise. * c-common.c (c_common_nodes_and_builtins): Use TARGET_ENUM_VA_LIST. * config/i386/i386-protos.h (ix86_get_valist_type): New. (ix86_enum_va_list): New. * config/i386/i386.c (sysv_va_list_type_node): New. (ms_va_list_type_node): New. (ix86_function_type_abi): Remove sorry. (ix86_build_builtin_va_list_abi): New. (ix86_build_builtin_va_list): Call ix86_build_builtin_va_list_abi for 64-bit targets. (ix86_va_start): Replace va_list_type_node by sysv_va_list_type_node. (ix86_init_builtins_va_builtins_abi): New. (ix86_init_builtins): Use ix86_init_builtins_va_builtins_abi for 64-bit targets. (ix86_handle_abi_attribute): New. (attribute_spec): Add sysv_abi and ms_abi. (ix86_fn_abi_va_list): New. (ix86_canonical_va_list_type): New. (ix86_enum_va_list): New. (TARGET_FN_ABI_VA_LIST): New. (TARGET_CANONICAL_VA_LIST_TYPE): New. * config/i386/i386.h (TARGET_ENUM_VA_LIST): New. * doc/tm.texi (TARGET_FN_ABI_VA_LIST): New. (TARGET_CANONICAL_VA_LIST_TYPE): New. (TARGET_ENUM_VA_LIST): New. * expr.h (std_fn_abi_va_list): New. (std_canonical_va_list_type): New. * target-def.h (TARGET_FN_ABI_VA_LIST): New. (TARGET_CANONICAL_VA_LIST_TYPE): New. (TARGET_INITIALIZER): Add TARGET_FN_ABI_VA_LIST and TARGET_CANONICAL_VA_LIST_TYPE. * target.h (struct gcc_target): Add fn_abi_va_list hook and canonical_va_list_type hook. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@137525 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c100
1 files changed, 66 insertions, 34 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 731955b5699..2d6ad2a1a34 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -4623,18 +4623,22 @@ expand_builtin_next_arg (void)
static tree
stabilize_va_list (tree valist, int needs_lvalue)
{
- if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
+ tree vatype = targetm.canonical_va_list_type (TREE_TYPE (valist));
+
+ gcc_assert (vatype != NULL_TREE);
+
+ if (TREE_CODE (vatype) == ARRAY_TYPE)
{
if (TREE_SIDE_EFFECTS (valist))
valist = save_expr (valist);
/* For this case, the backends will be expecting a pointer to
- TREE_TYPE (va_list_type_node), but it's possible we've
- actually been given an array (an actual va_list_type_node).
+ vatype, but it's possible we've actually been given an array
+ (an actual TARGET_CANONICAL_VA_LIST_TYPE (valist)).
So fix it. */
if (TREE_CODE (TREE_TYPE (valist)) == ARRAY_TYPE)
{
- tree p1 = build_pointer_type (TREE_TYPE (va_list_type_node));
+ tree p1 = build_pointer_type (TREE_TYPE (vatype));
valist = build_fold_addr_expr_with_type (valist, p1);
}
}
@@ -4647,7 +4651,7 @@ stabilize_va_list (tree valist, int needs_lvalue)
if (! TREE_SIDE_EFFECTS (valist))
return valist;
- pt = build_pointer_type (va_list_type_node);
+ pt = build_pointer_type (vatype);
valist = fold_build1 (ADDR_EXPR, pt, valist);
TREE_SIDE_EFFECTS (valist) = 1;
}
@@ -4668,6 +4672,47 @@ std_build_builtin_va_list (void)
return ptr_type_node;
}
+/* The "standard" abi va_list is va_list_type_node. */
+
+tree
+std_fn_abi_va_list (tree fndecl ATTRIBUTE_UNUSED)
+{
+ return va_list_type_node;
+}
+
+/* The "standard" type of va_list is va_list_type_node. */
+
+tree
+std_canonical_va_list_type (tree type)
+{
+ tree wtype, htype;
+
+ if (INDIRECT_REF_P (type))
+ type = TREE_TYPE (type);
+ else if (POINTER_TYPE_P (type) && POINTER_TYPE_P (TREE_TYPE(type)))
+ type = TREE_TYPE (type);
+
+ wtype = va_list_type_node;
+ htype = type;
+ if (TREE_CODE (wtype) == ARRAY_TYPE)
+ {
+ /* If va_list is an array type, the argument may have decayed
+ to a pointer type, e.g. by being passed to another function.
+ In that case, unwrap both types so that we can compare the
+ underlying records. */
+ if (TREE_CODE (htype) == ARRAY_TYPE
+ || POINTER_TYPE_P (htype))
+ {
+ wtype = TREE_TYPE (wtype);
+ htype = TREE_TYPE (htype);
+ }
+ }
+ if (TYPE_MAIN_VARIANT (wtype) == TYPE_MAIN_VARIANT (htype))
+ return va_list_type_node;
+
+ return NULL_TREE;
+}
+
/* The "standard" implementation of va_start: just assign `nextarg' to
the variable. */
@@ -4823,33 +4868,18 @@ dummy_object (tree type)
enum gimplify_status
gimplify_va_arg_expr (tree *expr_p, tree *pre_p, tree *post_p)
{
- tree promoted_type, want_va_type, have_va_type;
+ tree promoted_type, have_va_type;
tree valist = TREE_OPERAND (*expr_p, 0);
tree type = TREE_TYPE (*expr_p);
tree t;
/* Verify that valist is of the proper type. */
- want_va_type = va_list_type_node;
have_va_type = TREE_TYPE (valist);
-
if (have_va_type == error_mark_node)
return GS_ERROR;
+ have_va_type = targetm.canonical_va_list_type (have_va_type);
- if (TREE_CODE (want_va_type) == ARRAY_TYPE)
- {
- /* If va_list is an array type, the argument may have decayed
- to a pointer type, e.g. by being passed to another function.
- In that case, unwrap both types so that we can compare the
- underlying records. */
- if (TREE_CODE (have_va_type) == ARRAY_TYPE
- || POINTER_TYPE_P (have_va_type))
- {
- want_va_type = TREE_TYPE (want_va_type);
- have_va_type = TREE_TYPE (have_va_type);
- }
- }
-
- if (TYPE_MAIN_VARIANT (want_va_type) != TYPE_MAIN_VARIANT (have_va_type))
+ if (have_va_type == NULL_TREE)
{
error ("first argument to %<va_arg%> not of type %<va_list%>");
return GS_ERROR;
@@ -4857,7 +4887,7 @@ gimplify_va_arg_expr (tree *expr_p, tree *pre_p, tree *post_p)
/* Generate a diagnostic for requesting data of a type that cannot
be passed through `...' due to type promotion at the call site. */
- else if ((promoted_type = lang_hooks.types.type_promotes_to (type))
+ if ((promoted_type = lang_hooks.types.type_promotes_to (type))
!= type)
{
static bool gave_help;
@@ -4889,15 +4919,15 @@ gimplify_va_arg_expr (tree *expr_p, tree *pre_p, tree *post_p)
{
/* Make it easier for the backends by protecting the valist argument
from multiple evaluations. */
- if (TREE_CODE (va_list_type_node) == ARRAY_TYPE)
+ if (TREE_CODE (have_va_type) == ARRAY_TYPE)
{
/* For this case, the backends will be expecting a pointer to
- TREE_TYPE (va_list_type_node), but it's possible we've
- actually been given an array (an actual va_list_type_node).
+ TREE_TYPE (abi), but it's possible we've
+ actually been given an array (an actual TARGET_FN_ABI_VA_LIST).
So fix it. */
if (TREE_CODE (TREE_TYPE (valist)) == ARRAY_TYPE)
{
- tree p1 = build_pointer_type (TREE_TYPE (va_list_type_node));
+ tree p1 = build_pointer_type (TREE_TYPE (have_va_type));
valist = build_fold_addr_expr_with_type (valist, p1);
}
gimplify_expr (&valist, pre_p, post_p, is_gimple_val, fb_rvalue);
@@ -4945,9 +4975,11 @@ expand_builtin_va_copy (tree exp)
dst = stabilize_va_list (dst, 1);
src = stabilize_va_list (src, 0);
- if (TREE_CODE (va_list_type_node) != ARRAY_TYPE)
+ gcc_assert (cfun != NULL && cfun->decl != NULL_TREE);
+
+ if (TREE_CODE (targetm.fn_abi_va_list (cfun->decl)) != ARRAY_TYPE)
{
- t = build2 (MODIFY_EXPR, va_list_type_node, dst, src);
+ t = build2 (MODIFY_EXPR, targetm.fn_abi_va_list (cfun->decl), dst, src);
TREE_SIDE_EFFECTS (t) = 1;
expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
}
@@ -4958,8 +4990,8 @@ expand_builtin_va_copy (tree exp)
/* Evaluate to pointers. */
dstb = expand_expr (dst, NULL_RTX, Pmode, EXPAND_NORMAL);
srcb = expand_expr (src, NULL_RTX, Pmode, EXPAND_NORMAL);
- size = expand_expr (TYPE_SIZE_UNIT (va_list_type_node), NULL_RTX,
- VOIDmode, EXPAND_NORMAL);
+ size = expand_expr (TYPE_SIZE_UNIT (targetm.fn_abi_va_list (cfun->decl)),
+ NULL_RTX, VOIDmode, EXPAND_NORMAL);
dstb = convert_memory_address (Pmode, dstb);
srcb = convert_memory_address (Pmode, srcb);
@@ -4967,10 +4999,10 @@ expand_builtin_va_copy (tree exp)
/* "Dereference" to BLKmode memories. */
dstb = gen_rtx_MEM (BLKmode, dstb);
set_mem_alias_set (dstb, get_alias_set (TREE_TYPE (TREE_TYPE (dst))));
- set_mem_align (dstb, TYPE_ALIGN (va_list_type_node));
+ set_mem_align (dstb, TYPE_ALIGN (targetm.fn_abi_va_list (cfun->decl)));
srcb = gen_rtx_MEM (BLKmode, srcb);
set_mem_alias_set (srcb, get_alias_set (TREE_TYPE (TREE_TYPE (src))));
- set_mem_align (srcb, TYPE_ALIGN (va_list_type_node));
+ set_mem_align (srcb, TYPE_ALIGN (targetm.fn_abi_va_list (cfun->decl)));
/* Copy. */
emit_block_move (dstb, srcb, size, BLOCK_OP_NORMAL);