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]

[ADA Patch] Handle %qs in GNAT's bug box


The following patch to the Ada front-end implements Joseph Myers'
suggestion that front-ends should use the appropriate pretty printer
functionality to handle %qs, %w etc. in GCC's error messages rather
than avoid using them in the middle-end.
http://gcc.gnu.org/ml/gcc-patches/2005-05/msg00062.html

Without this patch gant1 generates truncated error messages as the
host's stdio runtime doesn't understand how to interpret %qs. So
(with a pending change to the compiler), gnat1 currently generates
diagnostics such as:

+===========================GNAT BUG DETECTED==============================+
| 4.1.0 20050501 (experimental) (i686-pc-linux-gnu) GCC error:             |
| tree check: expected class                                               |
| Error detected at c37213d.adb:90:37                                      |
| Please submit a bug report; see http://gcc.gnu.org/bugs.html.            |
...

With the patch below we now generate the slightly more useful:

+===========================GNAT BUG DETECTED==============================+
| 4.1.0 20050501 (experimental) (i686-pc-linux-gnu) GCC error:             |
| tree check: expected class 'constant', have 'binary' (bit_and_expr)      |
|    in max_size, at ada/utils.c:1992                                      |
| Error detected at c37213d.adb:90:37                                      |
| Please submit a bug report; see http://gcc.gnu.org/bugs.html.            |
...


The following patch has been tested on i686-pc-linux-gnu with a bootstrap
including C and Ada, and a full testsuite run, including ACATS, with no
new regressions.  Gaby could you confirm that I'm using the correct
pretty-printer functions and idioms, to simplify the Ada folks' review?
Admittedly, I'm subverting the constness of pp_formatted_text, but it
isn't clear whether Ada's Strings don't have to be NUL terminated, and
allocating yet another buffer to truncate the string at newline looked
like a waste.

Ok for mainline?


[p.s.  I'll address the suspicious uses of TREE_OVERFLOW in the Ada
front-end that cause the above ICE(s) in ACATS in a follow-up patch.]


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

	* misc.c (internal_error_function): Don't use vsprintf to format
	the error message text, instead use pp_format_text and the new
	pretty printer APIs.  This allows handling of %qs, %w, etc.


Index: misc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/misc.c,v
retrieving revision 1.101
diff -c -3 -p -r1.101 misc.c
*** misc.c	23 Apr 2005 21:28:09 -0000	1.101
--- misc.c	2 May 2005 23:21:55 -0000
*************** gnat_post_options (const char **pfilenam
*** 365,376 ****
  static void
  internal_error_function (const char *msgid, va_list *ap)
  {
!   char buffer[1000];		/* Assume this is big enough.  */
    char *p;
    String_Template temp;
    Fat_Pointer fp;

!   vsprintf (buffer, msgid, *ap);

    /* Go up to the first newline.  */
    for (p = buffer; *p; p++)
--- 365,395 ----
  static void
  internal_error_function (const char *msgid, va_list *ap)
  {
!   static pretty_printer pp;
!   static bool init = false;
!   text_info tinfo;
!   char *buffer;
    char *p;
    String_Template temp;
    Fat_Pointer fp;

!   /* Initialize or reset the pretty-printer.  */
!   if (!init)
!     {
!       pp_construct (&pp, NULL, 0);
!       init = true;
!     }
!   else
!     pp_clear_output_area (&pp);
!
!   /* Format the message into the pretty-printer.  */
!   tinfo.format_spec = msgid;
!   tinfo.args_ptr = ap;
!   tinfo.err_no = errno;
!   pp_format_text (&pp, &tinfo);
!
!   /* Extract a (writable) pointer to the formatted text.  */
!   buffer = (char*) pp_formatted_text (&pp);

    /* Go up to the first newline.  */
    for (p = buffer; *p; p++)
*************** internal_error_function (const char *msg
*** 380,387 ****
  	break;
        }

!   temp.Low_Bound = 1, temp.High_Bound = strlen (buffer);
!   fp.Array = buffer, fp.Bounds = &temp;

    Current_Error_Node = error_gnat_node;
    Compiler_Abort (fp, -1);
--- 399,408 ----
  	break;
        }

!   temp.Low_Bound = 1;
!   temp.High_Bound = p - buffer;
!   fp.Bounds = &temp;
!   fp.Array = buffer;

    Current_Error_Node = error_gnat_node;
    Compiler_Abort (fp, -1);


Roger
--


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