va_arg *, and why not.
Gabriel Dos Reis
gdr@codesourcery.com
Sun Jul 16 21:53:00 GMT 2000
Geoff Keating <geoffk@cygnus.com> writes:
| Hi Gabriel,
|
| at lines 910, 1425, and 1488, diagnostic.c does things like:
[...]
| or better would make output_buffer contain a real va_list, but you
| can't do this in gcc, because it's not portable to old compilers.
| You'll have to either:
|
| 1. implement va_copy, by using an autoconf test to determine whether
| or not va_list is an array type; or
| 2. only pass around va_list *.
I choose the latter. I'm boostrapping with this patch, does it let
you do a complete bootstrap?
While I was at it, I fix a thinko in c-errors.c
| This breaks the bootstrap on powerpc-linux.
I'm sorry for the confusion. My apologies.
-- Gaby
CodeSourcery, LLC http://www.codesourcery.com
2000-07-17 Gabriel Dos Reis <gdr@merlin.codesourcery.com>
* diagnostic.c (output_do_verbatim, diagnostic_for_decl): Change
prototype.
(pedwarn_with_decl, error_with_decl, warning_with_decl): Adjust
call to diagnostic_for_decl.
(output_verbatim, verbatim): Adjust callt to output_do_verbatim.
(report_diagnostic): Tweak.
* c-errors.c (pedwarn_c99): End variable argument list.
Index: diagnostic.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/diagnostic.c,v
retrieving revision 1.25
diff -p -r1.25 diagnostic.c
*** diagnostic.c 2000/07/15 16:50:31 1.25
--- diagnostic.c 2000/07/17 04:41:58
*************** Boston, MA 02111-1307, USA. */
*** 64,70 ****
/* Prototypes. */
static void finish_diagnostic PARAMS ((void));
static void output_do_verbatim PARAMS ((output_buffer *,
! const char *, va_list));
static void output_to_stream PARAMS ((output_buffer *, FILE *));
static void output_format PARAMS ((output_buffer *));
--- 64,70 ----
/* Prototypes. */
static void finish_diagnostic PARAMS ((void));
static void output_do_verbatim PARAMS ((output_buffer *,
! const char *, va_list *));
static void output_to_stream PARAMS ((output_buffer *, FILE *));
static void output_format PARAMS ((output_buffer *));
*************** static void output_do_printf PARAMS ((ou
*** 76,82 ****
static void format_with_decl PARAMS ((output_buffer *, tree));
static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
static void diagnostic_for_asm PARAMS ((rtx, const char *, va_list, int));
! static void diagnostic_for_decl PARAMS ((tree, const char *, va_list, int));
static void vnotice PARAMS ((FILE *, const char *, va_list));
static void set_real_maximum_length PARAMS ((output_buffer *));
--- 76,82 ----
static void format_with_decl PARAMS ((output_buffer *, tree));
static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
static void diagnostic_for_asm PARAMS ((rtx, const char *, va_list, int));
! static void diagnostic_for_decl PARAMS ((tree, const char *, va_list *, int));
static void vnotice PARAMS ((FILE *, const char *, va_list));
static void set_real_maximum_length PARAMS ((output_buffer *));
*************** diagnostic_for_asm (insn, msg, args, war
*** 892,901 ****
MSG is a format string which uses %s to substitute the declaration
name; subsequent substitutions are a la output_format. */
static void
! diagnostic_for_decl (decl, msg, args, warn)
tree decl;
const char *msg;
! va_list args;
int warn;
{
output_state os;
--- 892,901 ----
MSG is a format string which uses %s to substitute the declaration
name; subsequent substitutions are a la output_format. */
static void
! diagnostic_for_decl (decl, msg, args_ptr, warn)
tree decl;
const char *msg;
! va_list *args_ptr;
int warn;
{
output_state os;
*************** diagnostic_for_decl (decl, msg, args, wa
*** 907,913 ****
output_set_prefix
(diagnostic_buffer, context_as_prefix
(DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn));
! output_buffer_ptr_to_format_args (diagnostic_buffer) = &args;
output_buffer_text_cursor (diagnostic_buffer) = msg;
format_with_decl (diagnostic_buffer, decl);
finish_diagnostic ();
--- 907,913 ----
output_set_prefix
(diagnostic_buffer, context_as_prefix
(DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn));
! output_buffer_ptr_to_format_args (diagnostic_buffer) = args_ptr;
output_buffer_text_cursor (diagnostic_buffer) = msg;
format_with_decl (diagnostic_buffer, decl);
finish_diagnostic ();
*************** pedwarn_with_decl VPARAMS ((tree decl, c
*** 1027,1033 ****
or kernel uses the original layout). There's no point in issuing a
warning either, it's just unnecessary noise. */
if (!DECL_IN_SYSTEM_HEADER (decl))
! diagnostic_for_decl (decl, msgid, ap, !flag_pedantic_errors);
va_end (ap);
}
--- 1027,1033 ----
or kernel uses the original layout). There's no point in issuing a
warning either, it's just unnecessary noise. */
if (!DECL_IN_SYSTEM_HEADER (decl))
! diagnostic_for_decl (decl, msgid, &ap, !flag_pedantic_errors);
va_end (ap);
}
*************** error_with_decl VPARAMS ((tree decl, con
*** 1211,1217 ****
msgid = va_arg (ap, const char *);
#endif
! diagnostic_for_decl (decl, msgid, ap, /* warn = */ 0);
va_end (ap);
}
--- 1211,1217 ----
msgid = va_arg (ap, const char *);
#endif
! diagnostic_for_decl (decl, msgid, &ap, /* warn = */ 0);
va_end (ap);
}
*************** warning_with_decl VPARAMS ((tree decl, c
*** 1356,1362 ****
msgid = va_arg (ap, const char *);
#endif
! diagnostic_for_decl (decl, msgid, ap, /* warn = */ 1);
va_end (ap);
}
--- 1356,1362 ----
msgid = va_arg (ap, const char *);
#endif
! diagnostic_for_decl (decl, msgid, &ap, /* warn = */ 1);
va_end (ap);
}
*************** finish_diagnostic ()
*** 1411,1420 ****
/* Helper subroutine of output_verbatim and verbatim. Do the approriate
settings needed by BUFFER for a verbatim formatting. */
static void
! output_do_verbatim (buffer, msg, args)
output_buffer *buffer;
const char *msg;
! va_list args;
{
output_state os;
--- 1411,1420 ----
/* Helper subroutine of output_verbatim and verbatim. Do the approriate
settings needed by BUFFER for a verbatim formatting. */
static void
! output_do_verbatim (buffer, msg, args_ptr)
output_buffer *buffer;
const char *msg;
! va_list *args_ptr;
{
output_state os;
*************** output_do_verbatim (buffer, msg, args)
*** 1422,1428 ****
output_prefix (buffer) = NULL;
prefixing_policy (buffer) = DIAGNOSTICS_SHOW_PREFIX_NEVER;
output_buffer_text_cursor (buffer) = msg;
! output_buffer_ptr_to_format_args (buffer) = &args;
output_set_maximum_length (buffer, 0);
output_format (buffer);
buffer->state = os;
--- 1422,1428 ----
output_prefix (buffer) = NULL;
prefixing_policy (buffer) = DIAGNOSTICS_SHOW_PREFIX_NEVER;
output_buffer_text_cursor (buffer) = msg;
! output_buffer_ptr_to_format_args (buffer) = args_ptr;
output_set_maximum_length (buffer, 0);
output_format (buffer);
buffer->state = os;
*************** output_verbatim VPARAMS ((output_buffer
*** 1443,1449 ****
buffer = va_arg (ap, output_buffer *);
msg = va_arg (ap, const char *);
#endif
! output_do_verbatim (buffer, msg, ap);
va_end (ap);
}
--- 1443,1449 ----
buffer = va_arg (ap, output_buffer *);
msg = va_arg (ap, const char *);
#endif
! output_do_verbatim (buffer, msg, &ap);
va_end (ap);
}
*************** verbatim VPARAMS ((const char *msg, ...)
*** 1460,1466 ****
#ifndef ANSI_PROTOTYPES
msg = va_arg (ap, const char *);
#endif
! output_do_verbatim (diagnostic_buffer, msg, ap);
output_to_stream (diagnostic_buffer, stderr);
va_end (ap);
}
--- 1460,1466 ----
#ifndef ANSI_PROTOTYPES
msg = va_arg (ap, const char *);
#endif
! output_do_verbatim (diagnostic_buffer, msg, &ap);
output_to_stream (diagnostic_buffer, stderr);
va_end (ap);
}
*************** report_diagnostic (msg, args, file, line
*** 1479,1491 ****
int line;
int warn;
{
output_state os;
if (!count_error (warn))
return;
os = diagnostic_buffer->state;
diagnostic_msg = msg;
! diagnostic_args = &args;
report_error_function (file);
output_set_prefix
(diagnostic_buffer, context_as_prefix (file, line, warn));
--- 1479,1493 ----
int line;
int warn;
{
+ va_list ap;
output_state os;
if (!count_error (warn))
return;
+ va_copy (ap, args);
os = diagnostic_buffer->state;
diagnostic_msg = msg;
! diagnostic_args = ≈
report_error_function (file);
output_set_prefix
(diagnostic_buffer, context_as_prefix (file, line, warn));
*************** report_diagnostic (msg, args, file, line
*** 1493,1496 ****
--- 1495,1499 ----
finish_diagnostic ();
output_destroy_prefix (diagnostic_buffer);
diagnostic_buffer->state = os;
+ va_end (ap);
}
Index: c-errors.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-errors.c,v
retrieving revision 1.1
diff -p -r1.1 c-errors.c
*** c-errors.c 2000/07/12 14:12:51 1.1
--- c-errors.c 2000/07/17 04:41:58
*************** pedwarn_c99 VPARAMS ((const char *msgid,
*** 45,48 ****
--- 45,49 ----
report_diagnostic (msgid, ap, input_filename, lineno,
!flag_isoc99 || !flag_pedantic_errors);
+ va_end (ap);
}
More information about the Gcc-bugs
mailing list