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]

[PATCH] Avoid using %qs in calls to internal_error


The following patch fixes a problem with one of GCC's ICE error
messages being mysteriously truncated by the Ada front-end's bug
box.  The issue is that the call to internal_error in tree.c's
tree_class_check_failed uses %qs to specify a locale quoted string.

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

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


Naturally, the passing of formats containing %qs doesn't play nicely
with the host's vfprintf and vsprintf.  This then results in the Ada
front-end reporting truncated error messages in it's bug box (the
Linux/glibc runtime just stops upon encountering a %qs).


There are three possible solutions, in reverse order of effort;
(1) Teach each of the front-ends how to interpret/implement %qs,
(2) Teach each of the front-ends to strip %q from format strings,
(3) Don't use %qs in formats passed to internal_error.

The patch below implements the last of these for the only case
that I could find.  This is also consistent with other uses of
GCC's internal_error, that use "'%s'" where appropriate.


The patch below was tested on i686-pc-linux-gnu with a full
"make bootstrap", all default languages, and regression tested
with a top-level "make -k check" with no new failures.

Ok for mainline?  I was tempted to consider this obvious, but I
wanted to double check with the diagnostic folks that they didn't
think that options (1) or (2) above would be preferrable (in the
long term).  I'm not volunteering, but perhaps the C family
implementation should also use stdio directly, to help diagnose
mismatches in future?



2005-05-01  Roger Sayle  <roger@eyesopen.com>

	* tree.c (tree_class_check_failed): Don't use quotation qualifiers
	on conversion specifiers in calls to internal_error.


Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.476
diff -c -3 -p -r1.476 tree.c
*** tree.c	29 Apr 2005 20:27:49 -0000	1.476
--- tree.c	1 May 2005 21:31:39 -0000
*************** tree_class_check_failed (const tree node
*** 5462,5468 ****
  			 const char *file, int line, const char *function)
  {
    internal_error
!     ("tree check: expected class %qs, have %qs (%s) in %s, at %s:%d",
       TREE_CODE_CLASS_STRING (cl),
       TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
       tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);
--- 5462,5468 ----
  			 const char *file, int line, const char *function)
  {
    internal_error
!     ("tree check: expected class '%s', have '%s' (%s) in %s, at %s:%d",
       TREE_CODE_CLASS_STRING (cl),
       TREE_CODE_CLASS_STRING (TREE_CODE_CLASS (TREE_CODE (node))),
       tree_code_name[TREE_CODE (node)], function, trim_filename (file), line);


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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