This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Avoid using %qs in calls to internal_error


On Sun, 1 May 2005, Roger Sayle wrote:

> Unfortunately, the %q format qualifier is an internal GCC extension
> and not supported by most (all?) libc runtimes.  This poses problems
> for typical non-C/C++ front-end implementations of internal_error:

> In gcc/errors.c:
> > void
> > internal_error (const char *format, ...)
> > {
> >   va_list ap;
> >
> >   va_start (ap, format);
> >   fprintf (stderr, "%s: Internal error: ", progname);
> >   vfprintf (stderr, format, ap);
> >   va_end (ap);
> >   fputc ('\n', stderr);
> >   exit (FATAL_EXIT_CODE);
> > }

This is the implementation used in the generator programs, not in front 
ends.  As far as I know all formats that get passed to the generator 
program version use standard printf formats only.

> and in gcc/ada/misc.c:
> > static void
> > internal_error_function (const char *msgid, va_list *ap)
> > {
> >   char buffer[1000];            /* Assume this is big enough.  */
> >   ...
> >   vsprintf (buffer, msgid, *ap);

I'm not convinced it's desirable for any front ends to override 
internal_error like this.

> (1) Teach each of the front-ends how to interpret/implement %qs,

I don't think you want to teach the front ends in duplicate.  Instead, it 
would be better to generalise the pretty-printing support so it can be 
used by all the places that use either standard printf functions or 
printf-like functions (including in the generator programs).  This would 
for example allow all the references to HOST_WIDE_INT_PRINT_* to become %w 
formats.  This does require implementing functions such as asprintf on top 
of the pretty-printing.

> (3) Don't use %qs in formats passed to internal_error.

This is in practice what is done now for formats which we can't guarantee 
go through the pretty-printing code, including some diagnostics built up 
using asprintf and lots of diagnostics in programs such as gcc.c and 
collect2.c.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]