public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] va_copy(va_list, const va_list)
@ 2004-10-21 23:59 Earl Chew
  2004-10-22 19:19 ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Earl Chew @ 2004-10-21 23:59 UTC (permalink / raw)
  To: gcc-patches

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);
      }



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] va_copy(va_list, const va_list)
  2004-10-21 23:59 [PATCH] va_copy(va_list, const va_list) Earl Chew
@ 2004-10-22 19:19 ` Richard Henderson
  2004-10-22 23:44   ` Earl Chew
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2004-10-22 19:19 UTC (permalink / raw)
  To: Earl Chew; +Cc: gcc-patches

On Thu, Oct 21, 2004 at 03:39:20PM -0700, Earl Chew wrote:
> 	* 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.

Ok.

Please add a test case as well.


r~

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] va_copy(va_list, const va_list)
  2004-10-22 19:19 ` Richard Henderson
@ 2004-10-22 23:44   ` Earl Chew
  0 siblings, 0 replies; 3+ messages in thread
From: Earl Chew @ 2004-10-22 23:44 UTC (permalink / raw)
  To: gcc-patches; +Cc: Richard Henderson

Richard Henderson wrote:
> Please add a test case as well.

Attached.

Earl

--- /dev/null	2004-10-22 14:50:16.524000000 -0700
+++ gcc-3.4.1/gcc/testsuite/gcc.dg/20041022-1.c	2004-10-22 
14:49:33.243603300 -0700
@@ -0,0 +1,14 @@
+/* Verify that va_copy() can successfully copy from const qualified
+   va_list.  */
+
+/* { dg-do compile */
+/* { dg-options "-Werror" */
+
+#include <stdarg.h>
+
+void vacopy(const va_list arglist)
+{
+    va_list copylist;
+
+    va_copy(copylist, arglist);
+}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-10-22 21:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-21 23:59 [PATCH] va_copy(va_list, const va_list) Earl Chew
2004-10-22 19:19 ` Richard Henderson
2004-10-22 23:44   ` Earl Chew

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).