This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] va_copy(va_list, const va_list)
- From: Earl Chew <earl_chew at agilent dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 21 Oct 2004 15:39:20 -0700
- Subject: [PATCH] va_copy(va_list, const va_list)
Upgrading from 2.95.4 on PowerPC, I found that problems similar to
those described in postings found in:
comp.os.linux.powerpc:
http://groups.google.com/groups?selm=a14810d3.0308252335.27a62d1e%40posting.google.com&output=gplain
gnu.gcc.help:
http://groups.google.com/groups?hl=en&lr=&th=f096feb1d2131e06&seekm=88a021-9d12.ln1%40sd.swampdog&frame=off
Previously va_copy() was defined as a macro in stdarg.h and looked
similar to:
#define va_copy(lhs,rhs) (lhs) = (rhs)
This works even if (rhs) is qualified as const (see postings).
Now va_copy is a builtin function with signature:
void va_copy(va_list, va_list);
as per C99. This sometimes fails if rhs is qualified as const.
On i386, va_list is char*, and const qualified calls to va_copy()
still work.
On powerpc, va_list is a struct __va_list_tag[1], and const qualified
calls to va_copy fail with error message:
invalid conversion from `const __va_list_tag*' to `__va_list_tag*'
This patch accommodates the powerpc case by changing the signature
of va_copy() to:
void va_copy(va_list, const va_list);
The signature remains unchanged in the i386 case.
Earl
* builtin-types.def: Introduce const_va_list_arg_type_node
and replace BT_FN_VOID_VALIST_REF_VALIST_ARG with
BT_FN_VOID_VALIST_REF_CONST_VALIST_ARG
* builtin.def: Define va_copy(va_list, const va_list)
* c-common.c (c_common_nodes_and_builtins): Create
const_va_list_arg_type_node as appropriate.
--- gcc-3.4.1/gcc/builtin-types.def.orig 2004-10-21 13:08:22.465741300 -0700
+++ gcc-3.4.1/gcc/builtin-types.def 2004-10-21 13:09:24.997391500 -0700
@@ -87,6 +87,7 @@
DEF_PRIMITIVE_TYPE (BT_VALIST_REF, va_list_ref_type_node)
DEF_PRIMITIVE_TYPE (BT_VALIST_ARG, va_list_arg_type_node)
+DEF_PRIMITIVE_TYPE (BT_CONST_VALIST_ARG, const_va_list_arg_type_node)
DEF_FUNCTION_TYPE_0 (BT_FN_VOID, BT_VOID)
DEF_FUNCTION_TYPE_0 (BT_FN_PTR, BT_PTR)
@@ -162,8 +163,8 @@
BT_INT, BT_INT, BT_PTR)
DEF_FUNCTION_TYPE_2 (BT_FN_VOID_PTRMODE_PTR,
BT_VOID, BT_PTRMODE, BT_PTR)
-DEF_FUNCTION_TYPE_2 (BT_FN_VOID_VALIST_REF_VALIST_ARG,
- BT_VOID, BT_VALIST_REF, BT_VALIST_ARG)
+DEF_FUNCTION_TYPE_2 (BT_FN_VOID_VALIST_REF_CONST_VALIST_ARG,
+ BT_VOID, BT_VALIST_REF, BT_CONST_VALIST_ARG)
DEF_FUNCTION_TYPE_2 (BT_FN_LONG_LONG_LONG,
BT_LONG, BT_LONG, BT_LONG)
DEF_FUNCTION_TYPE_2 (BT_FN_INT_PTR_CONST_STRING,
--- gcc-3.4.1/gcc/builtins.def.orig 2004-10-21 13:14:16.327381000 -0700
+++ gcc-3.4.1/gcc/builtins.def 2004-10-21 13:14:29.968093300 -0700
@@ -546,7 +546,7 @@
DEF_LIB_BUILTIN (BUILT_IN_STRFTIME, "strftime",
BT_FN_SIZE_STRING_SIZE_CONST_STRING_CONST_PTR, ATTR_FORMAT_STRFTIME_3_0)
DEF_GCC_BUILTIN (BUILT_IN_TRAP, "trap", BT_FN_VOID,
ATTR_NORETURN_NOTHROW_LIST)
DEF_GCC_BUILTIN (BUILT_IN_UNWIND_INIT, "unwind_init",
BT_FN_VOID, ATTR_NULL)
-DEF_GCC_BUILTIN (BUILT_IN_VA_COPY, "va_copy",
BT_FN_VOID_VALIST_REF_VALIST_ARG, ATTR_NULL)
+DEF_GCC_BUILTIN (BUILT_IN_VA_COPY, "va_copy",
BT_FN_VOID_VALIST_REF_CONST_VALIST_ARG, ATTR_NULL)
DEF_GCC_BUILTIN (BUILT_IN_VA_END, "va_end",
BT_FN_VOID_VALIST_REF, ATTR_NULL)
DEF_GCC_BUILTIN (BUILT_IN_VA_START, "va_start",
BT_FN_VOID_VALIST_REF_VAR, ATTR_NULL)
DEF_EXT_LIB_BUILTIN (BUILT_IN__EXIT, "_exit", BT_FN_VOID_INT,
ATTR_NORETURN_NOTHROW_LIST)
--- gcc-3.4.1/gcc/c-common.c.orig 2004-10-21 13:03:40.213934900 -0700
+++ gcc-3.4.1/gcc/c-common.c 2004-10-21 13:17:37.828670600 -0700
@@ -3081,6 +3081,7 @@
tree array_domain_type;
tree va_list_ref_type_node;
tree va_list_arg_type_node;
+ tree const_va_list_arg_type_node;
/* Define `int' and `char' first so that dbx will output them first. */
record_builtin_type (RID_INT, NULL, integer_type_node);
@@ -3315,10 +3316,13 @@
{
va_list_arg_type_node = va_list_ref_type_node =
build_pointer_type (TREE_TYPE (va_list_type_node));
+ const_va_list_arg_type_node =
+ build_pointer_type (build_qualified_type
+ (TREE_TYPE (va_list_type_node),
TYPE_QUAL_CONST));
}
else
{
- va_list_arg_type_node = va_list_type_node;
+ va_list_arg_type_node = const_va_list_arg_type_node =
va_list_type_node;
va_list_ref_type_node = build_reference_type (va_list_type_node);
}