23308b6544e3831916d0c1fddbbec6e9184d2263
[gcc.git] / gcc / fortran / error.c
1 /* Handle errors.
2 Copyright (C) 2000-2015 Free Software Foundation, Inc.
3 Contributed by Andy Vaught & Niels Kristian Bech Jensen
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 /* Handle the inevitable errors. A major catch here is that things
22 flagged as errors in one match subroutine can conceivably be legal
23 elsewhere. This means that error messages are recorded and saved
24 for possible use later. If a line does not match a legal
25 construction, then the saved error message is reported. */
26
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "flags.h"
31 #include "gfortran.h"
32
33 #include "diagnostic.h"
34 #include "diagnostic-color.h"
35 #include "tree-diagnostic.h" /* tree_diagnostics_defaults */
36
37 #include <new> /* For placement-new */
38
39 static int suppress_errors = 0;
40
41 static bool warnings_not_errors = false;
42
43 static int terminal_width, errors, warnings;
44
45 static gfc_error_buf error_buffer, warning_buffer, *cur_error_buffer;
46
47 /* True if the error/warnings should be buffered. */
48 static bool buffered_p;
49 /* These are always buffered buffers (.flush_p == false) to be used by
50 the pretty-printer. */
51 static output_buffer *pp_error_buffer, *pp_warning_buffer;
52 static int warningcount_buffered, werrorcount_buffered;
53
54 /* Return true if there output_buffer is empty. */
55
56 static bool
57 gfc_output_buffer_empty_p (const output_buffer * buf)
58 {
59 return output_buffer_last_position_in_text (buf) == NULL;
60 }
61
62 /* Go one level deeper suppressing errors. */
63
64 void
65 gfc_push_suppress_errors (void)
66 {
67 gcc_assert (suppress_errors >= 0);
68 ++suppress_errors;
69 }
70
71 static void
72 gfc_error (const char *gmsgid, va_list ap) ATTRIBUTE_GCC_GFC(1,0);
73
74 static bool
75 gfc_warning (int opt, const char *gmsgid, va_list ap) ATTRIBUTE_GCC_GFC(2,0);
76
77
78 /* Leave one level of error suppressing. */
79
80 void
81 gfc_pop_suppress_errors (void)
82 {
83 gcc_assert (suppress_errors > 0);
84 --suppress_errors;
85 }
86
87
88 /* Determine terminal width (for trimming source lines in output). */
89
90 static int
91 gfc_get_terminal_width (void)
92 {
93 return isatty (STDERR_FILENO) ? get_terminal_width () : INT_MAX;
94 }
95
96
97 /* Per-file error initialization. */
98
99 void
100 gfc_error_init_1 (void)
101 {
102 terminal_width = gfc_get_terminal_width ();
103 errors = 0;
104 warnings = 0;
105 gfc_buffer_error (false);
106 }
107
108
109 /* Set the flag for buffering errors or not. */
110
111 void
112 gfc_buffer_error (bool flag)
113 {
114 buffered_p = flag;
115 }
116
117
118 /* Add a single character to the error buffer or output depending on
119 buffered_p. */
120
121 static void
122 error_char (char c)
123 {
124 if (buffered_p)
125 {
126 if (cur_error_buffer->index >= cur_error_buffer->allocated)
127 {
128 cur_error_buffer->allocated = cur_error_buffer->allocated
129 ? cur_error_buffer->allocated * 2 : 1000;
130 cur_error_buffer->message = XRESIZEVEC (char, cur_error_buffer->message,
131 cur_error_buffer->allocated);
132 }
133 cur_error_buffer->message[cur_error_buffer->index++] = c;
134 }
135 else
136 {
137 if (c != 0)
138 {
139 /* We build up complete lines before handing things
140 over to the library in order to speed up error printing. */
141 static char *line;
142 static size_t allocated = 0, index = 0;
143
144 if (index + 1 >= allocated)
145 {
146 allocated = allocated ? allocated * 2 : 1000;
147 line = XRESIZEVEC (char, line, allocated);
148 }
149 line[index++] = c;
150 if (c == '\n')
151 {
152 line[index] = '\0';
153 fputs (line, stderr);
154 index = 0;
155 }
156 }
157 }
158 }
159
160
161 /* Copy a string to wherever it needs to go. */
162
163 static void
164 error_string (const char *p)
165 {
166 while (*p)
167 error_char (*p++);
168 }
169
170
171 /* Print a formatted integer to the error buffer or output. */
172
173 #define IBUF_LEN 60
174
175 static void
176 error_uinteger (unsigned long int i)
177 {
178 char *p, int_buf[IBUF_LEN];
179
180 p = int_buf + IBUF_LEN - 1;
181 *p-- = '\0';
182
183 if (i == 0)
184 *p-- = '0';
185
186 while (i > 0)
187 {
188 *p-- = i % 10 + '0';
189 i = i / 10;
190 }
191
192 error_string (p + 1);
193 }
194
195 static void
196 error_integer (long int i)
197 {
198 unsigned long int u;
199
200 if (i < 0)
201 {
202 u = (unsigned long int) -i;
203 error_char ('-');
204 }
205 else
206 u = i;
207
208 error_uinteger (u);
209 }
210
211
212 static size_t
213 gfc_widechar_display_length (gfc_char_t c)
214 {
215 if (gfc_wide_is_printable (c) || c == '\t')
216 /* Printable ASCII character, or tabulation (output as a space). */
217 return 1;
218 else if (c < ((gfc_char_t) 1 << 8))
219 /* Displayed as \x?? */
220 return 4;
221 else if (c < ((gfc_char_t) 1 << 16))
222 /* Displayed as \u???? */
223 return 6;
224 else
225 /* Displayed as \U???????? */
226 return 10;
227 }
228
229
230 /* Length of the ASCII representation of the wide string, escaping wide
231 characters as print_wide_char_into_buffer() does. */
232
233 static size_t
234 gfc_wide_display_length (const gfc_char_t *str)
235 {
236 size_t i, len;
237
238 for (i = 0, len = 0; str[i]; i++)
239 len += gfc_widechar_display_length (str[i]);
240
241 return len;
242 }
243
244 static int
245 print_wide_char_into_buffer (gfc_char_t c, char *buf)
246 {
247 static const char xdigit[16] = { '0', '1', '2', '3', '4', '5', '6',
248 '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
249
250 if (gfc_wide_is_printable (c) || c == '\t')
251 {
252 buf[1] = '\0';
253 /* Tabulation is output as a space. */
254 buf[0] = (unsigned char) (c == '\t' ? ' ' : c);
255 return 1;
256 }
257 else if (c < ((gfc_char_t) 1 << 8))
258 {
259 buf[4] = '\0';
260 buf[3] = xdigit[c & 0x0F];
261 c = c >> 4;
262 buf[2] = xdigit[c & 0x0F];
263
264 buf[1] = 'x';
265 buf[0] = '\\';
266 return 4;
267 }
268 else if (c < ((gfc_char_t) 1 << 16))
269 {
270 buf[6] = '\0';
271 buf[5] = xdigit[c & 0x0F];
272 c = c >> 4;
273 buf[4] = xdigit[c & 0x0F];
274 c = c >> 4;
275 buf[3] = xdigit[c & 0x0F];
276 c = c >> 4;
277 buf[2] = xdigit[c & 0x0F];
278
279 buf[1] = 'u';
280 buf[0] = '\\';
281 return 6;
282 }
283 else
284 {
285 buf[10] = '\0';
286 buf[9] = xdigit[c & 0x0F];
287 c = c >> 4;
288 buf[8] = xdigit[c & 0x0F];
289 c = c >> 4;
290 buf[7] = xdigit[c & 0x0F];
291 c = c >> 4;
292 buf[6] = xdigit[c & 0x0F];
293 c = c >> 4;
294 buf[5] = xdigit[c & 0x0F];
295 c = c >> 4;
296 buf[4] = xdigit[c & 0x0F];
297 c = c >> 4;
298 buf[3] = xdigit[c & 0x0F];
299 c = c >> 4;
300 buf[2] = xdigit[c & 0x0F];
301
302 buf[1] = 'U';
303 buf[0] = '\\';
304 return 10;
305 }
306 }
307
308 static char wide_char_print_buffer[11];
309
310 const char *
311 gfc_print_wide_char (gfc_char_t c)
312 {
313 print_wide_char_into_buffer (c, wide_char_print_buffer);
314 return wide_char_print_buffer;
315 }
316
317
318 /* Show the file, where it was included, and the source line, give a
319 locus. Calls error_printf() recursively, but the recursion is at
320 most one level deep. */
321
322 static void error_printf (const char *, ...) ATTRIBUTE_GCC_GFC(1,2);
323
324 static void
325 show_locus (locus *loc, int c1, int c2)
326 {
327 gfc_linebuf *lb;
328 gfc_file *f;
329 gfc_char_t *p;
330 int i, offset, cmax;
331
332 /* TODO: Either limit the total length and number of included files
333 displayed or add buffering of arbitrary number of characters in
334 error messages. */
335
336 /* Write out the error header line, giving the source file and error
337 location (in GNU standard "[file]:[line].[column]:" format),
338 followed by an "included by" stack and a blank line. This header
339 format is matched by a testsuite parser defined in
340 lib/gfortran-dg.exp. */
341
342 lb = loc->lb;
343 f = lb->file;
344
345 error_string (f->filename);
346 error_char (':');
347
348 error_integer (LOCATION_LINE (lb->location));
349
350 if ((c1 > 0) || (c2 > 0))
351 error_char ('.');
352
353 if (c1 > 0)
354 error_integer (c1);
355
356 if ((c1 > 0) && (c2 > 0))
357 error_char ('-');
358
359 if (c2 > 0)
360 error_integer (c2);
361
362 error_char (':');
363 error_char ('\n');
364
365 for (;;)
366 {
367 i = f->inclusion_line;
368
369 f = f->up;
370 if (f == NULL) break;
371
372 error_printf (" Included at %s:%d:", f->filename, i);
373 }
374
375 error_char ('\n');
376
377 /* Calculate an appropriate horizontal offset of the source line in
378 order to get the error locus within the visible portion of the
379 line. Note that if the margin of 5 here is changed, the
380 corresponding margin of 10 in show_loci should be changed. */
381
382 offset = 0;
383
384 /* If the two loci would appear in the same column, we shift
385 '2' one column to the right, so as to print '12' rather than
386 just '1'. We do this here so it will be accounted for in the
387 margin calculations. */
388
389 if (c1 == c2)
390 c2 += 1;
391
392 cmax = (c1 < c2) ? c2 : c1;
393 if (cmax > terminal_width - 5)
394 offset = cmax - terminal_width + 5;
395
396 /* Show the line itself, taking care not to print more than what can
397 show up on the terminal. Tabs are converted to spaces, and
398 nonprintable characters are converted to a "\xNN" sequence. */
399
400 p = &(lb->line[offset]);
401 i = gfc_wide_display_length (p);
402 if (i > terminal_width)
403 i = terminal_width - 1;
404
405 while (i > 0)
406 {
407 static char buffer[11];
408 i -= print_wide_char_into_buffer (*p++, buffer);
409 error_string (buffer);
410 }
411
412 error_char ('\n');
413
414 /* Show the '1' and/or '2' corresponding to the column of the error
415 locus. Note that a value of -1 for c1 or c2 will simply cause
416 the relevant number not to be printed. */
417
418 c1 -= offset;
419 c2 -= offset;
420 cmax -= offset;
421
422 p = &(lb->line[offset]);
423 for (i = 0; i < cmax; i++)
424 {
425 int spaces, j;
426 spaces = gfc_widechar_display_length (*p++);
427
428 if (i == c1)
429 error_char ('1'), spaces--;
430 else if (i == c2)
431 error_char ('2'), spaces--;
432
433 for (j = 0; j < spaces; j++)
434 error_char (' ');
435 }
436
437 if (i == c1)
438 error_char ('1');
439 else if (i == c2)
440 error_char ('2');
441
442 error_char ('\n');
443
444 }
445
446
447 /* As part of printing an error, we show the source lines that caused
448 the problem. We show at least one, and possibly two loci; the two
449 loci may or may not be on the same source line. */
450
451 static void
452 show_loci (locus *l1, locus *l2)
453 {
454 int m, c1, c2;
455
456 if (l1 == NULL || l1->lb == NULL)
457 {
458 error_printf ("<During initialization>\n");
459 return;
460 }
461
462 /* While calculating parameters for printing the loci, we consider possible
463 reasons for printing one per line. If appropriate, print the loci
464 individually; otherwise we print them both on the same line. */
465
466 c1 = l1->nextc - l1->lb->line;
467 if (l2 == NULL)
468 {
469 show_locus (l1, c1, -1);
470 return;
471 }
472
473 c2 = l2->nextc - l2->lb->line;
474
475 if (c1 < c2)
476 m = c2 - c1;
477 else
478 m = c1 - c2;
479
480 /* Note that the margin value of 10 here needs to be less than the
481 margin of 5 used in the calculation of offset in show_locus. */
482
483 if (l1->lb != l2->lb || m > terminal_width - 10)
484 {
485 show_locus (l1, c1, -1);
486 show_locus (l2, -1, c2);
487 return;
488 }
489
490 show_locus (l1, c1, c2);
491
492 return;
493 }
494
495
496 /* Workhorse for the error printing subroutines. This subroutine is
497 inspired by g77's error handling and is similar to printf() with
498 the following %-codes:
499
500 %c Character, %d or %i Integer, %s String, %% Percent
501 %L Takes locus argument
502 %C Current locus (no argument)
503
504 If a locus pointer is given, the actual source line is printed out
505 and the column is indicated. Since we want the error message at
506 the bottom of any source file information, we must scan the
507 argument list twice -- once to determine whether the loci are
508 present and record this for printing, and once to print the error
509 message after and loci have been printed. A maximum of two locus
510 arguments are permitted.
511
512 This function is also called (recursively) by show_locus in the
513 case of included files; however, as show_locus does not resupply
514 any loci, the recursion is at most one level deep. */
515
516 #define MAX_ARGS 10
517
518 static void ATTRIBUTE_GCC_GFC(2,0)
519 error_print (const char *type, const char *format0, va_list argp)
520 {
521 enum { TYPE_CURRENTLOC, TYPE_LOCUS, TYPE_INTEGER, TYPE_UINTEGER,
522 TYPE_LONGINT, TYPE_ULONGINT, TYPE_CHAR, TYPE_STRING,
523 NOTYPE };
524 struct
525 {
526 int type;
527 int pos;
528 union
529 {
530 int intval;
531 unsigned int uintval;
532 long int longintval;
533 unsigned long int ulongintval;
534 char charval;
535 const char * stringval;
536 } u;
537 } arg[MAX_ARGS], spec[MAX_ARGS];
538 /* spec is the array of specifiers, in the same order as they
539 appear in the format string. arg is the array of arguments,
540 in the same order as they appear in the va_list. */
541
542 char c;
543 int i, n, have_l1, pos, maxpos;
544 locus *l1, *l2, *loc;
545 const char *format;
546
547 loc = l1 = l2 = NULL;
548
549 have_l1 = 0;
550 pos = -1;
551 maxpos = -1;
552
553 n = 0;
554 format = format0;
555
556 for (i = 0; i < MAX_ARGS; i++)
557 {
558 arg[i].type = NOTYPE;
559 spec[i].pos = -1;
560 }
561
562 /* First parse the format string for position specifiers. */
563 while (*format)
564 {
565 c = *format++;
566 if (c != '%')
567 continue;
568
569 if (*format == '%')
570 {
571 format++;
572 continue;
573 }
574
575 if (ISDIGIT (*format))
576 {
577 /* This is a position specifier. For example, the number
578 12 in the format string "%12$d", which specifies the third
579 argument of the va_list, formatted in %d format.
580 For details, see "man 3 printf". */
581 pos = atoi(format) - 1;
582 gcc_assert (pos >= 0);
583 while (ISDIGIT(*format))
584 format++;
585 gcc_assert (*format == '$');
586 format++;
587 }
588 else
589 pos++;
590
591 c = *format++;
592
593 if (pos > maxpos)
594 maxpos = pos;
595
596 switch (c)
597 {
598 case 'C':
599 arg[pos].type = TYPE_CURRENTLOC;
600 break;
601
602 case 'L':
603 arg[pos].type = TYPE_LOCUS;
604 break;
605
606 case 'd':
607 case 'i':
608 arg[pos].type = TYPE_INTEGER;
609 break;
610
611 case 'u':
612 arg[pos].type = TYPE_UINTEGER;
613 break;
614
615 case 'l':
616 c = *format++;
617 if (c == 'u')
618 arg[pos].type = TYPE_ULONGINT;
619 else if (c == 'i' || c == 'd')
620 arg[pos].type = TYPE_LONGINT;
621 else
622 gcc_unreachable ();
623 break;
624
625 case 'c':
626 arg[pos].type = TYPE_CHAR;
627 break;
628
629 case 's':
630 arg[pos].type = TYPE_STRING;
631 break;
632
633 default:
634 gcc_unreachable ();
635 }
636
637 spec[n++].pos = pos;
638 }
639
640 /* Then convert the values for each %-style argument. */
641 for (pos = 0; pos <= maxpos; pos++)
642 {
643 gcc_assert (arg[pos].type != NOTYPE);
644 switch (arg[pos].type)
645 {
646 case TYPE_CURRENTLOC:
647 loc = &gfc_current_locus;
648 /* Fall through. */
649
650 case TYPE_LOCUS:
651 if (arg[pos].type == TYPE_LOCUS)
652 loc = va_arg (argp, locus *);
653
654 if (have_l1)
655 {
656 l2 = loc;
657 arg[pos].u.stringval = "(2)";
658 }
659 else
660 {
661 l1 = loc;
662 have_l1 = 1;
663 arg[pos].u.stringval = "(1)";
664 }
665 break;
666
667 case TYPE_INTEGER:
668 arg[pos].u.intval = va_arg (argp, int);
669 break;
670
671 case TYPE_UINTEGER:
672 arg[pos].u.uintval = va_arg (argp, unsigned int);
673 break;
674
675 case TYPE_LONGINT:
676 arg[pos].u.longintval = va_arg (argp, long int);
677 break;
678
679 case TYPE_ULONGINT:
680 arg[pos].u.ulongintval = va_arg (argp, unsigned long int);
681 break;
682
683 case TYPE_CHAR:
684 arg[pos].u.charval = (char) va_arg (argp, int);
685 break;
686
687 case TYPE_STRING:
688 arg[pos].u.stringval = (const char *) va_arg (argp, char *);
689 break;
690
691 default:
692 gcc_unreachable ();
693 }
694 }
695
696 for (n = 0; spec[n].pos >= 0; n++)
697 spec[n].u = arg[spec[n].pos].u;
698
699 /* Show the current loci if we have to. */
700 if (have_l1)
701 show_loci (l1, l2);
702
703 if (*type)
704 {
705 error_string (type);
706 error_char (' ');
707 }
708
709 have_l1 = 0;
710 format = format0;
711 n = 0;
712
713 for (; *format; format++)
714 {
715 if (*format != '%')
716 {
717 error_char (*format);
718 continue;
719 }
720
721 format++;
722 if (ISDIGIT (*format))
723 {
724 /* This is a position specifier. See comment above. */
725 while (ISDIGIT (*format))
726 format++;
727
728 /* Skip over the dollar sign. */
729 format++;
730 }
731
732 switch (*format)
733 {
734 case '%':
735 error_char ('%');
736 break;
737
738 case 'c':
739 error_char (spec[n++].u.charval);
740 break;
741
742 case 's':
743 case 'C': /* Current locus */
744 case 'L': /* Specified locus */
745 error_string (spec[n++].u.stringval);
746 break;
747
748 case 'd':
749 case 'i':
750 error_integer (spec[n++].u.intval);
751 break;
752
753 case 'u':
754 error_uinteger (spec[n++].u.uintval);
755 break;
756
757 case 'l':
758 format++;
759 if (*format == 'u')
760 error_uinteger (spec[n++].u.ulongintval);
761 else
762 error_integer (spec[n++].u.longintval);
763 break;
764
765 }
766 }
767
768 error_char ('\n');
769 }
770
771
772 /* Wrapper for error_print(). */
773
774 static void
775 error_printf (const char *gmsgid, ...)
776 {
777 va_list argp;
778
779 va_start (argp, gmsgid);
780 error_print ("", _(gmsgid), argp);
781 va_end (argp);
782 }
783
784
785 /* Increment the number of errors, and check whether too many have
786 been printed. */
787
788 static void
789 gfc_increment_error_count (void)
790 {
791 errors++;
792 if ((gfc_option.max_errors != 0) && (errors >= gfc_option.max_errors))
793 gfc_fatal_error ("Error count reached limit of %d.", gfc_option.max_errors);
794 }
795
796
797 /* Clear any output buffered in a pretty-print output_buffer. */
798
799 static void
800 gfc_clear_pp_buffer (output_buffer *this_buffer)
801 {
802 pretty_printer *pp = global_dc->printer;
803 output_buffer *tmp_buffer = pp->buffer;
804 pp->buffer = this_buffer;
805 pp_clear_output_area (pp);
806 pp->buffer = tmp_buffer;
807 }
808
809
810 /* This is just a helper function to avoid duplicating the logic of
811 gfc_warning. */
812
813 static bool
814 gfc_warning (int opt, const char *gmsgid, va_list ap)
815 {
816 va_list argp;
817 va_copy (argp, ap);
818
819 diagnostic_info diagnostic;
820 bool fatal_errors = global_dc->fatal_errors;
821 pretty_printer *pp = global_dc->printer;
822 output_buffer *tmp_buffer = pp->buffer;
823
824 gfc_clear_pp_buffer (pp_warning_buffer);
825
826 if (buffered_p)
827 {
828 pp->buffer = pp_warning_buffer;
829 global_dc->fatal_errors = false;
830 /* To prevent -fmax-errors= triggering. */
831 --werrorcount;
832 }
833
834 diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION,
835 DK_WARNING);
836 diagnostic.option_index = opt;
837 bool ret = report_diagnostic (&diagnostic);
838
839 if (buffered_p)
840 {
841 pp->buffer = tmp_buffer;
842 global_dc->fatal_errors = fatal_errors;
843
844 warningcount_buffered = 0;
845 werrorcount_buffered = 0;
846 /* Undo the above --werrorcount if not Werror, otherwise
847 werrorcount is correct already. */
848 if (!ret)
849 ++werrorcount;
850 else if (diagnostic.kind == DK_ERROR)
851 ++werrorcount_buffered;
852 else
853 ++werrorcount, --warningcount, ++warningcount_buffered;
854 }
855
856 va_end (argp);
857 return ret;
858 }
859
860 /* Issue a warning. */
861
862 bool
863 gfc_warning (int opt, const char *gmsgid, ...)
864 {
865 va_list argp;
866
867 va_start (argp, gmsgid);
868 bool ret = gfc_warning (opt, gmsgid, argp);
869 va_end (argp);
870 return ret;
871 }
872
873
874 /* Whether, for a feature included in a given standard set (GFC_STD_*),
875 we should issue an error or a warning, or be quiet. */
876
877 notification
878 gfc_notification_std (int std)
879 {
880 bool warning;
881
882 warning = ((gfc_option.warn_std & std) != 0) && !inhibit_warnings;
883 if ((gfc_option.allow_std & std) != 0 && !warning)
884 return SILENT;
885
886 return warning ? WARNING : ERROR;
887 }
888
889
890 /* Possibly issue a warning/error about use of a nonstandard (or deleted)
891 feature. An error/warning will be issued if the currently selected
892 standard does not contain the requested bits. Return false if
893 an error is generated. */
894
895 bool
896 gfc_notify_std (int std, const char *gmsgid, ...)
897 {
898 va_list argp;
899 bool warning;
900 const char *msg, *msg2;
901 char *buffer;
902
903 warning = ((gfc_option.warn_std & std) != 0) && !inhibit_warnings;
904 if ((gfc_option.allow_std & std) != 0 && !warning)
905 return true;
906
907 if (suppress_errors)
908 return warning ? true : false;
909
910 switch (std)
911 {
912 case GFC_STD_F2008_TS:
913 msg = "TS 29113/TS 18508:";
914 break;
915 case GFC_STD_F2008_OBS:
916 msg = _("Fortran 2008 obsolescent feature:");
917 break;
918 case GFC_STD_F2008:
919 msg = "Fortran 2008:";
920 break;
921 case GFC_STD_F2003:
922 msg = "Fortran 2003:";
923 break;
924 case GFC_STD_GNU:
925 msg = _("GNU Extension:");
926 break;
927 case GFC_STD_LEGACY:
928 msg = _("Legacy Extension:");
929 break;
930 case GFC_STD_F95_OBS:
931 msg = _("Obsolescent feature:");
932 break;
933 case GFC_STD_F95_DEL:
934 msg = _("Deleted feature:");
935 break;
936 default:
937 gcc_unreachable ();
938 }
939
940 msg2 = _(gmsgid);
941 buffer = (char *) alloca (strlen (msg) + strlen (msg2) + 2);
942 strcpy (buffer, msg);
943 strcat (buffer, " ");
944 strcat (buffer, msg2);
945
946 va_start (argp, gmsgid);
947 if (warning)
948 gfc_warning (0, buffer, argp);
949 else
950 gfc_error (buffer, argp);
951 va_end (argp);
952
953 return (warning && !warnings_are_errors) ? true : false;
954 }
955
956
957 /* Called from output_format -- during diagnostic message processing
958 to handle Fortran specific format specifiers with the following meanings:
959
960 %C Current locus (no argument)
961 %L Takes locus argument
962 */
963 static bool
964 gfc_format_decoder (pretty_printer *pp,
965 text_info *text, const char *spec,
966 int precision ATTRIBUTE_UNUSED, bool wide ATTRIBUTE_UNUSED,
967 bool plus ATTRIBUTE_UNUSED, bool hash ATTRIBUTE_UNUSED)
968 {
969 switch (*spec)
970 {
971 case 'C':
972 case 'L':
973 {
974 static const char *result[2] = { "(1)", "(2)" };
975 locus *loc;
976 if (*spec == 'C')
977 loc = &gfc_current_locus;
978 else
979 loc = va_arg (*text->args_ptr, locus *);
980 gcc_assert (loc->nextc - loc->lb->line >= 0);
981 unsigned int offset = loc->nextc - loc->lb->line;
982 /* If location[0] != UNKNOWN_LOCATION means that we already
983 processed one of %C/%L. */
984 int loc_num = text->get_location (0) == UNKNOWN_LOCATION ? 0 : 1;
985 text->set_location (loc_num,
986 linemap_position_for_loc_and_offset (line_table,
987 loc->lb->location,
988 offset));
989 pp_string (pp, result[loc_num]);
990 return true;
991 }
992 default:
993 return false;
994 }
995 }
996
997 /* Return a malloc'd string describing the kind of diagnostic. The
998 caller is responsible for freeing the memory. */
999 static char *
1000 gfc_diagnostic_build_kind_prefix (diagnostic_context *context,
1001 const diagnostic_info *diagnostic)
1002 {
1003 static const char *const diagnostic_kind_text[] = {
1004 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
1005 #include "gfc-diagnostic.def"
1006 #undef DEFINE_DIAGNOSTIC_KIND
1007 "must-not-happen"
1008 };
1009 static const char *const diagnostic_kind_color[] = {
1010 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C),
1011 #include "gfc-diagnostic.def"
1012 #undef DEFINE_DIAGNOSTIC_KIND
1013 NULL
1014 };
1015 gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
1016 const char *text = _(diagnostic_kind_text[diagnostic->kind]);
1017 const char *text_cs = "", *text_ce = "";
1018 pretty_printer *pp = context->printer;
1019
1020 if (diagnostic_kind_color[diagnostic->kind])
1021 {
1022 text_cs = colorize_start (pp_show_color (pp),
1023 diagnostic_kind_color[diagnostic->kind]);
1024 text_ce = colorize_stop (pp_show_color (pp));
1025 }
1026 return build_message_string ("%s%s:%s ", text_cs, text, text_ce);
1027 }
1028
1029 /* Return a malloc'd string describing a location. The caller is
1030 responsible for freeing the memory. */
1031 static char *
1032 gfc_diagnostic_build_locus_prefix (diagnostic_context *context,
1033 expanded_location s)
1034 {
1035 pretty_printer *pp = context->printer;
1036 const char *locus_cs = colorize_start (pp_show_color (pp), "locus");
1037 const char *locus_ce = colorize_stop (pp_show_color (pp));
1038 return (s.file == NULL
1039 ? build_message_string ("%s%s:%s", locus_cs, progname, locus_ce )
1040 : !strcmp (s.file, N_("<built-in>"))
1041 ? build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce)
1042 : context->show_column
1043 ? build_message_string ("%s%s:%d:%d:%s", locus_cs, s.file, s.line,
1044 s.column, locus_ce)
1045 : build_message_string ("%s%s:%d:%s", locus_cs, s.file, s.line, locus_ce));
1046 }
1047
1048 /* Return a malloc'd string describing two locations. The caller is
1049 responsible for freeing the memory. */
1050 static char *
1051 gfc_diagnostic_build_locus_prefix (diagnostic_context *context,
1052 expanded_location s, expanded_location s2)
1053 {
1054 pretty_printer *pp = context->printer;
1055 const char *locus_cs = colorize_start (pp_show_color (pp), "locus");
1056 const char *locus_ce = colorize_stop (pp_show_color (pp));
1057
1058 return (s.file == NULL
1059 ? build_message_string ("%s%s:%s", locus_cs, progname, locus_ce )
1060 : !strcmp (s.file, N_("<built-in>"))
1061 ? build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce)
1062 : context->show_column
1063 ? build_message_string ("%s%s:%d:%d-%d:%s", locus_cs, s.file, s.line,
1064 MIN (s.column, s2.column),
1065 MAX (s.column, s2.column), locus_ce)
1066 : build_message_string ("%s%s:%d:%s", locus_cs, s.file, s.line,
1067 locus_ce));
1068 }
1069
1070 /* This function prints the locus (file:line:column), the diagnostic kind
1071 (Error, Warning) and (optionally) the caret line (a source line
1072 with '1' and/or '2' below it).
1073
1074 With -fdiagnostic-show-caret (the default) and for valid locations,
1075 it prints for one location:
1076
1077 [locus]:
1078
1079 some code
1080 1
1081 Error: Some error at (1)
1082
1083 for two locations that fit in the same locus line:
1084
1085 [locus]:
1086
1087 some code and some more code
1088 1 2
1089 Error: Some error at (1) and (2)
1090
1091 and for two locations that do not fit in the same locus line:
1092
1093 [locus]:
1094
1095 some code
1096 1
1097 [locus2]:
1098
1099 some other code
1100 2
1101 Error: Some error at (1) and (2)
1102
1103 With -fno-diagnostic-show-caret or if one of the locations is not
1104 valid, it prints for one location (or for two locations that fit in
1105 the same locus line):
1106
1107 [locus]: Error: Some error at (1) and (2)
1108
1109 and for two locations that do not fit in the same locus line:
1110
1111 [name]:[locus]: Error: (1)
1112 [name]:[locus2]: Error: Some error at (1) and (2)
1113 */
1114 static void
1115 gfc_diagnostic_starter (diagnostic_context *context,
1116 diagnostic_info *diagnostic)
1117 {
1118 char * kind_prefix = gfc_diagnostic_build_kind_prefix (context, diagnostic);
1119
1120 expanded_location s1 = diagnostic_expand_location (diagnostic);
1121 expanded_location s2;
1122 bool one_locus = diagnostic_location (diagnostic, 1) == UNKNOWN_LOCATION;
1123 bool same_locus = false;
1124
1125 if (!one_locus)
1126 {
1127 s2 = diagnostic_expand_location (diagnostic, 1);
1128 same_locus = diagnostic_same_line (context, s1, s2);
1129 }
1130
1131 char * locus_prefix = (one_locus || !same_locus)
1132 ? gfc_diagnostic_build_locus_prefix (context, s1)
1133 : gfc_diagnostic_build_locus_prefix (context, s1, s2);
1134
1135 if (!context->show_caret
1136 || diagnostic_location (diagnostic, 0) <= BUILTINS_LOCATION
1137 || diagnostic_location (diagnostic, 0) == context->last_location)
1138 {
1139 pp_set_prefix (context->printer,
1140 concat (locus_prefix, " ", kind_prefix, NULL));
1141 free (locus_prefix);
1142
1143 if (one_locus || same_locus)
1144 {
1145 free (kind_prefix);
1146 return;
1147 }
1148 /* In this case, we print the previous locus and prefix as:
1149
1150 [locus]:[prefix]: (1)
1151
1152 and we flush with a new line before setting the new prefix. */
1153 pp_string (context->printer, "(1)");
1154 pp_newline (context->printer);
1155 locus_prefix = gfc_diagnostic_build_locus_prefix (context, s2);
1156 pp_set_prefix (context->printer,
1157 concat (locus_prefix, " ", kind_prefix, NULL));
1158 free (kind_prefix);
1159 free (locus_prefix);
1160 }
1161 else
1162 {
1163 pp_verbatim (context->printer, locus_prefix);
1164 free (locus_prefix);
1165 /* Fortran uses an empty line between locus and caret line. */
1166 pp_newline (context->printer);
1167 diagnostic_show_locus (context, diagnostic);
1168 pp_newline (context->printer);
1169 /* If the caret line was shown, the prefix does not contain the
1170 locus. */
1171 pp_set_prefix (context->printer, kind_prefix);
1172
1173 if (one_locus || same_locus)
1174 return;
1175
1176 locus_prefix = gfc_diagnostic_build_locus_prefix (context, s2);
1177 if (diagnostic_location (diagnostic, 1) <= BUILTINS_LOCATION)
1178 {
1179 /* No caret line for the second location. Override the previous
1180 prefix with [locus2]:[prefix]. */
1181 pp_set_prefix (context->printer,
1182 concat (locus_prefix, " ", kind_prefix, NULL));
1183 free (kind_prefix);
1184 free (locus_prefix);
1185 }
1186 else
1187 {
1188 /* We print the caret for the second location. */
1189 pp_verbatim (context->printer, locus_prefix);
1190 free (locus_prefix);
1191 /* Fortran uses an empty line between locus and caret line. */
1192 pp_newline (context->printer);
1193 s1.column = 0; /* Print only a caret line for s2. */
1194 diagnostic_print_caret_line (context, s2, s1,
1195 context->caret_chars[1], '\0');
1196 pp_newline (context->printer);
1197 /* If the caret line was shown, the prefix does not contain the
1198 locus. */
1199 pp_set_prefix (context->printer, kind_prefix);
1200 }
1201 }
1202 }
1203
1204 static void
1205 gfc_diagnostic_finalizer (diagnostic_context *context,
1206 diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
1207 {
1208 pp_destroy_prefix (context->printer);
1209 pp_newline_and_flush (context->printer);
1210 }
1211
1212 /* Immediate warning (i.e. do not buffer the warning) with an explicit
1213 location. */
1214
1215 bool
1216 gfc_warning_now_at (location_t loc, int opt, const char *gmsgid, ...)
1217 {
1218 va_list argp;
1219 diagnostic_info diagnostic;
1220 bool ret;
1221
1222 va_start (argp, gmsgid);
1223 diagnostic_set_info (&diagnostic, gmsgid, &argp, loc, DK_WARNING);
1224 diagnostic.option_index = opt;
1225 ret = report_diagnostic (&diagnostic);
1226 va_end (argp);
1227 return ret;
1228 }
1229
1230 /* Immediate warning (i.e. do not buffer the warning). */
1231
1232 bool
1233 gfc_warning_now (int opt, const char *gmsgid, ...)
1234 {
1235 va_list argp;
1236 diagnostic_info diagnostic;
1237 bool ret;
1238
1239 va_start (argp, gmsgid);
1240 diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION,
1241 DK_WARNING);
1242 diagnostic.option_index = opt;
1243 ret = report_diagnostic (&diagnostic);
1244 va_end (argp);
1245 return ret;
1246 }
1247
1248
1249 /* Immediate error (i.e. do not buffer). */
1250 /* This function uses the common diagnostics, but does not support
1251 two locations; when being used in scanner.c, ensure that the location
1252 is properly setup. Otherwise, use gfc_error_now_1. */
1253
1254 void
1255 gfc_error_now (const char *gmsgid, ...)
1256 {
1257 va_list argp;
1258 diagnostic_info diagnostic;
1259
1260 va_start (argp, gmsgid);
1261 diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, DK_ERROR);
1262 report_diagnostic (&diagnostic);
1263 va_end (argp);
1264 }
1265
1266
1267 /* Fatal error, never returns. */
1268
1269 void
1270 gfc_fatal_error (const char *gmsgid, ...)
1271 {
1272 va_list argp;
1273 diagnostic_info diagnostic;
1274
1275 va_start (argp, gmsgid);
1276 diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, DK_FATAL);
1277 report_diagnostic (&diagnostic);
1278 va_end (argp);
1279
1280 gcc_unreachable ();
1281 }
1282
1283 /* Clear the warning flag. */
1284
1285 void
1286 gfc_clear_warning (void)
1287 {
1288 warning_buffer.flag = 0;
1289
1290 gfc_clear_pp_buffer (pp_warning_buffer);
1291 warningcount_buffered = 0;
1292 werrorcount_buffered = 0;
1293 }
1294
1295
1296 /* Check to see if any warnings have been saved.
1297 If so, print the warning. */
1298
1299 void
1300 gfc_warning_check (void)
1301 {
1302 if (warning_buffer.flag)
1303 {
1304 warnings++;
1305 if (warning_buffer.message != NULL)
1306 fputs (warning_buffer.message, stderr);
1307 gfc_clear_warning ();
1308 }
1309 /* This is for the new diagnostics machinery. */
1310 else if (! gfc_output_buffer_empty_p (pp_warning_buffer))
1311 {
1312 pretty_printer *pp = global_dc->printer;
1313 output_buffer *tmp_buffer = pp->buffer;
1314 pp->buffer = pp_warning_buffer;
1315 pp_really_flush (pp);
1316 warningcount += warningcount_buffered;
1317 werrorcount += werrorcount_buffered;
1318 gcc_assert (warningcount_buffered + werrorcount_buffered == 1);
1319 diagnostic_action_after_output (global_dc,
1320 warningcount_buffered
1321 ? DK_WARNING : DK_ERROR);
1322 pp->buffer = tmp_buffer;
1323 }
1324 }
1325
1326
1327 /* Issue an error. */
1328 /* Use gfc_error instead, unless two locations are used in the same
1329 warning or for scanner.c, if the location is not properly set up. */
1330
1331 void
1332 gfc_error_1 (const char *gmsgid, ...)
1333 {
1334 va_list argp;
1335
1336 if (warnings_not_errors)
1337 goto warning;
1338
1339 if (suppress_errors)
1340 return;
1341
1342 error_buffer.flag = 1;
1343 error_buffer.index = 0;
1344 cur_error_buffer = &error_buffer;
1345
1346 va_start (argp, gmsgid);
1347 error_print (_("Error:"), _(gmsgid), argp);
1348 va_end (argp);
1349
1350 error_char ('\0');
1351
1352 if (!buffered_p)
1353 gfc_increment_error_count();
1354
1355 return;
1356
1357 warning:
1358
1359 if (inhibit_warnings)
1360 return;
1361
1362 warning_buffer.flag = 1;
1363 warning_buffer.index = 0;
1364 cur_error_buffer = &warning_buffer;
1365
1366 va_start (argp, gmsgid);
1367 error_print (_("Warning:"), _(gmsgid), argp);
1368 va_end (argp);
1369
1370 error_char ('\0');
1371
1372 if (!buffered_p)
1373 {
1374 warnings++;
1375 if (warnings_are_errors)
1376 gfc_increment_error_count();
1377 }
1378 }
1379
1380 /* Issue an error. */
1381 /* This function uses the common diagnostics, but does not support
1382 two locations; when being used in scanner.c, ensure that the location
1383 is properly setup. Otherwise, use gfc_error_1. */
1384
1385 static void
1386 gfc_error (const char *gmsgid, va_list ap)
1387 {
1388 va_list argp;
1389 va_copy (argp, ap);
1390
1391 if (warnings_not_errors)
1392 {
1393 gfc_warning (/*opt=*/0, gmsgid, argp);
1394 va_end (argp);
1395 return;
1396 }
1397
1398 if (suppress_errors)
1399 {
1400 va_end (argp);
1401 return;
1402 }
1403
1404 diagnostic_info diagnostic;
1405 bool fatal_errors = global_dc->fatal_errors;
1406 pretty_printer *pp = global_dc->printer;
1407 output_buffer *tmp_buffer = pp->buffer;
1408
1409 gfc_clear_pp_buffer (pp_error_buffer);
1410
1411 if (buffered_p)
1412 {
1413 pp->buffer = pp_error_buffer;
1414 global_dc->fatal_errors = false;
1415 /* To prevent -fmax-errors= triggering, we decrease it before
1416 report_diagnostic increases it. */
1417 --errorcount;
1418 }
1419
1420 diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, DK_ERROR);
1421 report_diagnostic (&diagnostic);
1422
1423 if (buffered_p)
1424 {
1425 pp->buffer = tmp_buffer;
1426 global_dc->fatal_errors = fatal_errors;
1427 }
1428
1429 va_end (argp);
1430 }
1431
1432
1433 void
1434 gfc_error (const char *gmsgid, ...)
1435 {
1436 va_list argp;
1437 va_start (argp, gmsgid);
1438 gfc_error (gmsgid, argp);
1439 va_end (argp);
1440 }
1441
1442
1443 /* Immediate error. */
1444 /* Use gfc_error_now instead, unless two locations are used in the same
1445 warning or for scanner.c, if the location is not properly set up. */
1446
1447 void
1448 gfc_error_now_1 (const char *gmsgid, ...)
1449 {
1450 va_list argp;
1451 bool buffered_p_saved;
1452
1453 error_buffer.flag = 1;
1454 error_buffer.index = 0;
1455 cur_error_buffer = &error_buffer;
1456
1457 buffered_p_saved = buffered_p;
1458 buffered_p = false;
1459
1460 va_start (argp, gmsgid);
1461 error_print (_("Error:"), _(gmsgid), argp);
1462 va_end (argp);
1463
1464 error_char ('\0');
1465
1466 gfc_increment_error_count();
1467
1468 buffered_p = buffered_p_saved;
1469
1470 if (flag_fatal_errors)
1471 exit (FATAL_EXIT_CODE);
1472 }
1473
1474
1475 /* This shouldn't happen... but sometimes does. */
1476
1477 void
1478 gfc_internal_error (const char *gmsgid, ...)
1479 {
1480 va_list argp;
1481 diagnostic_info diagnostic;
1482
1483 va_start (argp, gmsgid);
1484 diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, DK_ICE);
1485 report_diagnostic (&diagnostic);
1486 va_end (argp);
1487
1488 gcc_unreachable ();
1489 }
1490
1491
1492 /* Clear the error flag when we start to compile a source line. */
1493
1494 void
1495 gfc_clear_error (void)
1496 {
1497 error_buffer.flag = 0;
1498 warnings_not_errors = false;
1499 gfc_clear_pp_buffer (pp_error_buffer);
1500 }
1501
1502
1503 /* Tests the state of error_flag. */
1504
1505 bool
1506 gfc_error_flag_test (void)
1507 {
1508 return error_buffer.flag
1509 || !gfc_output_buffer_empty_p (pp_error_buffer);
1510 }
1511
1512
1513 /* Check to see if any errors have been saved.
1514 If so, print the error. Returns the state of error_flag. */
1515
1516 bool
1517 gfc_error_check (void)
1518 {
1519 bool error_raised = (bool) error_buffer.flag;
1520
1521 if (error_raised)
1522 {
1523 if (error_buffer.message != NULL)
1524 fputs (error_buffer.message, stderr);
1525 error_buffer.flag = 0;
1526 gfc_clear_pp_buffer (pp_error_buffer);
1527
1528 gfc_increment_error_count();
1529
1530 if (flag_fatal_errors)
1531 exit (FATAL_EXIT_CODE);
1532 }
1533 /* This is for the new diagnostics machinery. */
1534 else if (! gfc_output_buffer_empty_p (pp_error_buffer))
1535 {
1536 error_raised = true;
1537 pretty_printer *pp = global_dc->printer;
1538 output_buffer *tmp_buffer = pp->buffer;
1539 pp->buffer = pp_error_buffer;
1540 pp_really_flush (pp);
1541 ++errorcount;
1542 gcc_assert (gfc_output_buffer_empty_p (pp_error_buffer));
1543 diagnostic_action_after_output (global_dc, DK_ERROR);
1544 pp->buffer = tmp_buffer;
1545 }
1546
1547 return error_raised;
1548 }
1549
1550 /* Move the text buffered from FROM to TO, then clear
1551 FROM. Independently if there was text in FROM, TO is also
1552 cleared. */
1553
1554 static void
1555 gfc_move_output_buffer_from_to (output_buffer *from, output_buffer *to)
1556 {
1557 gfc_clear_pp_buffer (to);
1558 /* We make sure this is always buffered. */
1559 to->flush_p = false;
1560
1561 if (! gfc_output_buffer_empty_p (from))
1562 {
1563 const char *str = output_buffer_formatted_text (from);
1564 output_buffer_append_r (to, str, strlen (str));
1565 gfc_clear_pp_buffer (from);
1566 }
1567 }
1568
1569 /* Save the existing error state. */
1570
1571 void
1572 gfc_push_error (output_buffer *buffer_err, gfc_error_buf *err)
1573 {
1574 err->flag = error_buffer.flag;
1575 if (error_buffer.flag)
1576 err->message = xstrdup (error_buffer.message);
1577
1578 error_buffer.flag = 0;
1579
1580 /* This part uses the common diagnostics. */
1581 gfc_move_output_buffer_from_to (pp_error_buffer, buffer_err);
1582 }
1583
1584
1585 /* Restore a previous pushed error state. */
1586
1587 void
1588 gfc_pop_error (output_buffer *buffer_err, gfc_error_buf *err)
1589 {
1590 error_buffer.flag = err->flag;
1591 if (error_buffer.flag)
1592 {
1593 size_t len = strlen (err->message) + 1;
1594 gcc_assert (len <= error_buffer.allocated);
1595 memcpy (error_buffer.message, err->message, len);
1596 free (err->message);
1597 }
1598 /* This part uses the common diagnostics. */
1599 gfc_move_output_buffer_from_to (buffer_err, pp_error_buffer);
1600 }
1601
1602
1603 /* Free a pushed error state, but keep the current error state. */
1604
1605 void
1606 gfc_free_error (output_buffer *buffer_err, gfc_error_buf *err)
1607 {
1608 if (err->flag)
1609 free (err->message);
1610
1611 gfc_clear_pp_buffer (buffer_err);
1612 }
1613
1614
1615 /* Report the number of warnings and errors that occurred to the caller. */
1616
1617 void
1618 gfc_get_errors (int *w, int *e)
1619 {
1620 if (w != NULL)
1621 *w = warnings + warningcount + werrorcount;
1622 if (e != NULL)
1623 *e = errors + errorcount + sorrycount + werrorcount;
1624 }
1625
1626
1627 /* Switch errors into warnings. */
1628
1629 void
1630 gfc_errors_to_warnings (bool f)
1631 {
1632 warnings_not_errors = f;
1633 }
1634
1635 void
1636 gfc_diagnostics_init (void)
1637 {
1638 diagnostic_starter (global_dc) = gfc_diagnostic_starter;
1639 diagnostic_finalizer (global_dc) = gfc_diagnostic_finalizer;
1640 diagnostic_format_decoder (global_dc) = gfc_format_decoder;
1641 global_dc->caret_chars[0] = '1';
1642 global_dc->caret_chars[1] = '2';
1643 pp_warning_buffer = new (XNEW (output_buffer)) output_buffer ();
1644 pp_warning_buffer->flush_p = false;
1645 pp_error_buffer = new (XNEW (output_buffer)) output_buffer ();
1646 pp_error_buffer->flush_p = false;
1647 }
1648
1649 void
1650 gfc_diagnostics_finish (void)
1651 {
1652 tree_diagnostics_defaults (global_dc);
1653 /* We still want to use the gfc starter and finalizer, not the tree
1654 defaults. */
1655 diagnostic_starter (global_dc) = gfc_diagnostic_starter;
1656 diagnostic_finalizer (global_dc) = gfc_diagnostic_finalizer;
1657 global_dc->caret_chars[0] = '^';
1658 global_dc->caret_chars[1] = '^';
1659 }