annotate gcc/diagnostic.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Language-independent diagnostic subroutines for the GNU Compiler Collection
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 1999-2020 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 /* This file implements the language independent aspect of diagnostic
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 message module. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "coretypes.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "version.h"
111
kono
parents: 67
diff changeset
29 #include "demangle.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #include "intl.h"
111
kono
parents: 67
diff changeset
31 #include "backtrace.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 #include "diagnostic.h"
111
kono
parents: 67
diff changeset
33 #include "diagnostic-color.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
34 #include "diagnostic-url.h"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
35 #include "diagnostic-metadata.h"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
36 #include "diagnostic-path.h"
111
kono
parents: 67
diff changeset
37 #include "edit-context.h"
kono
parents: 67
diff changeset
38 #include "selftest.h"
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
39 #include "selftest-diagnostic.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
40 #include "opts.h"
111
kono
parents: 67
diff changeset
41
kono
parents: 67
diff changeset
42 #ifdef HAVE_TERMIOS_H
kono
parents: 67
diff changeset
43 # include <termios.h>
kono
parents: 67
diff changeset
44 #endif
kono
parents: 67
diff changeset
45
kono
parents: 67
diff changeset
46 #ifdef GWINSZ_IN_SYS_IOCTL
kono
parents: 67
diff changeset
47 # include <sys/ioctl.h>
kono
parents: 67
diff changeset
48 #endif
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
50 /* Disable warnings about quoting issues in the pp_xxx calls below
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
51 that (intentionally) don't follow GCC diagnostic conventions. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
52 #if __GNUC__ >= 10
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
53 # pragma GCC diagnostic push
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
54 # pragma GCC diagnostic ignored "-Wformat-diag"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
55 #endif
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
56
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
57 #define pedantic_warning_kind(DC) \
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
58 ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
59 #define permissive_error_kind(DC) ((DC)->permissive ? DK_WARNING : DK_ERROR)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
60 #define permissive_error_option(DC) ((DC)->opt_permissive)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 /* Prototypes. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
63 static bool diagnostic_impl (rich_location *, const diagnostic_metadata *,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
64 int, const char *,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
65 va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(4,0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
66 static bool diagnostic_n_impl (rich_location *, const diagnostic_metadata *,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
67 int, unsigned HOST_WIDE_INT,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
68 const char *, const char *, va_list *,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
69 diagnostic_t) ATTRIBUTE_GCC_DIAG(6,0);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 static void real_abort (void) ATTRIBUTE_NORETURN;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
74 /* Name of program invoked, sans directories. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
75
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
76 const char *progname;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
77
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 /* A diagnostic_context surrogate for stderr. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 static diagnostic_context global_diagnostic_context;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 diagnostic_context *global_dc = &global_diagnostic_context;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 /* Return a malloc'd string containing MSG formatted a la printf. The
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 caller is responsible for freeing the memory. */
111
kono
parents: 67
diff changeset
84 char *
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 build_message_string (const char *msg, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 char *str;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 va_start (ap, msg);
111
kono
parents: 67
diff changeset
91 str = xvasprintf (msg, ap);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 return str;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 /* Same as diagnostic_build_prefix, but only the source FILE is given. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 char *
111
kono
parents: 67
diff changeset
99 file_name_as_prefix (diagnostic_context *context, const char *f)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 {
111
kono
parents: 67
diff changeset
101 const char *locus_cs
kono
parents: 67
diff changeset
102 = colorize_start (pp_show_color (context->printer), "locus");
kono
parents: 67
diff changeset
103 const char *locus_ce = colorize_stop (pp_show_color (context->printer));
kono
parents: 67
diff changeset
104 return build_message_string ("%s%s:%s ", locus_cs, f, locus_ce);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108
111
kono
parents: 67
diff changeset
109 /* Return the value of the getenv("COLUMNS") as an integer. If the
kono
parents: 67
diff changeset
110 value is not set to a positive integer, use ioctl to get the
kono
parents: 67
diff changeset
111 terminal width. If it fails, return INT_MAX. */
kono
parents: 67
diff changeset
112 int
kono
parents: 67
diff changeset
113 get_terminal_width (void)
kono
parents: 67
diff changeset
114 {
kono
parents: 67
diff changeset
115 const char * s = getenv ("COLUMNS");
kono
parents: 67
diff changeset
116 if (s != NULL) {
kono
parents: 67
diff changeset
117 int n = atoi (s);
kono
parents: 67
diff changeset
118 if (n > 0)
kono
parents: 67
diff changeset
119 return n;
kono
parents: 67
diff changeset
120 }
kono
parents: 67
diff changeset
121
kono
parents: 67
diff changeset
122 #ifdef TIOCGWINSZ
kono
parents: 67
diff changeset
123 struct winsize w;
kono
parents: 67
diff changeset
124 w.ws_col = 0;
kono
parents: 67
diff changeset
125 if (ioctl (0, TIOCGWINSZ, &w) == 0 && w.ws_col > 0)
kono
parents: 67
diff changeset
126 return w.ws_col;
kono
parents: 67
diff changeset
127 #endif
kono
parents: 67
diff changeset
128
kono
parents: 67
diff changeset
129 return INT_MAX;
kono
parents: 67
diff changeset
130 }
kono
parents: 67
diff changeset
131
kono
parents: 67
diff changeset
132 /* Set caret_max_width to value. */
kono
parents: 67
diff changeset
133 void
kono
parents: 67
diff changeset
134 diagnostic_set_caret_max_width (diagnostic_context *context, int value)
kono
parents: 67
diff changeset
135 {
kono
parents: 67
diff changeset
136 /* One minus to account for the leading empty space. */
kono
parents: 67
diff changeset
137 value = value ? value - 1
kono
parents: 67
diff changeset
138 : (isatty (fileno (pp_buffer (context->printer)->stream))
kono
parents: 67
diff changeset
139 ? get_terminal_width () - 1: INT_MAX);
kono
parents: 67
diff changeset
140
kono
parents: 67
diff changeset
141 if (value <= 0)
kono
parents: 67
diff changeset
142 value = INT_MAX;
kono
parents: 67
diff changeset
143
kono
parents: 67
diff changeset
144 context->caret_max_width = value;
kono
parents: 67
diff changeset
145 }
kono
parents: 67
diff changeset
146
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
147 /* Default implementation of final_cb. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
148
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
149 static void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
150 default_diagnostic_final_cb (diagnostic_context *context)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
151 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
152 /* Some of the errors may actually have been warnings. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
153 if (diagnostic_kind_count (context, DK_WERROR))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
154 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
155 /* -Werror was given. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
156 if (context->warning_as_error_requested)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
157 pp_verbatim (context->printer,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
158 _("%s: all warnings being treated as errors"),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
159 progname);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
160 /* At least one -Werror= was given. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
161 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
162 pp_verbatim (context->printer,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
163 _("%s: some warnings being treated as errors"),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
164 progname);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
165 pp_newline_and_flush (context->printer);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
166 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
167 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
168
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 /* Initialize the diagnostic message outputting machinery. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 void
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
171 diagnostic_initialize (diagnostic_context *context, int n_opts)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
173 int i;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
174
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 /* Allocate a basic pretty-printer. Clients will replace this a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 much more elaborated pretty-printer if they wish. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 context->printer = XNEW (pretty_printer);
111
kono
parents: 67
diff changeset
178 new (context->printer) pretty_printer ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 context->warning_as_error_requested = false;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
182 context->n_opts = n_opts;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
183 context->classify_diagnostic = XNEWVEC (diagnostic_t, n_opts);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
184 for (i = 0; i < n_opts; i++)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
185 context->classify_diagnostic[i] = DK_UNSPECIFIED;
111
kono
parents: 67
diff changeset
186 context->show_caret = false;
kono
parents: 67
diff changeset
187 diagnostic_set_caret_max_width (context, pp_line_cutoff (context->printer));
kono
parents: 67
diff changeset
188 for (i = 0; i < rich_location::STATICALLY_ALLOCATED_RANGES; i++)
kono
parents: 67
diff changeset
189 context->caret_chars[i] = '^';
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
190 context->show_cwe = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
191 context->path_format = DPF_NONE;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
192 context->show_path_depths = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 context->show_option_requested = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 context->abort_on_error = false;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
195 context->show_column = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
196 context->pedantic_errors = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
197 context->permissive = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
198 context->opt_permissive = 0;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
199 context->fatal_errors = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
200 context->dc_inhibit_warnings = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
201 context->dc_warn_system_headers = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
202 context->max_errors = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 context->internal_error = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 diagnostic_starter (context) = default_diagnostic_starter;
111
kono
parents: 67
diff changeset
205 context->start_span = default_diagnostic_start_span_fn;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 diagnostic_finalizer (context) = default_diagnostic_finalizer;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
207 context->option_enabled = NULL;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
208 context->option_state = NULL;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
209 context->option_name = NULL;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
210 context->get_option_url = NULL;
111
kono
parents: 67
diff changeset
211 context->last_location = UNKNOWN_LOCATION;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 context->last_module = 0;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
213 context->x_data = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 context->lock = 0;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
215 context->inhibit_notes_p = false;
111
kono
parents: 67
diff changeset
216 context->colorize_source_p = false;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
217 context->show_labels_p = false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
218 context->show_line_numbers_p = false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
219 context->min_margin_width = 0;
111
kono
parents: 67
diff changeset
220 context->show_ruler_p = false;
kono
parents: 67
diff changeset
221 context->parseable_fixits_p = false;
kono
parents: 67
diff changeset
222 context->edit_context_ptr = NULL;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
223 context->diagnostic_group_nesting_depth = 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
224 context->diagnostic_group_emission_count = 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
225 context->begin_group_cb = NULL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
226 context->end_group_cb = NULL;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
227 context->final_cb = default_diagnostic_final_cb;
111
kono
parents: 67
diff changeset
228 }
kono
parents: 67
diff changeset
229
kono
parents: 67
diff changeset
230 /* Maybe initialize the color support. We require clients to do this
kono
parents: 67
diff changeset
231 explicitly, since most clients don't want color. When called
kono
parents: 67
diff changeset
232 without a VALUE, it initializes with DIAGNOSTICS_COLOR_DEFAULT. */
kono
parents: 67
diff changeset
233
kono
parents: 67
diff changeset
234 void
kono
parents: 67
diff changeset
235 diagnostic_color_init (diagnostic_context *context, int value /*= -1 */)
kono
parents: 67
diff changeset
236 {
kono
parents: 67
diff changeset
237 /* value == -1 is the default value. */
kono
parents: 67
diff changeset
238 if (value < 0)
kono
parents: 67
diff changeset
239 {
kono
parents: 67
diff changeset
240 /* If DIAGNOSTICS_COLOR_DEFAULT is -1, default to
kono
parents: 67
diff changeset
241 -fdiagnostics-color=auto if GCC_COLORS is in the environment,
kono
parents: 67
diff changeset
242 otherwise default to -fdiagnostics-color=never, for other
kono
parents: 67
diff changeset
243 values default to that
kono
parents: 67
diff changeset
244 -fdiagnostics-color={never,auto,always}. */
kono
parents: 67
diff changeset
245 if (DIAGNOSTICS_COLOR_DEFAULT == -1)
kono
parents: 67
diff changeset
246 {
kono
parents: 67
diff changeset
247 if (!getenv ("GCC_COLORS"))
kono
parents: 67
diff changeset
248 return;
kono
parents: 67
diff changeset
249 value = DIAGNOSTICS_COLOR_AUTO;
kono
parents: 67
diff changeset
250 }
kono
parents: 67
diff changeset
251 else
kono
parents: 67
diff changeset
252 value = DIAGNOSTICS_COLOR_DEFAULT;
kono
parents: 67
diff changeset
253 }
kono
parents: 67
diff changeset
254 pp_show_color (context->printer)
kono
parents: 67
diff changeset
255 = colorize_init ((diagnostic_color_rule_t) value);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
256 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
257
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
258 /* Initialize URL support within CONTEXT based on VALUE, handling "auto". */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
259
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
260 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
261 diagnostic_urls_init (diagnostic_context *context, int value /*= -1 */)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
262 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
263 if (value < 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
264 value = DIAGNOSTICS_COLOR_DEFAULT;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
265
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
266 context->printer->show_urls
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
267 = diagnostic_urls_enabled_p ((diagnostic_url_rule_t) value);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
268 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
269
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
270 /* Do any cleaning up required after the last diagnostic is emitted. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
271
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
272 void
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
273 diagnostic_finish (diagnostic_context *context)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
274 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
275 if (context->final_cb)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
276 context->final_cb (context);
111
kono
parents: 67
diff changeset
277
kono
parents: 67
diff changeset
278 diagnostic_file_cache_fini ();
kono
parents: 67
diff changeset
279
kono
parents: 67
diff changeset
280 XDELETEVEC (context->classify_diagnostic);
kono
parents: 67
diff changeset
281 context->classify_diagnostic = NULL;
kono
parents: 67
diff changeset
282
kono
parents: 67
diff changeset
283 /* diagnostic_initialize allocates context->printer using XNEW
kono
parents: 67
diff changeset
284 and placement-new. */
kono
parents: 67
diff changeset
285 context->printer->~pretty_printer ();
kono
parents: 67
diff changeset
286 XDELETE (context->printer);
kono
parents: 67
diff changeset
287 context->printer = NULL;
kono
parents: 67
diff changeset
288
kono
parents: 67
diff changeset
289 if (context->edit_context_ptr)
kono
parents: 67
diff changeset
290 {
kono
parents: 67
diff changeset
291 delete context->edit_context_ptr;
kono
parents: 67
diff changeset
292 context->edit_context_ptr = NULL;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
293 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 /* Initialize DIAGNOSTIC, where the message MSG has already been
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 translated. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
111
kono
parents: 67
diff changeset
300 va_list *args, rich_location *richloc,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 diagnostic_t kind)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 {
111
kono
parents: 67
diff changeset
303 gcc_assert (richloc);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 diagnostic->message.err_no = errno;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 diagnostic->message.args_ptr = args;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 diagnostic->message.format_spec = msg;
111
kono
parents: 67
diff changeset
307 diagnostic->message.m_richloc = richloc;
kono
parents: 67
diff changeset
308 diagnostic->richloc = richloc;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
309 diagnostic->metadata = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 diagnostic->kind = kind;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 diagnostic->option_index = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 /* Initialize DIAGNOSTIC, where the message GMSGID has not yet been
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 translated. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid,
111
kono
parents: 67
diff changeset
318 va_list *args, rich_location *richloc,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 diagnostic_t kind)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 {
111
kono
parents: 67
diff changeset
321 gcc_assert (richloc);
kono
parents: 67
diff changeset
322 diagnostic_set_info_translated (diagnostic, _(gmsgid), args, richloc, kind);
kono
parents: 67
diff changeset
323 }
kono
parents: 67
diff changeset
324
kono
parents: 67
diff changeset
325 static const char *const diagnostic_kind_color[] = {
kono
parents: 67
diff changeset
326 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C),
kono
parents: 67
diff changeset
327 #include "diagnostic.def"
kono
parents: 67
diff changeset
328 #undef DEFINE_DIAGNOSTIC_KIND
kono
parents: 67
diff changeset
329 NULL
kono
parents: 67
diff changeset
330 };
kono
parents: 67
diff changeset
331
kono
parents: 67
diff changeset
332 /* Get a color name for diagnostics of type KIND
kono
parents: 67
diff changeset
333 Result could be NULL. */
kono
parents: 67
diff changeset
334
kono
parents: 67
diff changeset
335 const char *
kono
parents: 67
diff changeset
336 diagnostic_get_color_for_kind (diagnostic_t kind)
kono
parents: 67
diff changeset
337 {
kono
parents: 67
diff changeset
338 return diagnostic_kind_color[kind];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
341 /* Return a formatted line and column ':%line:%column'. Elided if
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
342 zero. The result is a statically allocated buffer. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
343
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
344 static const char *
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
345 maybe_line_and_column (int line, int col)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
346 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
347 static char result[32];
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
348
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
349 if (line)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
350 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
351 size_t l = snprintf (result, sizeof (result),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
352 col ? ":%d:%d" : ":%d", line, col);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
353 gcc_checking_assert (l < sizeof (result));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
354 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
355 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
356 result[0] = 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
357 return result;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
358 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
359
111
kono
parents: 67
diff changeset
360 /* Return a malloc'd string describing a location e.g. "foo.c:42:10".
kono
parents: 67
diff changeset
361 The caller is responsible for freeing the memory. */
kono
parents: 67
diff changeset
362
kono
parents: 67
diff changeset
363 static char *
kono
parents: 67
diff changeset
364 diagnostic_get_location_text (diagnostic_context *context,
kono
parents: 67
diff changeset
365 expanded_location s)
kono
parents: 67
diff changeset
366 {
kono
parents: 67
diff changeset
367 pretty_printer *pp = context->printer;
kono
parents: 67
diff changeset
368 const char *locus_cs = colorize_start (pp_show_color (pp), "locus");
kono
parents: 67
diff changeset
369 const char *locus_ce = colorize_stop (pp_show_color (pp));
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
370 const char *file = s.file ? s.file : progname;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
371 int line = strcmp (file, N_("<built-in>")) ? s.line : 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
372 int col = context->show_column ? s.column : 0;
111
kono
parents: 67
diff changeset
373
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
374 const char *line_col = maybe_line_and_column (line, col);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
375 return build_message_string ("%s%s%s:%s", locus_cs, file,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
376 line_col, locus_ce);
111
kono
parents: 67
diff changeset
377 }
kono
parents: 67
diff changeset
378
kono
parents: 67
diff changeset
379 /* Return a malloc'd string describing a location and the severity of the
kono
parents: 67
diff changeset
380 diagnostic, e.g. "foo.c:42:10: error: ". The caller is responsible for
kono
parents: 67
diff changeset
381 freeing the memory. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 char *
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
383 diagnostic_build_prefix (diagnostic_context *context,
111
kono
parents: 67
diff changeset
384 const diagnostic_info *diagnostic)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 static const char *const diagnostic_kind_text[] = {
111
kono
parents: 67
diff changeset
387 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 #include "diagnostic.def"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 #undef DEFINE_DIAGNOSTIC_KIND
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 "must-not-happen"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393
111
kono
parents: 67
diff changeset
394 const char *text = _(diagnostic_kind_text[diagnostic->kind]);
kono
parents: 67
diff changeset
395 const char *text_cs = "", *text_ce = "";
kono
parents: 67
diff changeset
396 pretty_printer *pp = context->printer;
kono
parents: 67
diff changeset
397
kono
parents: 67
diff changeset
398 if (diagnostic_kind_color[diagnostic->kind])
kono
parents: 67
diff changeset
399 {
kono
parents: 67
diff changeset
400 text_cs = colorize_start (pp_show_color (pp),
kono
parents: 67
diff changeset
401 diagnostic_kind_color[diagnostic->kind]);
kono
parents: 67
diff changeset
402 text_ce = colorize_stop (pp_show_color (pp));
kono
parents: 67
diff changeset
403 }
kono
parents: 67
diff changeset
404
kono
parents: 67
diff changeset
405 expanded_location s = diagnostic_expand_location (diagnostic);
kono
parents: 67
diff changeset
406 char *location_text = diagnostic_get_location_text (context, s);
kono
parents: 67
diff changeset
407
kono
parents: 67
diff changeset
408 char *result = build_message_string ("%s %s%s%s", location_text,
kono
parents: 67
diff changeset
409 text_cs, text, text_ce);
kono
parents: 67
diff changeset
410 free (location_text);
kono
parents: 67
diff changeset
411 return result;
kono
parents: 67
diff changeset
412 }
kono
parents: 67
diff changeset
413
kono
parents: 67
diff changeset
414 /* Functions at which to stop the backtrace print. It's not
kono
parents: 67
diff changeset
415 particularly helpful to print the callers of these functions. */
kono
parents: 67
diff changeset
416
kono
parents: 67
diff changeset
417 static const char * const bt_stop[] =
kono
parents: 67
diff changeset
418 {
kono
parents: 67
diff changeset
419 "main",
kono
parents: 67
diff changeset
420 "toplev::main",
kono
parents: 67
diff changeset
421 "execute_one_pass",
kono
parents: 67
diff changeset
422 "compile_file",
kono
parents: 67
diff changeset
423 };
kono
parents: 67
diff changeset
424
kono
parents: 67
diff changeset
425 /* A callback function passed to the backtrace_full function. */
kono
parents: 67
diff changeset
426
kono
parents: 67
diff changeset
427 static int
kono
parents: 67
diff changeset
428 bt_callback (void *data, uintptr_t pc, const char *filename, int lineno,
kono
parents: 67
diff changeset
429 const char *function)
kono
parents: 67
diff changeset
430 {
kono
parents: 67
diff changeset
431 int *pcount = (int *) data;
kono
parents: 67
diff changeset
432
kono
parents: 67
diff changeset
433 /* If we don't have any useful information, don't print
kono
parents: 67
diff changeset
434 anything. */
kono
parents: 67
diff changeset
435 if (filename == NULL && function == NULL)
kono
parents: 67
diff changeset
436 return 0;
kono
parents: 67
diff changeset
437
kono
parents: 67
diff changeset
438 /* Skip functions in diagnostic.c. */
kono
parents: 67
diff changeset
439 if (*pcount == 0
kono
parents: 67
diff changeset
440 && filename != NULL
kono
parents: 67
diff changeset
441 && strcmp (lbasename (filename), "diagnostic.c") == 0)
kono
parents: 67
diff changeset
442 return 0;
kono
parents: 67
diff changeset
443
kono
parents: 67
diff changeset
444 /* Print up to 20 functions. We could make this a --param, but
kono
parents: 67
diff changeset
445 since this is only for debugging just use a constant for now. */
kono
parents: 67
diff changeset
446 if (*pcount >= 20)
kono
parents: 67
diff changeset
447 {
kono
parents: 67
diff changeset
448 /* Returning a non-zero value stops the backtrace. */
kono
parents: 67
diff changeset
449 return 1;
kono
parents: 67
diff changeset
450 }
kono
parents: 67
diff changeset
451 ++*pcount;
kono
parents: 67
diff changeset
452
kono
parents: 67
diff changeset
453 char *alc = NULL;
kono
parents: 67
diff changeset
454 if (function != NULL)
kono
parents: 67
diff changeset
455 {
kono
parents: 67
diff changeset
456 char *str = cplus_demangle_v3 (function,
kono
parents: 67
diff changeset
457 (DMGL_VERBOSE | DMGL_ANSI
kono
parents: 67
diff changeset
458 | DMGL_GNU_V3 | DMGL_PARAMS));
kono
parents: 67
diff changeset
459 if (str != NULL)
kono
parents: 67
diff changeset
460 {
kono
parents: 67
diff changeset
461 alc = str;
kono
parents: 67
diff changeset
462 function = str;
kono
parents: 67
diff changeset
463 }
kono
parents: 67
diff changeset
464
kono
parents: 67
diff changeset
465 for (size_t i = 0; i < ARRAY_SIZE (bt_stop); ++i)
kono
parents: 67
diff changeset
466 {
kono
parents: 67
diff changeset
467 size_t len = strlen (bt_stop[i]);
kono
parents: 67
diff changeset
468 if (strncmp (function, bt_stop[i], len) == 0
kono
parents: 67
diff changeset
469 && (function[len] == '\0' || function[len] == '('))
kono
parents: 67
diff changeset
470 {
kono
parents: 67
diff changeset
471 if (alc != NULL)
kono
parents: 67
diff changeset
472 free (alc);
kono
parents: 67
diff changeset
473 /* Returning a non-zero value stops the backtrace. */
kono
parents: 67
diff changeset
474 return 1;
kono
parents: 67
diff changeset
475 }
kono
parents: 67
diff changeset
476 }
kono
parents: 67
diff changeset
477 }
kono
parents: 67
diff changeset
478
kono
parents: 67
diff changeset
479 fprintf (stderr, "0x%lx %s\n\t%s:%d\n",
kono
parents: 67
diff changeset
480 (unsigned long) pc,
kono
parents: 67
diff changeset
481 function == NULL ? "???" : function,
kono
parents: 67
diff changeset
482 filename == NULL ? "???" : filename,
kono
parents: 67
diff changeset
483 lineno);
kono
parents: 67
diff changeset
484
kono
parents: 67
diff changeset
485 if (alc != NULL)
kono
parents: 67
diff changeset
486 free (alc);
kono
parents: 67
diff changeset
487
kono
parents: 67
diff changeset
488 return 0;
kono
parents: 67
diff changeset
489 }
kono
parents: 67
diff changeset
490
kono
parents: 67
diff changeset
491 /* A callback function passed to the backtrace_full function. This is
kono
parents: 67
diff changeset
492 called if backtrace_full has an error. */
kono
parents: 67
diff changeset
493
kono
parents: 67
diff changeset
494 static void
kono
parents: 67
diff changeset
495 bt_err_callback (void *data ATTRIBUTE_UNUSED, const char *msg, int errnum)
kono
parents: 67
diff changeset
496 {
kono
parents: 67
diff changeset
497 if (errnum < 0)
kono
parents: 67
diff changeset
498 {
kono
parents: 67
diff changeset
499 /* This means that no debug info was available. Just quietly
kono
parents: 67
diff changeset
500 skip printing backtrace info. */
kono
parents: 67
diff changeset
501 return;
kono
parents: 67
diff changeset
502 }
kono
parents: 67
diff changeset
503 fprintf (stderr, "%s%s%s\n", msg, errnum == 0 ? "" : ": ",
kono
parents: 67
diff changeset
504 errnum == 0 ? "" : xstrerror (errnum));
kono
parents: 67
diff changeset
505 }
kono
parents: 67
diff changeset
506
kono
parents: 67
diff changeset
507 /* Check if we've met the maximum error limit, and if so fatally exit
kono
parents: 67
diff changeset
508 with a message. CONTEXT is the context to check, and FLUSH
kono
parents: 67
diff changeset
509 indicates whether a diagnostic_finish call is needed. */
kono
parents: 67
diff changeset
510
kono
parents: 67
diff changeset
511 void
kono
parents: 67
diff changeset
512 diagnostic_check_max_errors (diagnostic_context *context, bool flush)
kono
parents: 67
diff changeset
513 {
kono
parents: 67
diff changeset
514 if (!context->max_errors)
kono
parents: 67
diff changeset
515 return;
kono
parents: 67
diff changeset
516
kono
parents: 67
diff changeset
517 int count = (diagnostic_kind_count (context, DK_ERROR)
kono
parents: 67
diff changeset
518 + diagnostic_kind_count (context, DK_SORRY)
kono
parents: 67
diff changeset
519 + diagnostic_kind_count (context, DK_WERROR));
kono
parents: 67
diff changeset
520
kono
parents: 67
diff changeset
521 if (count >= context->max_errors)
kono
parents: 67
diff changeset
522 {
kono
parents: 67
diff changeset
523 fnotice (stderr,
kono
parents: 67
diff changeset
524 "compilation terminated due to -fmax-errors=%u.\n",
kono
parents: 67
diff changeset
525 context->max_errors);
kono
parents: 67
diff changeset
526 if (flush)
kono
parents: 67
diff changeset
527 diagnostic_finish (context);
kono
parents: 67
diff changeset
528 exit (FATAL_EXIT_CODE);
kono
parents: 67
diff changeset
529 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 /* Take any action which is expected to happen after the diagnostic
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 is written out. This function does not always return. */
111
kono
parents: 67
diff changeset
534 void
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 diagnostic_action_after_output (diagnostic_context *context,
111
kono
parents: 67
diff changeset
536 diagnostic_t diag_kind)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 {
111
kono
parents: 67
diff changeset
538 switch (diag_kind)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 case DK_DEBUG:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 case DK_NOTE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 case DK_ANACHRONISM:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 case DK_WARNING:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 case DK_ERROR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 case DK_SORRY:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 if (context->abort_on_error)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 real_abort ();
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
550 if (context->fatal_errors)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
553 diagnostic_finish (context);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 exit (FATAL_EXIT_CODE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 case DK_ICE:
111
kono
parents: 67
diff changeset
559 case DK_ICE_NOBT:
kono
parents: 67
diff changeset
560 {
kono
parents: 67
diff changeset
561 struct backtrace_state *state = NULL;
kono
parents: 67
diff changeset
562 if (diag_kind == DK_ICE)
kono
parents: 67
diff changeset
563 state = backtrace_create_state (NULL, 0, bt_err_callback, NULL);
kono
parents: 67
diff changeset
564 int count = 0;
kono
parents: 67
diff changeset
565 if (state != NULL)
kono
parents: 67
diff changeset
566 backtrace_full (state, 2, bt_callback, bt_err_callback,
kono
parents: 67
diff changeset
567 (void *) &count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
568
111
kono
parents: 67
diff changeset
569 if (context->abort_on_error)
kono
parents: 67
diff changeset
570 real_abort ();
kono
parents: 67
diff changeset
571
kono
parents: 67
diff changeset
572 fnotice (stderr, "Please submit a full bug report,\n"
kono
parents: 67
diff changeset
573 "with preprocessed source if appropriate.\n");
kono
parents: 67
diff changeset
574 if (count > 0)
kono
parents: 67
diff changeset
575 fnotice (stderr,
kono
parents: 67
diff changeset
576 ("Please include the complete backtrace "
kono
parents: 67
diff changeset
577 "with any bug report.\n"));
kono
parents: 67
diff changeset
578 fnotice (stderr, "See %s for instructions.\n", bug_report_url);
kono
parents: 67
diff changeset
579
kono
parents: 67
diff changeset
580 exit (ICE_EXIT_CODE);
kono
parents: 67
diff changeset
581 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 case DK_FATAL:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 if (context->abort_on_error)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 real_abort ();
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
586 diagnostic_finish (context);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 fnotice (stderr, "compilation terminated.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 exit (FATAL_EXIT_CODE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594
111
kono
parents: 67
diff changeset
595 /* True if the last module or file in which a diagnostic was reported is
kono
parents: 67
diff changeset
596 different from the current one. */
kono
parents: 67
diff changeset
597
kono
parents: 67
diff changeset
598 static bool
kono
parents: 67
diff changeset
599 last_module_changed_p (diagnostic_context *context,
kono
parents: 67
diff changeset
600 const line_map_ordinary *map)
kono
parents: 67
diff changeset
601 {
kono
parents: 67
diff changeset
602 return context->last_module != map;
kono
parents: 67
diff changeset
603 }
kono
parents: 67
diff changeset
604
kono
parents: 67
diff changeset
605 /* Remember the current module or file as being the last one in which we
kono
parents: 67
diff changeset
606 report a diagnostic. */
kono
parents: 67
diff changeset
607
kono
parents: 67
diff changeset
608 static void
kono
parents: 67
diff changeset
609 set_last_module (diagnostic_context *context, const line_map_ordinary *map)
kono
parents: 67
diff changeset
610 {
kono
parents: 67
diff changeset
611 context->last_module = map;
kono
parents: 67
diff changeset
612 }
kono
parents: 67
diff changeset
613
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 void
111
kono
parents: 67
diff changeset
615 diagnostic_report_current_module (diagnostic_context *context, location_t where)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 {
111
kono
parents: 67
diff changeset
617 const line_map_ordinary *map = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 if (pp_needs_newline (context->printer))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 pp_newline (context->printer);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 pp_needs_newline (context->printer) = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624
111
kono
parents: 67
diff changeset
625 if (where <= BUILTINS_LOCATION)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627
111
kono
parents: 67
diff changeset
628 linemap_resolve_location (line_table, where,
kono
parents: 67
diff changeset
629 LRK_MACRO_DEFINITION_LOCATION,
kono
parents: 67
diff changeset
630 &map);
kono
parents: 67
diff changeset
631
kono
parents: 67
diff changeset
632 if (map && last_module_changed_p (context, map))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 {
111
kono
parents: 67
diff changeset
634 set_last_module (context, map);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 if (! MAIN_FILE_P (map))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
637 bool first = true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
638 do
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
640 where = linemap_included_from (map);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
641 map = linemap_included_from_linemap (line_table, map);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
642 const char *line_col
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
643 = maybe_line_and_column (SOURCE_LINE (map, where),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
644 first && context->show_column
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
645 ? SOURCE_COLUMN (map, where) : 0);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
646 static const char *const msgs[] =
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
647 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
648 N_("In file included from"),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
649 N_(" from"),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
650 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
651 unsigned index = !first;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
652 pp_verbatim (context->printer, "%s%s %r%s%s%R",
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
653 first ? "" : ",\n", _(msgs[index]),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
654 "locus", LINEMAP_FILE (map), line_col);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
655 first = false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
657 while (! MAIN_FILE_P (map));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 pp_verbatim (context->printer, ":");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
659 pp_newline (context->printer);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
664 /* If DIAGNOSTIC has a diagnostic_path and CONTEXT supports printing paths,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
665 print the path. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
666
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
667 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
668 diagnostic_show_any_path (diagnostic_context *context,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
669 diagnostic_info *diagnostic)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
670 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
671 const diagnostic_path *path = diagnostic->richloc->get_path ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
672 if (!path)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
673 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
674
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
675 if (context->print_path)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
676 context->print_path (context, path);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
677 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
678
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
679 /* Return true if the events in this path involve more than one
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
680 function, or false if it is purely intraprocedural. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
681
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
682 bool
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
683 diagnostic_path::interprocedural_p () const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
684 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
685 const unsigned num = num_events ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
686 for (unsigned i = 0; i < num; i++)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
687 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
688 if (get_event (i).get_fndecl () != get_event (0).get_fndecl ())
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
689 return true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
690 if (get_event (i).get_stack_depth () != get_event (0).get_stack_depth ())
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
691 return true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
692 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
693 return false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
694 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
695
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
696 void
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 default_diagnostic_starter (diagnostic_context *context,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 diagnostic_info *diagnostic)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 {
111
kono
parents: 67
diff changeset
700 diagnostic_report_current_module (context, diagnostic_location (diagnostic));
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
701 pp_set_prefix (context->printer, diagnostic_build_prefix (context,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
702 diagnostic));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
705 void
111
kono
parents: 67
diff changeset
706 default_diagnostic_start_span_fn (diagnostic_context *context,
kono
parents: 67
diff changeset
707 expanded_location exploc)
kono
parents: 67
diff changeset
708 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
709 char *text = diagnostic_get_location_text (context, exploc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
710 pp_string (context->printer, text);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
711 free (text);
111
kono
parents: 67
diff changeset
712 pp_newline (context->printer);
kono
parents: 67
diff changeset
713 }
kono
parents: 67
diff changeset
714
kono
parents: 67
diff changeset
715 void
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 default_diagnostic_finalizer (diagnostic_context *context,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
717 diagnostic_info *diagnostic,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
718 diagnostic_t)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
720 char *saved_prefix = pp_take_prefix (context->printer);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
721 pp_set_prefix (context->printer, NULL);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
722 pp_newline (context->printer);
111
kono
parents: 67
diff changeset
723 diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
724 pp_set_prefix (context->printer, saved_prefix);
111
kono
parents: 67
diff changeset
725 pp_flush (context->printer);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 /* Interface to specify diagnostic kind overrides. Returns the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 previous setting, or DK_UNSPECIFIED if the parameters are out of
111
kono
parents: 67
diff changeset
730 range. If OPTION_INDEX is zero, the new setting is for all the
kono
parents: 67
diff changeset
731 diagnostics. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 diagnostic_t
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 diagnostic_classify_diagnostic (diagnostic_context *context,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 int option_index,
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
735 diagnostic_t new_kind,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
736 location_t where)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 diagnostic_t old_kind;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739
111
kono
parents: 67
diff changeset
740 if (option_index < 0
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
741 || option_index >= context->n_opts
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743 return DK_UNSPECIFIED;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 old_kind = context->classify_diagnostic[option_index];
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
746
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
747 /* Handle pragmas separately, since we need to keep track of *where*
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
748 the pragmas were. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
749 if (where != UNKNOWN_LOCATION)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
750 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
751 int i;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
752
111
kono
parents: 67
diff changeset
753 /* Record the command-line status, so we can reset it back on DK_POP. */
kono
parents: 67
diff changeset
754 if (old_kind == DK_UNSPECIFIED)
kono
parents: 67
diff changeset
755 {
kono
parents: 67
diff changeset
756 old_kind = !context->option_enabled (option_index,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
757 context->lang_mask,
111
kono
parents: 67
diff changeset
758 context->option_state)
kono
parents: 67
diff changeset
759 ? DK_IGNORED : (context->warning_as_error_requested
kono
parents: 67
diff changeset
760 ? DK_ERROR : DK_WARNING);
kono
parents: 67
diff changeset
761 context->classify_diagnostic[option_index] = old_kind;
kono
parents: 67
diff changeset
762 }
kono
parents: 67
diff changeset
763
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
764 for (i = context->n_classification_history - 1; i >= 0; i --)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
765 if (context->classification_history[i].option == option_index)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
766 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
767 old_kind = context->classification_history[i].kind;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
768 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
769 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
770
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
771 i = context->n_classification_history;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
772 context->classification_history =
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
773 (diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
774 * sizeof (diagnostic_classification_change_t));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
775 context->classification_history[i].location = where;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
776 context->classification_history[i].option = option_index;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
777 context->classification_history[i].kind = new_kind;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
778 context->n_classification_history ++;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
779 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
780 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
781 context->classify_diagnostic[option_index] = new_kind;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
782
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 return old_kind;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
786 /* Save all diagnostic classifications in a stack. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
787 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
788 diagnostic_push_diagnostics (diagnostic_context *context, location_t where ATTRIBUTE_UNUSED)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
789 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
790 context->push_list = (int *) xrealloc (context->push_list, (context->n_push + 1) * sizeof (int));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
791 context->push_list[context->n_push ++] = context->n_classification_history;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
792 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
793
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
794 /* Restore the topmost classification set off the stack. If the stack
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
795 is empty, revert to the state based on command line parameters. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
796 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
797 diagnostic_pop_diagnostics (diagnostic_context *context, location_t where)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
798 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
799 int jump_to;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
800 int i;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
801
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
802 if (context->n_push)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
803 jump_to = context->push_list [-- context->n_push];
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
804 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
805 jump_to = 0;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
806
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
807 i = context->n_classification_history;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
808 context->classification_history =
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
809 (diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
810 * sizeof (diagnostic_classification_change_t));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
811 context->classification_history[i].location = where;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
812 context->classification_history[i].option = jump_to;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
813 context->classification_history[i].kind = DK_POP;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
814 context->n_classification_history ++;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
815 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
816
111
kono
parents: 67
diff changeset
817 /* Helper function for print_parseable_fixits. Print TEXT to PP, obeying the
kono
parents: 67
diff changeset
818 escaping rules for -fdiagnostics-parseable-fixits. */
kono
parents: 67
diff changeset
819
kono
parents: 67
diff changeset
820 static void
kono
parents: 67
diff changeset
821 print_escaped_string (pretty_printer *pp, const char *text)
kono
parents: 67
diff changeset
822 {
kono
parents: 67
diff changeset
823 gcc_assert (pp);
kono
parents: 67
diff changeset
824 gcc_assert (text);
kono
parents: 67
diff changeset
825
kono
parents: 67
diff changeset
826 pp_character (pp, '"');
kono
parents: 67
diff changeset
827 for (const char *ch = text; *ch; ch++)
kono
parents: 67
diff changeset
828 {
kono
parents: 67
diff changeset
829 switch (*ch)
kono
parents: 67
diff changeset
830 {
kono
parents: 67
diff changeset
831 case '\\':
kono
parents: 67
diff changeset
832 /* Escape backslash as two backslashes. */
kono
parents: 67
diff changeset
833 pp_string (pp, "\\\\");
kono
parents: 67
diff changeset
834 break;
kono
parents: 67
diff changeset
835 case '\t':
kono
parents: 67
diff changeset
836 /* Escape tab as "\t". */
kono
parents: 67
diff changeset
837 pp_string (pp, "\\t");
kono
parents: 67
diff changeset
838 break;
kono
parents: 67
diff changeset
839 case '\n':
kono
parents: 67
diff changeset
840 /* Escape newline as "\n". */
kono
parents: 67
diff changeset
841 pp_string (pp, "\\n");
kono
parents: 67
diff changeset
842 break;
kono
parents: 67
diff changeset
843 case '"':
kono
parents: 67
diff changeset
844 /* Escape doublequotes as \". */
kono
parents: 67
diff changeset
845 pp_string (pp, "\\\"");
kono
parents: 67
diff changeset
846 break;
kono
parents: 67
diff changeset
847 default:
kono
parents: 67
diff changeset
848 if (ISPRINT (*ch))
kono
parents: 67
diff changeset
849 pp_character (pp, *ch);
kono
parents: 67
diff changeset
850 else
kono
parents: 67
diff changeset
851 /* Use octal for non-printable chars. */
kono
parents: 67
diff changeset
852 {
kono
parents: 67
diff changeset
853 unsigned char c = (*ch & 0xff);
kono
parents: 67
diff changeset
854 pp_printf (pp, "\\%o%o%o", (c / 64), (c / 8) & 007, c & 007);
kono
parents: 67
diff changeset
855 }
kono
parents: 67
diff changeset
856 break;
kono
parents: 67
diff changeset
857 }
kono
parents: 67
diff changeset
858 }
kono
parents: 67
diff changeset
859 pp_character (pp, '"');
kono
parents: 67
diff changeset
860 }
kono
parents: 67
diff changeset
861
kono
parents: 67
diff changeset
862 /* Implementation of -fdiagnostics-parseable-fixits. Print a
kono
parents: 67
diff changeset
863 machine-parseable version of all fixits in RICHLOC to PP. */
kono
parents: 67
diff changeset
864
kono
parents: 67
diff changeset
865 static void
kono
parents: 67
diff changeset
866 print_parseable_fixits (pretty_printer *pp, rich_location *richloc)
kono
parents: 67
diff changeset
867 {
kono
parents: 67
diff changeset
868 gcc_assert (pp);
kono
parents: 67
diff changeset
869 gcc_assert (richloc);
kono
parents: 67
diff changeset
870
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
871 char *saved_prefix = pp_take_prefix (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
872 pp_set_prefix (pp, NULL);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
873
111
kono
parents: 67
diff changeset
874 for (unsigned i = 0; i < richloc->get_num_fixit_hints (); i++)
kono
parents: 67
diff changeset
875 {
kono
parents: 67
diff changeset
876 const fixit_hint *hint = richloc->get_fixit_hint (i);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
877 location_t start_loc = hint->get_start_loc ();
111
kono
parents: 67
diff changeset
878 expanded_location start_exploc = expand_location (start_loc);
kono
parents: 67
diff changeset
879 pp_string (pp, "fix-it:");
kono
parents: 67
diff changeset
880 print_escaped_string (pp, start_exploc.file);
kono
parents: 67
diff changeset
881 /* For compatibility with clang, print as a half-open range. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
882 location_t next_loc = hint->get_next_loc ();
111
kono
parents: 67
diff changeset
883 expanded_location next_exploc = expand_location (next_loc);
kono
parents: 67
diff changeset
884 pp_printf (pp, ":{%i:%i-%i:%i}:",
kono
parents: 67
diff changeset
885 start_exploc.line, start_exploc.column,
kono
parents: 67
diff changeset
886 next_exploc.line, next_exploc.column);
kono
parents: 67
diff changeset
887 print_escaped_string (pp, hint->get_string ());
kono
parents: 67
diff changeset
888 pp_newline (pp);
kono
parents: 67
diff changeset
889 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
890
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
891 pp_set_prefix (pp, saved_prefix);
111
kono
parents: 67
diff changeset
892 }
kono
parents: 67
diff changeset
893
kono
parents: 67
diff changeset
894 /* Update the diag_class of DIAGNOSTIC based on its location
kono
parents: 67
diff changeset
895 relative to any
kono
parents: 67
diff changeset
896 #pragma GCC diagnostic
kono
parents: 67
diff changeset
897 directives recorded within CONTEXT.
kono
parents: 67
diff changeset
898
kono
parents: 67
diff changeset
899 Return the new diag_class of DIAGNOSTIC if it was updated, or
kono
parents: 67
diff changeset
900 DK_UNSPECIFIED otherwise. */
kono
parents: 67
diff changeset
901
kono
parents: 67
diff changeset
902 static diagnostic_t
kono
parents: 67
diff changeset
903 update_effective_level_from_pragmas (diagnostic_context *context,
kono
parents: 67
diff changeset
904 diagnostic_info *diagnostic)
kono
parents: 67
diff changeset
905 {
kono
parents: 67
diff changeset
906 diagnostic_t diag_class = DK_UNSPECIFIED;
kono
parents: 67
diff changeset
907
kono
parents: 67
diff changeset
908 if (context->n_classification_history > 0)
kono
parents: 67
diff changeset
909 {
kono
parents: 67
diff changeset
910 location_t location = diagnostic_location (diagnostic);
kono
parents: 67
diff changeset
911
kono
parents: 67
diff changeset
912 /* FIXME: Stupid search. Optimize later. */
kono
parents: 67
diff changeset
913 for (int i = context->n_classification_history - 1; i >= 0; i --)
kono
parents: 67
diff changeset
914 {
kono
parents: 67
diff changeset
915 if (linemap_location_before_p
kono
parents: 67
diff changeset
916 (line_table,
kono
parents: 67
diff changeset
917 context->classification_history[i].location,
kono
parents: 67
diff changeset
918 location))
kono
parents: 67
diff changeset
919 {
kono
parents: 67
diff changeset
920 if (context->classification_history[i].kind == (int) DK_POP)
kono
parents: 67
diff changeset
921 {
kono
parents: 67
diff changeset
922 i = context->classification_history[i].option;
kono
parents: 67
diff changeset
923 continue;
kono
parents: 67
diff changeset
924 }
kono
parents: 67
diff changeset
925 int option = context->classification_history[i].option;
kono
parents: 67
diff changeset
926 /* The option 0 is for all the diagnostics. */
kono
parents: 67
diff changeset
927 if (option == 0 || option == diagnostic->option_index)
kono
parents: 67
diff changeset
928 {
kono
parents: 67
diff changeset
929 diag_class = context->classification_history[i].kind;
kono
parents: 67
diff changeset
930 if (diag_class != DK_UNSPECIFIED)
kono
parents: 67
diff changeset
931 diagnostic->kind = diag_class;
kono
parents: 67
diff changeset
932 break;
kono
parents: 67
diff changeset
933 }
kono
parents: 67
diff changeset
934 }
kono
parents: 67
diff changeset
935 }
kono
parents: 67
diff changeset
936 }
kono
parents: 67
diff changeset
937
kono
parents: 67
diff changeset
938 return diag_class;
kono
parents: 67
diff changeset
939 }
kono
parents: 67
diff changeset
940
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
941 /* Generate a URL string describing CWE. The caller is responsible for
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
942 freeing the string. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
943
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
944 static char *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
945 get_cwe_url (int cwe)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
946 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
947 return xasprintf ("https://cwe.mitre.org/data/definitions/%i.html", cwe);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
948 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
949
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
950 /* If DIAGNOSTIC has a CWE identifier, print it.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
951
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
952 For example, if the diagnostic metadata associates it with CWE-119,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
953 " [CWE-119]" will be printed, suitably colorized, and with a URL of a
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
954 description of the security issue. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
955
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
956 static void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
957 print_any_cwe (diagnostic_context *context,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
958 const diagnostic_info *diagnostic)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
959 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
960 if (diagnostic->metadata == NULL)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
961 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
962
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
963 int cwe = diagnostic->metadata->get_cwe ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
964 if (cwe)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
965 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
966 pretty_printer *pp = context->printer;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
967 char *saved_prefix = pp_take_prefix (context->printer);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
968 pp_string (pp, " [");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
969 pp_string (pp, colorize_start (pp_show_color (pp),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
970 diagnostic_kind_color[diagnostic->kind]));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
971 char *cwe_url = get_cwe_url (cwe);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
972 pp_begin_url (pp, cwe_url);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
973 free (cwe_url);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
974 pp_printf (pp, "CWE-%i", cwe);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
975 pp_set_prefix (context->printer, saved_prefix);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
976 pp_end_url (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
977 pp_string (pp, colorize_stop (pp_show_color (pp)));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
978 pp_character (pp, ']');
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
979 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
980 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
981
111
kono
parents: 67
diff changeset
982 /* Print any metadata about the option used to control DIAGNOSTIC to CONTEXT's
kono
parents: 67
diff changeset
983 printer, e.g. " [-Werror=uninitialized]".
kono
parents: 67
diff changeset
984 Subroutine of diagnostic_report_diagnostic. */
kono
parents: 67
diff changeset
985
kono
parents: 67
diff changeset
986 static void
kono
parents: 67
diff changeset
987 print_option_information (diagnostic_context *context,
kono
parents: 67
diff changeset
988 const diagnostic_info *diagnostic,
kono
parents: 67
diff changeset
989 diagnostic_t orig_diag_kind)
kono
parents: 67
diff changeset
990 {
kono
parents: 67
diff changeset
991 char *option_text;
kono
parents: 67
diff changeset
992
kono
parents: 67
diff changeset
993 option_text = context->option_name (context, diagnostic->option_index,
kono
parents: 67
diff changeset
994 orig_diag_kind, diagnostic->kind);
kono
parents: 67
diff changeset
995
kono
parents: 67
diff changeset
996 if (option_text)
kono
parents: 67
diff changeset
997 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
998 char *option_url = NULL;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
999 if (context->get_option_url)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1000 option_url = context->get_option_url (context,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1001 diagnostic->option_index);
111
kono
parents: 67
diff changeset
1002 pretty_printer *pp = context->printer;
kono
parents: 67
diff changeset
1003 pp_string (pp, " [");
kono
parents: 67
diff changeset
1004 pp_string (pp, colorize_start (pp_show_color (pp),
kono
parents: 67
diff changeset
1005 diagnostic_kind_color[diagnostic->kind]));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1006 if (option_url)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1007 pp_begin_url (pp, option_url);
111
kono
parents: 67
diff changeset
1008 pp_string (pp, option_text);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1009 if (option_url)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1010 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1011 pp_end_url (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1012 free (option_url);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1013 }
111
kono
parents: 67
diff changeset
1014 pp_string (pp, colorize_stop (pp_show_color (pp)));
kono
parents: 67
diff changeset
1015 pp_character (pp, ']');
kono
parents: 67
diff changeset
1016 free (option_text);
kono
parents: 67
diff changeset
1017 }
kono
parents: 67
diff changeset
1018 }
kono
parents: 67
diff changeset
1019
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1020 /* Report a diagnostic message (an error or a warning) as specified by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1021 DC. This function is *the* subroutine in terms of which front-ends
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1022 should implement their specific diagnostic handling modules. The
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1023 front-end independent format specifiers are exactly those described
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1024 in the documentation of output_format.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1025 Return true if a diagnostic was printed, false otherwise. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1026
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028 diagnostic_report_diagnostic (diagnostic_context *context,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029 diagnostic_info *diagnostic)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1030 {
111
kono
parents: 67
diff changeset
1031 location_t location = diagnostic_location (diagnostic);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1032 diagnostic_t orig_diag_kind = diagnostic->kind;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1033
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1034 /* Give preference to being able to inhibit warnings, before they
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035 get reclassified to something else. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036 if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1037 && !diagnostic_report_warnings_p (context, location))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1040 if (diagnostic->kind == DK_PEDWARN)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1041 {
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1042 diagnostic->kind = pedantic_warning_kind (context);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1043 /* We do this to avoid giving the message for -pedantic-errors. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1044 orig_diag_kind = diagnostic->kind;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1045 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1046
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1047 if (diagnostic->kind == DK_NOTE && context->inhibit_notes_p)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1048 return false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1049
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050 if (context->lock > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 /* If we're reporting an ICE in the middle of some other error,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 try to flush out the previous error, then let this one
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054 through. Don't do this more than once. */
111
kono
parents: 67
diff changeset
1055 if ((diagnostic->kind == DK_ICE || diagnostic->kind == DK_ICE_NOBT)
kono
parents: 67
diff changeset
1056 && context->lock == 1)
kono
parents: 67
diff changeset
1057 pp_newline_and_flush (context->printer);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1059 error_recursion (context);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1060 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062 /* If the user requested that warnings be treated as errors, so be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1063 it. Note that we do this before the next block so that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1064 individual warnings can be overridden back to warnings with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1065 -Wno-error=*. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1066 if (context->warning_as_error_requested
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1067 && diagnostic->kind == DK_WARNING)
111
kono
parents: 67
diff changeset
1068 diagnostic->kind = DK_ERROR;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1069
111
kono
parents: 67
diff changeset
1070 if (diagnostic->option_index
kono
parents: 67
diff changeset
1071 && diagnostic->option_index != permissive_error_option (context))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1072 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1073 /* This tests if the user provided the appropriate -Wfoo or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1074 -Wno-foo option. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1075 if (! context->option_enabled (diagnostic->option_index,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1076 context->lang_mask,
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1077 context->option_state))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1078 return false;
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1079
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1080 /* This tests for #pragma diagnostic changes. */
111
kono
parents: 67
diff changeset
1081 diagnostic_t diag_class
kono
parents: 67
diff changeset
1082 = update_effective_level_from_pragmas (context, diagnostic);
kono
parents: 67
diff changeset
1083
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084 /* This tests if the user provided the appropriate -Werror=foo
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1085 option. */
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1086 if (diag_class == DK_UNSPECIFIED
111
kono
parents: 67
diff changeset
1087 && (context->classify_diagnostic[diagnostic->option_index]
kono
parents: 67
diff changeset
1088 != DK_UNSPECIFIED))
kono
parents: 67
diff changeset
1089 diagnostic->kind
kono
parents: 67
diff changeset
1090 = context->classify_diagnostic[diagnostic->option_index];
kono
parents: 67
diff changeset
1091
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092 /* This allows for future extensions, like temporarily disabling
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1093 warnings for ranges of source code. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1094 if (diagnostic->kind == DK_IGNORED)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1095 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1096 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1097
111
kono
parents: 67
diff changeset
1098 if (diagnostic->kind != DK_NOTE)
kono
parents: 67
diff changeset
1099 diagnostic_check_max_errors (context);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1100
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1101 context->lock++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1102
111
kono
parents: 67
diff changeset
1103 if (diagnostic->kind == DK_ICE || diagnostic->kind == DK_ICE_NOBT)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1104 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105 /* When not checking, ICEs are converted to fatal errors when an
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1106 error has already occurred. This is counteracted by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1107 abort_on_error. */
111
kono
parents: 67
diff changeset
1108 if (!CHECKING_P
kono
parents: 67
diff changeset
1109 && (diagnostic_kind_count (context, DK_ERROR) > 0
kono
parents: 67
diff changeset
1110 || diagnostic_kind_count (context, DK_SORRY) > 0)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1111 && !context->abort_on_error)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112 {
111
kono
parents: 67
diff changeset
1113 expanded_location s
kono
parents: 67
diff changeset
1114 = expand_location (diagnostic_location (diagnostic));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1115 fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1116 s.file, s.line);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1117 exit (ICE_EXIT_CODE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1118 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1119 if (context->internal_error)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1120 (*context->internal_error) (context,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1121 diagnostic->message.format_spec,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1122 diagnostic->message.args_ptr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1123 }
111
kono
parents: 67
diff changeset
1124 if (diagnostic->kind == DK_ERROR && orig_diag_kind == DK_WARNING)
kono
parents: 67
diff changeset
1125 ++diagnostic_kind_count (context, DK_WERROR);
kono
parents: 67
diff changeset
1126 else
kono
parents: 67
diff changeset
1127 ++diagnostic_kind_count (context, diagnostic->kind);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1128
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1129 /* Is this the initial diagnostic within the stack of groups? */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1130 if (context->diagnostic_group_emission_count == 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1131 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1132 if (context->begin_group_cb)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1133 context->begin_group_cb (context);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1134 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1135 context->diagnostic_group_emission_count++;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1136
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1137 diagnostic->message.x_data = &diagnostic->x_data;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1138 diagnostic->x_data = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1139 pp_format (context->printer, &diagnostic->message);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1140 (*diagnostic_starter (context)) (context, diagnostic);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1141 pp_output_formatted_text (context->printer);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1142 if (context->show_cwe)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1143 print_any_cwe (context, diagnostic);
111
kono
parents: 67
diff changeset
1144 if (context->show_option_requested)
kono
parents: 67
diff changeset
1145 print_option_information (context, diagnostic, orig_diag_kind);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1146 (*diagnostic_finalizer (context)) (context, diagnostic, orig_diag_kind);
111
kono
parents: 67
diff changeset
1147 if (context->parseable_fixits_p)
kono
parents: 67
diff changeset
1148 {
kono
parents: 67
diff changeset
1149 print_parseable_fixits (context->printer, diagnostic->richloc);
kono
parents: 67
diff changeset
1150 pp_flush (context->printer);
kono
parents: 67
diff changeset
1151 }
kono
parents: 67
diff changeset
1152 diagnostic_action_after_output (context, diagnostic->kind);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1153 diagnostic->x_data = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154
111
kono
parents: 67
diff changeset
1155 if (context->edit_context_ptr)
kono
parents: 67
diff changeset
1156 if (diagnostic->richloc->fixits_can_be_auto_applied_p ())
kono
parents: 67
diff changeset
1157 context->edit_context_ptr->add_fixits (diagnostic->richloc);
kono
parents: 67
diff changeset
1158
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 context->lock--;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1161 diagnostic_show_any_path (context, diagnostic);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1162
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1166 /* Get the number of digits in the decimal representation of VALUE. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1167
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1168 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1169 num_digits (int value)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1170 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1171 /* Perhaps simpler to use log10 for this, but doing it this way avoids
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1172 using floating point. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1173 gcc_assert (value >= 0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1174
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1175 if (value == 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1176 return 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1177
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1178 int digits = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1179 while (value > 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1180 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1181 digits++;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1182 value /= 10;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1183 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1184 return digits;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1185 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1186
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1187 /* Given a partial pathname as input, return another pathname that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1188 shares no directory elements with the pathname of __FILE__. This
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1189 is used by fancy_abort() to print `Internal compiler error in expr.c'
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1191
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 const char *
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1193 trim_filename (const char *name)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1195 static const char this_file[] = __FILE__;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 const char *p = name, *q = this_file;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1198 /* First skip any "../" in each filename. This allows us to give a proper
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1199 reference to a file in a subdirectory. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1200 while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2]))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1201 p += 3;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1203 while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2]))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204 q += 3;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1205
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206 /* Now skip any parts the two filenames have in common. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1207 while (*p == *q && *p != 0 && *q != 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208 p++, q++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 /* Now go backwards until the previous directory separator. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 while (p > name && !IS_DIR_SEPARATOR (p[-1]))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1212 p--;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1213
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1214 return p;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1215 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1216
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1217 /* Standard error reporting routines in increasing order of severity.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1218 All of these take arguments like printf. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220 /* Text to be emitted verbatim to the error message stream; this
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1221 produces no prefix and disables line-wrapping. Use rarely. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1222 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1223 verbatim (const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1224 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225 text_info text;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1227
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1228 va_start (ap, gmsgid);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1229 text.err_no = errno;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1230 text.args_ptr = &ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1231 text.format_spec = _(gmsgid);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1232 text.x_data = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1233 pp_format_verbatim (global_dc->printer, &text);
111
kono
parents: 67
diff changeset
1234 pp_newline_and_flush (global_dc->printer);
kono
parents: 67
diff changeset
1235 va_end (ap);
kono
parents: 67
diff changeset
1236 }
kono
parents: 67
diff changeset
1237
kono
parents: 67
diff changeset
1238 /* Add a note with text GMSGID and with LOCATION to the diagnostic CONTEXT. */
kono
parents: 67
diff changeset
1239 void
kono
parents: 67
diff changeset
1240 diagnostic_append_note (diagnostic_context *context,
kono
parents: 67
diff changeset
1241 location_t location,
kono
parents: 67
diff changeset
1242 const char * gmsgid, ...)
kono
parents: 67
diff changeset
1243 {
kono
parents: 67
diff changeset
1244 diagnostic_info diagnostic;
kono
parents: 67
diff changeset
1245 va_list ap;
kono
parents: 67
diff changeset
1246 rich_location richloc (line_table, location);
kono
parents: 67
diff changeset
1247
kono
parents: 67
diff changeset
1248 va_start (ap, gmsgid);
kono
parents: 67
diff changeset
1249 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_NOTE);
kono
parents: 67
diff changeset
1250 if (context->inhibit_notes_p)
kono
parents: 67
diff changeset
1251 {
kono
parents: 67
diff changeset
1252 va_end (ap);
kono
parents: 67
diff changeset
1253 return;
kono
parents: 67
diff changeset
1254 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1255 char *saved_prefix = pp_take_prefix (context->printer);
111
kono
parents: 67
diff changeset
1256 pp_set_prefix (context->printer,
kono
parents: 67
diff changeset
1257 diagnostic_build_prefix (context, &diagnostic));
kono
parents: 67
diff changeset
1258 pp_format (context->printer, &diagnostic.message);
kono
parents: 67
diff changeset
1259 pp_output_formatted_text (context->printer);
kono
parents: 67
diff changeset
1260 pp_destroy_prefix (context->printer);
kono
parents: 67
diff changeset
1261 pp_set_prefix (context->printer, saved_prefix);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1262 pp_newline (context->printer);
111
kono
parents: 67
diff changeset
1263 diagnostic_show_locus (context, &richloc, DK_NOTE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1266
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1267 /* Implement emit_diagnostic, inform, warning, warning_at, pedwarn,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1268 permerror, error, error_at, error_at, sorry, fatal_error, internal_error,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1269 and internal_error_no_backtrace, as documented and defined below. */
111
kono
parents: 67
diff changeset
1270 static bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1271 diagnostic_impl (rich_location *richloc, const diagnostic_metadata *metadata,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1272 int opt, const char *gmsgid,
111
kono
parents: 67
diff changeset
1273 va_list *ap, diagnostic_t kind)
kono
parents: 67
diff changeset
1274 {
kono
parents: 67
diff changeset
1275 diagnostic_info diagnostic;
kono
parents: 67
diff changeset
1276 if (kind == DK_PERMERROR)
kono
parents: 67
diff changeset
1277 {
kono
parents: 67
diff changeset
1278 diagnostic_set_info (&diagnostic, gmsgid, ap, richloc,
kono
parents: 67
diff changeset
1279 permissive_error_kind (global_dc));
kono
parents: 67
diff changeset
1280 diagnostic.option_index = permissive_error_option (global_dc);
kono
parents: 67
diff changeset
1281 }
kono
parents: 67
diff changeset
1282 else
kono
parents: 67
diff changeset
1283 {
kono
parents: 67
diff changeset
1284 diagnostic_set_info (&diagnostic, gmsgid, ap, richloc, kind);
kono
parents: 67
diff changeset
1285 if (kind == DK_WARNING || kind == DK_PEDWARN)
kono
parents: 67
diff changeset
1286 diagnostic.option_index = opt;
kono
parents: 67
diff changeset
1287 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1288 diagnostic.metadata = metadata;
111
kono
parents: 67
diff changeset
1289 return diagnostic_report_diagnostic (global_dc, &diagnostic);
kono
parents: 67
diff changeset
1290 }
kono
parents: 67
diff changeset
1291
kono
parents: 67
diff changeset
1292 /* Implement inform_n, warning_n, and error_n, as documented and
kono
parents: 67
diff changeset
1293 defined below. */
kono
parents: 67
diff changeset
1294 static bool
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1295 diagnostic_n_impl (rich_location *richloc, const diagnostic_metadata *metadata,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1296 int opt, unsigned HOST_WIDE_INT n,
111
kono
parents: 67
diff changeset
1297 const char *singular_gmsgid,
kono
parents: 67
diff changeset
1298 const char *plural_gmsgid,
kono
parents: 67
diff changeset
1299 va_list *ap, diagnostic_t kind)
kono
parents: 67
diff changeset
1300 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1301 diagnostic_info diagnostic;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1302 unsigned long gtn;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1303
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1304 if (sizeof n <= sizeof gtn)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1305 gtn = n;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1306 else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1307 /* Use the largest number ngettext can handle, otherwise
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1308 preserve the six least significant decimal digits for
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1309 languages where the plural form depends on them. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1310 gtn = n <= ULONG_MAX ? n : n % 1000000LU + 1000000LU;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1311
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1312 const char *text = ngettext (singular_gmsgid, plural_gmsgid, gtn);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1313 diagnostic_set_info_translated (&diagnostic, text, ap, richloc, kind);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1314 if (kind == DK_WARNING)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1315 diagnostic.option_index = opt;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1316 diagnostic.metadata = metadata;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1317 return diagnostic_report_diagnostic (global_dc, &diagnostic);
111
kono
parents: 67
diff changeset
1318 }
kono
parents: 67
diff changeset
1319
kono
parents: 67
diff changeset
1320 /* Wrapper around diagnostic_impl taking a variable argument list. */
kono
parents: 67
diff changeset
1321
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1322 bool
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1323 emit_diagnostic (diagnostic_t kind, location_t location, int opt,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1324 const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1325 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1326 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 va_start (ap, gmsgid);
111
kono
parents: 67
diff changeset
1329 rich_location richloc (line_table, location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1330 bool ret = diagnostic_impl (&richloc, NULL, opt, gmsgid, &ap, kind);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1331 va_end (ap);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1332 return ret;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1333 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1334
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1335 /* As above, but for rich_location *. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1336
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1337 bool
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1338 emit_diagnostic (diagnostic_t kind, rich_location *richloc, int opt,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1339 const char *gmsgid, ...)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1340 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1341 auto_diagnostic_group d;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1342 va_list ap;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1343 va_start (ap, gmsgid);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1344 bool ret = diagnostic_impl (richloc, NULL, opt, gmsgid, &ap, kind);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1345 va_end (ap);
111
kono
parents: 67
diff changeset
1346 return ret;
kono
parents: 67
diff changeset
1347 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1348
111
kono
parents: 67
diff changeset
1349 /* Wrapper around diagnostic_impl taking a va_list parameter. */
kono
parents: 67
diff changeset
1350
kono
parents: 67
diff changeset
1351 bool
kono
parents: 67
diff changeset
1352 emit_diagnostic_valist (diagnostic_t kind, location_t location, int opt,
kono
parents: 67
diff changeset
1353 const char *gmsgid, va_list *ap)
kono
parents: 67
diff changeset
1354 {
kono
parents: 67
diff changeset
1355 rich_location richloc (line_table, location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1356 return diagnostic_impl (&richloc, NULL, opt, gmsgid, ap, kind);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1357 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1358
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1359 /* An informative note at LOCATION. Use this for additional details on an error
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1360 message. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1361 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1362 inform (location_t location, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1363 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1364 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1365 va_list ap;
111
kono
parents: 67
diff changeset
1366 va_start (ap, gmsgid);
kono
parents: 67
diff changeset
1367 rich_location richloc (line_table, location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1368 diagnostic_impl (&richloc, NULL, -1, gmsgid, &ap, DK_NOTE);
111
kono
parents: 67
diff changeset
1369 va_end (ap);
kono
parents: 67
diff changeset
1370 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1371
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1372 /* Same as "inform" above, but at RICHLOC. */
111
kono
parents: 67
diff changeset
1373 void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1374 inform (rich_location *richloc, const char *gmsgid, ...)
111
kono
parents: 67
diff changeset
1375 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1376 gcc_assert (richloc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1377
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1378 auto_diagnostic_group d;
111
kono
parents: 67
diff changeset
1379 va_list ap;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1380 va_start (ap, gmsgid);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1381 diagnostic_impl (richloc, NULL, -1, gmsgid, &ap, DK_NOTE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1382 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1383 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1384
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1385 /* An informative note at LOCATION. Use this for additional details on an
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1386 error message. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1387 void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1388 inform_n (location_t location, unsigned HOST_WIDE_INT n,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1389 const char *singular_gmsgid, const char *plural_gmsgid, ...)
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1390 {
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1391 va_list ap;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1392 va_start (ap, plural_gmsgid);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1393 auto_diagnostic_group d;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1394 rich_location richloc (line_table, location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1395 diagnostic_n_impl (&richloc, NULL, -1, n, singular_gmsgid, plural_gmsgid,
111
kono
parents: 67
diff changeset
1396 &ap, DK_NOTE);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1397 va_end (ap);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1398 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1399
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1400 /* A warning at INPUT_LOCATION. Use this for code which is correct according
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1401 to the relevant language specification but is likely to be buggy anyway.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1402 Returns true if the warning was printed, false if it was inhibited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1403 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1404 warning (int opt, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1405 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1406 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1407 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1408 va_start (ap, gmsgid);
111
kono
parents: 67
diff changeset
1409 rich_location richloc (line_table, input_location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1410 bool ret = diagnostic_impl (&richloc, NULL, opt, gmsgid, &ap, DK_WARNING);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1411 va_end (ap);
111
kono
parents: 67
diff changeset
1412 return ret;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1413 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1414
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1415 /* A warning at LOCATION. Use this for code which is correct according to the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1416 relevant language specification but is likely to be buggy anyway.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1417 Returns true if the warning was printed, false if it was inhibited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1418
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1419 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1420 warning_at (location_t location, int opt, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1421 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1422 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1423 va_list ap;
111
kono
parents: 67
diff changeset
1424 va_start (ap, gmsgid);
kono
parents: 67
diff changeset
1425 rich_location richloc (line_table, location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1426 bool ret = diagnostic_impl (&richloc, NULL, opt, gmsgid, &ap, DK_WARNING);
111
kono
parents: 67
diff changeset
1427 va_end (ap);
kono
parents: 67
diff changeset
1428 return ret;
kono
parents: 67
diff changeset
1429 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1430
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1431 /* Same as "warning at" above, but using RICHLOC. */
111
kono
parents: 67
diff changeset
1432
kono
parents: 67
diff changeset
1433 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1434 warning_at (rich_location *richloc, int opt, const char *gmsgid, ...)
111
kono
parents: 67
diff changeset
1435 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1436 gcc_assert (richloc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1437
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1438 auto_diagnostic_group d;
111
kono
parents: 67
diff changeset
1439 va_list ap;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1440 va_start (ap, gmsgid);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1441 bool ret = diagnostic_impl (richloc, NULL, opt, gmsgid, &ap, DK_WARNING);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1442 va_end (ap);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1443 return ret;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1444 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1445
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1446 /* Same as "warning at" above, but using METADATA. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1447
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1448 bool
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1449 warning_meta (rich_location *richloc,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1450 const diagnostic_metadata &metadata,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1451 int opt, const char *gmsgid, ...)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1452 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1453 gcc_assert (richloc);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1454
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1455 auto_diagnostic_group d;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1456 va_list ap;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1457 va_start (ap, gmsgid);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1458 bool ret
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1459 = diagnostic_impl (richloc, &metadata, opt, gmsgid, &ap,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1460 DK_WARNING);
111
kono
parents: 67
diff changeset
1461 va_end (ap);
kono
parents: 67
diff changeset
1462 return ret;
kono
parents: 67
diff changeset
1463 }
kono
parents: 67
diff changeset
1464
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1465 /* Same as warning_n plural variant below, but using RICHLOC. */
111
kono
parents: 67
diff changeset
1466
kono
parents: 67
diff changeset
1467 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1468 warning_n (rich_location *richloc, int opt, unsigned HOST_WIDE_INT n,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1469 const char *singular_gmsgid, const char *plural_gmsgid, ...)
111
kono
parents: 67
diff changeset
1470 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1471 gcc_assert (richloc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1472
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1473 auto_diagnostic_group d;
111
kono
parents: 67
diff changeset
1474 va_list ap;
kono
parents: 67
diff changeset
1475 va_start (ap, plural_gmsgid);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1476 bool ret = diagnostic_n_impl (richloc, NULL, opt, n,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1477 singular_gmsgid, plural_gmsgid,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1478 &ap, DK_WARNING);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1479 va_end (ap);
111
kono
parents: 67
diff changeset
1480 return ret;
kono
parents: 67
diff changeset
1481 }
kono
parents: 67
diff changeset
1482
kono
parents: 67
diff changeset
1483 /* A warning at LOCATION. Use this for code which is correct according to the
kono
parents: 67
diff changeset
1484 relevant language specification but is likely to be buggy anyway.
kono
parents: 67
diff changeset
1485 Returns true if the warning was printed, false if it was inhibited. */
kono
parents: 67
diff changeset
1486
kono
parents: 67
diff changeset
1487 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1488 warning_n (location_t location, int opt, unsigned HOST_WIDE_INT n,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1489 const char *singular_gmsgid, const char *plural_gmsgid, ...)
111
kono
parents: 67
diff changeset
1490 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1491 auto_diagnostic_group d;
111
kono
parents: 67
diff changeset
1492 va_list ap;
kono
parents: 67
diff changeset
1493 va_start (ap, plural_gmsgid);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1494 rich_location richloc (line_table, location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1495 bool ret = diagnostic_n_impl (&richloc, NULL, opt, n,
111
kono
parents: 67
diff changeset
1496 singular_gmsgid, plural_gmsgid,
kono
parents: 67
diff changeset
1497 &ap, DK_WARNING);
kono
parents: 67
diff changeset
1498 va_end (ap);
kono
parents: 67
diff changeset
1499 return ret;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1500 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1501
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1502 /* A "pedantic" warning at LOCATION: issues a warning unless
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1503 -pedantic-errors was given on the command line, in which case it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1504 issues an error. Use this for diagnostics required by the relevant
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1505 language standard, if you have chosen not to make them errors.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1506
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1507 Note that these diagnostics are issued independent of the setting
111
kono
parents: 67
diff changeset
1508 of the -Wpedantic command-line switch. To get a warning enabled
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1509 only with that switch, use either "if (pedantic) pedwarn
111
kono
parents: 67
diff changeset
1510 (OPT_Wpedantic,...)" or just "pedwarn (OPT_Wpedantic,..)". To get a
kono
parents: 67
diff changeset
1511 pedwarn independently of the -Wpedantic switch use "pedwarn (0,...)".
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1512
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1513 Returns true if the warning was printed, false if it was inhibited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1514
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1515 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1516 pedwarn (location_t location, int opt, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1517 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1518 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1519 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1520 va_start (ap, gmsgid);
111
kono
parents: 67
diff changeset
1521 rich_location richloc (line_table, location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1522 bool ret = diagnostic_impl (&richloc, NULL, opt, gmsgid, &ap, DK_PEDWARN);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1523 va_end (ap);
111
kono
parents: 67
diff changeset
1524 return ret;
kono
parents: 67
diff changeset
1525 }
kono
parents: 67
diff changeset
1526
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1527 /* Same as pedwarn above, but using RICHLOC. */
111
kono
parents: 67
diff changeset
1528
kono
parents: 67
diff changeset
1529 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1530 pedwarn (rich_location *richloc, int opt, const char *gmsgid, ...)
111
kono
parents: 67
diff changeset
1531 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1532 gcc_assert (richloc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1533
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1534 auto_diagnostic_group d;
111
kono
parents: 67
diff changeset
1535 va_list ap;
kono
parents: 67
diff changeset
1536 va_start (ap, gmsgid);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1537 bool ret = diagnostic_impl (richloc, NULL, opt, gmsgid, &ap, DK_PEDWARN);
111
kono
parents: 67
diff changeset
1538 va_end (ap);
kono
parents: 67
diff changeset
1539 return ret;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1540 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1541
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1542 /* A "permissive" error at LOCATION: issues an error unless
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1543 -fpermissive was given on the command line, in which case it issues
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1544 a warning. Use this for things that really should be errors but we
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1545 want to support legacy code.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1546
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1547 Returns true if the warning was printed, false if it was inhibited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1548
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1549 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1550 permerror (location_t location, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1551 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1552 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1553 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1554 va_start (ap, gmsgid);
111
kono
parents: 67
diff changeset
1555 rich_location richloc (line_table, location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1556 bool ret = diagnostic_impl (&richloc, NULL, -1, gmsgid, &ap, DK_PERMERROR);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1557 va_end (ap);
111
kono
parents: 67
diff changeset
1558 return ret;
kono
parents: 67
diff changeset
1559 }
kono
parents: 67
diff changeset
1560
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1561 /* Same as "permerror" above, but at RICHLOC. */
111
kono
parents: 67
diff changeset
1562
kono
parents: 67
diff changeset
1563 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1564 permerror (rich_location *richloc, const char *gmsgid, ...)
111
kono
parents: 67
diff changeset
1565 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1566 gcc_assert (richloc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1567
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1568 auto_diagnostic_group d;
111
kono
parents: 67
diff changeset
1569 va_list ap;
kono
parents: 67
diff changeset
1570 va_start (ap, gmsgid);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1571 bool ret = diagnostic_impl (richloc, NULL, -1, gmsgid, &ap, DK_PERMERROR);
111
kono
parents: 67
diff changeset
1572 va_end (ap);
kono
parents: 67
diff changeset
1573 return ret;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1574 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1575
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1576 /* A hard error: the code is definitely ill-formed, and an object file
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1577 will not be produced. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1578 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1579 error (const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1580 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1581 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1582 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1583 va_start (ap, gmsgid);
111
kono
parents: 67
diff changeset
1584 rich_location richloc (line_table, input_location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1585 diagnostic_impl (&richloc, NULL, -1, gmsgid, &ap, DK_ERROR);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1586 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1587 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1588
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1589 /* A hard error: the code is definitely ill-formed, and an object file
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1590 will not be produced. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1591 void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1592 error_n (location_t location, unsigned HOST_WIDE_INT n,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1593 const char *singular_gmsgid, const char *plural_gmsgid, ...)
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1594 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1595 auto_diagnostic_group d;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1596 va_list ap;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1597 va_start (ap, plural_gmsgid);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1598 rich_location richloc (line_table, location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1599 diagnostic_n_impl (&richloc, NULL, -1, n, singular_gmsgid, plural_gmsgid,
111
kono
parents: 67
diff changeset
1600 &ap, DK_ERROR);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1601 va_end (ap);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1602 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
1603
111
kono
parents: 67
diff changeset
1604 /* Same as above, but use location LOC instead of input_location. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1605 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1606 error_at (location_t loc, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1607 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1608 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1609 va_list ap;
111
kono
parents: 67
diff changeset
1610 va_start (ap, gmsgid);
kono
parents: 67
diff changeset
1611 rich_location richloc (line_table, loc);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1612 diagnostic_impl (&richloc, NULL, -1, gmsgid, &ap, DK_ERROR);
111
kono
parents: 67
diff changeset
1613 va_end (ap);
kono
parents: 67
diff changeset
1614 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1615
111
kono
parents: 67
diff changeset
1616 /* Same as above, but use RICH_LOC. */
kono
parents: 67
diff changeset
1617
kono
parents: 67
diff changeset
1618 void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1619 error_at (rich_location *richloc, const char *gmsgid, ...)
111
kono
parents: 67
diff changeset
1620 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1621 gcc_assert (richloc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1622
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1623 auto_diagnostic_group d;
111
kono
parents: 67
diff changeset
1624 va_list ap;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1625 va_start (ap, gmsgid);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1626 diagnostic_impl (richloc, NULL, -1, gmsgid, &ap, DK_ERROR);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1627 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1628 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1629
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1630 /* "Sorry, not implemented." Use for a language feature which is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1631 required by the relevant specification but not implemented by GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1632 An object file will not be produced. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1633 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1634 sorry (const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1635 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1636 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1637 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1638 va_start (ap, gmsgid);
111
kono
parents: 67
diff changeset
1639 rich_location richloc (line_table, input_location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1640 diagnostic_impl (&richloc, NULL, -1, gmsgid, &ap, DK_SORRY);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1641 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1642 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1643
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1644 /* Same as above, but use location LOC instead of input_location. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1645 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1646 sorry_at (location_t loc, const char *gmsgid, ...)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1647 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1648 auto_diagnostic_group d;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1649 va_list ap;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1650 va_start (ap, gmsgid);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1651 rich_location richloc (line_table, loc);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1652 diagnostic_impl (&richloc, NULL, -1, gmsgid, &ap, DK_SORRY);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1653 va_end (ap);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1654 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1655
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1656 /* Return true if an error or a "sorry" has been seen. Various
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1657 processing is disabled after errors. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1658 bool
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1659 seen_error (void)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1660 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1661 return errorcount || sorrycount;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1662 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1663
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1664 /* An error which is severe enough that we make no attempt to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1665 continue. Do not use this for internal consistency checks; that's
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1666 internal_error. Use of this function should be rare. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1667 void
111
kono
parents: 67
diff changeset
1668 fatal_error (location_t loc, const char *gmsgid, ...)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1669 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1670 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1671 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1672 va_start (ap, gmsgid);
111
kono
parents: 67
diff changeset
1673 rich_location richloc (line_table, loc);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1674 diagnostic_impl (&richloc, NULL, -1, gmsgid, &ap, DK_FATAL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1675 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1676
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1677 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1678 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1679
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1680 /* An internal consistency check has failed. We make no attempt to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1681 continue. Note that unless there is debugging value to be had from
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1682 a more specific message, or some other good reason, you should use
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1683 abort () instead of calling this function directly. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1684 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1685 internal_error (const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1686 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1687 auto_diagnostic_group d;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1688 va_list ap;
111
kono
parents: 67
diff changeset
1689 va_start (ap, gmsgid);
kono
parents: 67
diff changeset
1690 rich_location richloc (line_table, input_location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1691 diagnostic_impl (&richloc, NULL, -1, gmsgid, &ap, DK_ICE);
111
kono
parents: 67
diff changeset
1692 va_end (ap);
kono
parents: 67
diff changeset
1693
kono
parents: 67
diff changeset
1694 gcc_unreachable ();
kono
parents: 67
diff changeset
1695 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1696
111
kono
parents: 67
diff changeset
1697 /* Like internal_error, but no backtrace will be printed. Used when
kono
parents: 67
diff changeset
1698 the internal error does not happen at the current location, but happened
kono
parents: 67
diff changeset
1699 somewhere else. */
kono
parents: 67
diff changeset
1700 void
kono
parents: 67
diff changeset
1701 internal_error_no_backtrace (const char *gmsgid, ...)
kono
parents: 67
diff changeset
1702 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1703 auto_diagnostic_group d;
111
kono
parents: 67
diff changeset
1704 va_list ap;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1705 va_start (ap, gmsgid);
111
kono
parents: 67
diff changeset
1706 rich_location richloc (line_table, input_location);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1707 diagnostic_impl (&richloc, NULL, -1, gmsgid, &ap, DK_ICE_NOBT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1708 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1709
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1710 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1711 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1712
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1713 /* Special case error functions. Most are implemented in terms of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1714 above, or should be. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1715
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1716 /* Print a diagnostic MSGID on FILE. This is just fprintf, except it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1717 runs its second argument through gettext. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1718 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1719 fnotice (FILE *file, const char *cmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1720 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1721 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1722
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1723 va_start (ap, cmsgid);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1724 vfprintf (file, _(cmsgid), ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1725 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1726 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1727
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1728 /* Inform the user that an error occurred while trying to report some
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1729 other error. This indicates catastrophic internal inconsistencies,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1730 so give up now. But do try to flush out the previous error.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1731 This mustn't use internal_error, that will cause infinite recursion. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1732
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1733 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1734 error_recursion (diagnostic_context *context)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1735 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1736 if (context->lock < 3)
111
kono
parents: 67
diff changeset
1737 pp_newline_and_flush (context->printer);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1738
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1739 fnotice (stderr,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1740 "Internal compiler error: Error reporting routines re-entered.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1741
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1742 /* Call diagnostic_action_after_output to get the "please submit a bug
111
kono
parents: 67
diff changeset
1743 report" message. */
kono
parents: 67
diff changeset
1744 diagnostic_action_after_output (context, DK_ICE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1745
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1746 /* Do not use gcc_unreachable here; that goes through internal_error
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1747 and therefore would cause infinite recursion. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1748 real_abort ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1749 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1750
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1751 /* Report an internal compiler error in a friendly manner. This is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1752 the function that gets called upon use of abort() in the source
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1753 code generally, thanks to a special macro. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1754
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1755 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1756 fancy_abort (const char *file, int line, const char *function)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1757 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1758 internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1759 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1760
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1761 /* class auto_diagnostic_group. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1762
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1763 /* Constructor: "push" this group into global_dc. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1764
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1765 auto_diagnostic_group::auto_diagnostic_group ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1766 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1767 global_dc->diagnostic_group_nesting_depth++;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1768 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1769
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1770 /* Destructor: "pop" this group from global_dc. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1771
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1772 auto_diagnostic_group::~auto_diagnostic_group ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1773 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1774 if (--global_dc->diagnostic_group_nesting_depth == 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1775 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1776 /* Handle the case where we've popped the final diagnostic group.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1777 If any diagnostics were emitted, give the context a chance
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1778 to do something. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1779 if (global_dc->diagnostic_group_emission_count > 0)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1780 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1781 if (global_dc->end_group_cb)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1782 global_dc->end_group_cb (global_dc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1783 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1784 global_dc->diagnostic_group_emission_count = 0;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1785 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1786 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1787
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1788 /* Implementation of diagnostic_path::num_events vfunc for
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1789 simple_diagnostic_path: simply get the number of events in the vec. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1790
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1791 unsigned
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1792 simple_diagnostic_path::num_events () const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1793 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1794 return m_events.length ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1795 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1796
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1797 /* Implementation of diagnostic_path::get_event vfunc for
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1798 simple_diagnostic_path: simply return the event in the vec. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1799
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1800 const diagnostic_event &
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1801 simple_diagnostic_path::get_event (int idx) const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1802 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1803 return *m_events[idx];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1804 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1805
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1806 /* Add an event to this path at LOC within function FNDECL at
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1807 stack depth DEPTH.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1808
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1809 Use m_context's printer to format FMT, as the text of the new
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1810 event.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1811
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1812 Return the id of the new event. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1813
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1814 diagnostic_event_id_t
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1815 simple_diagnostic_path::add_event (location_t loc, tree fndecl, int depth,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1816 const char *fmt, ...)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1817 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1818 pretty_printer *pp = m_event_pp;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1819 pp_clear_output_area (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1820
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1821 text_info ti;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1822 rich_location rich_loc (line_table, UNKNOWN_LOCATION);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1823
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1824 va_list ap;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1825
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1826 va_start (ap, fmt);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1827
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1828 ti.format_spec = _(fmt);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1829 ti.args_ptr = &ap;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1830 ti.err_no = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1831 ti.x_data = NULL;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1832 ti.m_richloc = &rich_loc;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1833
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1834 pp_format (pp, &ti);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1835 pp_output_formatted_text (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1836
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1837 va_end (ap);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1838
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1839 simple_diagnostic_event *new_event
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1840 = new simple_diagnostic_event (loc, fndecl, depth, pp_formatted_text (pp));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1841 m_events.safe_push (new_event);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1842
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1843 pp_clear_output_area (pp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1844
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1845 return diagnostic_event_id_t (m_events.length () - 1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1846 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1847
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1848 /* struct simple_diagnostic_event. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1849
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1850 /* simple_diagnostic_event's ctor. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1851
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1852 simple_diagnostic_event::simple_diagnostic_event (location_t loc,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1853 tree fndecl,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1854 int depth,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1855 const char *desc)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1856 : m_loc (loc), m_fndecl (fndecl), m_depth (depth), m_desc (xstrdup (desc))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1857 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1858 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1859
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1860 /* simple_diagnostic_event's dtor. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1861
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1862 simple_diagnostic_event::~simple_diagnostic_event ()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1863 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1864 free (m_desc);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1865 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1866
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1867 /* Print PATH by emitting a dummy "note" associated with it. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1868
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1869 DEBUG_FUNCTION
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1870 void debug (diagnostic_path *path)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1871 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1872 rich_location richloc (line_table, UNKNOWN_LOCATION);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1873 richloc.set_path (path);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1874 inform (&richloc, "debug path");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1875 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1876
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1877 /* Really call the system 'abort'. This has to go right at the end of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1878 this file, so that there are no functions after it that call abort
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1879 and get the system abort instead of our macro. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1880 #undef abort
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1881 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1882 real_abort (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1883 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1884 abort ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1885 }
111
kono
parents: 67
diff changeset
1886
kono
parents: 67
diff changeset
1887 #if CHECKING_P
kono
parents: 67
diff changeset
1888
kono
parents: 67
diff changeset
1889 namespace selftest {
kono
parents: 67
diff changeset
1890
kono
parents: 67
diff changeset
1891 /* Helper function for test_print_escaped_string. */
kono
parents: 67
diff changeset
1892
kono
parents: 67
diff changeset
1893 static void
kono
parents: 67
diff changeset
1894 assert_print_escaped_string (const location &loc, const char *expected_output,
kono
parents: 67
diff changeset
1895 const char *input)
kono
parents: 67
diff changeset
1896 {
kono
parents: 67
diff changeset
1897 pretty_printer pp;
kono
parents: 67
diff changeset
1898 print_escaped_string (&pp, input);
kono
parents: 67
diff changeset
1899 ASSERT_STREQ_AT (loc, expected_output, pp_formatted_text (&pp));
kono
parents: 67
diff changeset
1900 }
kono
parents: 67
diff changeset
1901
kono
parents: 67
diff changeset
1902 #define ASSERT_PRINT_ESCAPED_STRING_STREQ(EXPECTED_OUTPUT, INPUT) \
kono
parents: 67
diff changeset
1903 assert_print_escaped_string (SELFTEST_LOCATION, EXPECTED_OUTPUT, INPUT)
kono
parents: 67
diff changeset
1904
kono
parents: 67
diff changeset
1905 /* Tests of print_escaped_string. */
kono
parents: 67
diff changeset
1906
kono
parents: 67
diff changeset
1907 static void
kono
parents: 67
diff changeset
1908 test_print_escaped_string ()
kono
parents: 67
diff changeset
1909 {
kono
parents: 67
diff changeset
1910 /* Empty string. */
kono
parents: 67
diff changeset
1911 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"\"", "");
kono
parents: 67
diff changeset
1912
kono
parents: 67
diff changeset
1913 /* Non-empty string. */
kono
parents: 67
diff changeset
1914 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"hello world\"", "hello world");
kono
parents: 67
diff changeset
1915
kono
parents: 67
diff changeset
1916 /* Various things that need to be escaped: */
kono
parents: 67
diff changeset
1917 /* Backslash. */
kono
parents: 67
diff changeset
1918 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\\\after\"",
kono
parents: 67
diff changeset
1919 "before\\after");
kono
parents: 67
diff changeset
1920 /* Tab. */
kono
parents: 67
diff changeset
1921 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\tafter\"",
kono
parents: 67
diff changeset
1922 "before\tafter");
kono
parents: 67
diff changeset
1923 /* Newline. */
kono
parents: 67
diff changeset
1924 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\nafter\"",
kono
parents: 67
diff changeset
1925 "before\nafter");
kono
parents: 67
diff changeset
1926 /* Double quote. */
kono
parents: 67
diff changeset
1927 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\\"after\"",
kono
parents: 67
diff changeset
1928 "before\"after");
kono
parents: 67
diff changeset
1929
kono
parents: 67
diff changeset
1930 /* Non-printable characters: BEL: '\a': 0x07 */
kono
parents: 67
diff changeset
1931 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\007after\"",
kono
parents: 67
diff changeset
1932 "before\aafter");
kono
parents: 67
diff changeset
1933 /* Non-printable characters: vertical tab: '\v': 0x0b */
kono
parents: 67
diff changeset
1934 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\013after\"",
kono
parents: 67
diff changeset
1935 "before\vafter");
kono
parents: 67
diff changeset
1936 }
kono
parents: 67
diff changeset
1937
kono
parents: 67
diff changeset
1938 /* Tests of print_parseable_fixits. */
kono
parents: 67
diff changeset
1939
kono
parents: 67
diff changeset
1940 /* Verify that print_parseable_fixits emits the empty string if there
kono
parents: 67
diff changeset
1941 are no fixits. */
kono
parents: 67
diff changeset
1942
kono
parents: 67
diff changeset
1943 static void
kono
parents: 67
diff changeset
1944 test_print_parseable_fixits_none ()
kono
parents: 67
diff changeset
1945 {
kono
parents: 67
diff changeset
1946 pretty_printer pp;
kono
parents: 67
diff changeset
1947 rich_location richloc (line_table, UNKNOWN_LOCATION);
kono
parents: 67
diff changeset
1948
kono
parents: 67
diff changeset
1949 print_parseable_fixits (&pp, &richloc);
kono
parents: 67
diff changeset
1950 ASSERT_STREQ ("", pp_formatted_text (&pp));
kono
parents: 67
diff changeset
1951 }
kono
parents: 67
diff changeset
1952
kono
parents: 67
diff changeset
1953 /* Verify that print_parseable_fixits does the right thing if there
kono
parents: 67
diff changeset
1954 is an insertion fixit hint. */
kono
parents: 67
diff changeset
1955
kono
parents: 67
diff changeset
1956 static void
kono
parents: 67
diff changeset
1957 test_print_parseable_fixits_insert ()
kono
parents: 67
diff changeset
1958 {
kono
parents: 67
diff changeset
1959 pretty_printer pp;
kono
parents: 67
diff changeset
1960 rich_location richloc (line_table, UNKNOWN_LOCATION);
kono
parents: 67
diff changeset
1961
kono
parents: 67
diff changeset
1962 linemap_add (line_table, LC_ENTER, false, "test.c", 0);
kono
parents: 67
diff changeset
1963 linemap_line_start (line_table, 5, 100);
kono
parents: 67
diff changeset
1964 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
kono
parents: 67
diff changeset
1965 location_t where = linemap_position_for_column (line_table, 10);
kono
parents: 67
diff changeset
1966 richloc.add_fixit_insert_before (where, "added content");
kono
parents: 67
diff changeset
1967
kono
parents: 67
diff changeset
1968 print_parseable_fixits (&pp, &richloc);
kono
parents: 67
diff changeset
1969 ASSERT_STREQ ("fix-it:\"test.c\":{5:10-5:10}:\"added content\"\n",
kono
parents: 67
diff changeset
1970 pp_formatted_text (&pp));
kono
parents: 67
diff changeset
1971 }
kono
parents: 67
diff changeset
1972
kono
parents: 67
diff changeset
1973 /* Verify that print_parseable_fixits does the right thing if there
kono
parents: 67
diff changeset
1974 is an removal fixit hint. */
kono
parents: 67
diff changeset
1975
kono
parents: 67
diff changeset
1976 static void
kono
parents: 67
diff changeset
1977 test_print_parseable_fixits_remove ()
kono
parents: 67
diff changeset
1978 {
kono
parents: 67
diff changeset
1979 pretty_printer pp;
kono
parents: 67
diff changeset
1980 rich_location richloc (line_table, UNKNOWN_LOCATION);
kono
parents: 67
diff changeset
1981
kono
parents: 67
diff changeset
1982 linemap_add (line_table, LC_ENTER, false, "test.c", 0);
kono
parents: 67
diff changeset
1983 linemap_line_start (line_table, 5, 100);
kono
parents: 67
diff changeset
1984 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
kono
parents: 67
diff changeset
1985 source_range where;
kono
parents: 67
diff changeset
1986 where.m_start = linemap_position_for_column (line_table, 10);
kono
parents: 67
diff changeset
1987 where.m_finish = linemap_position_for_column (line_table, 20);
kono
parents: 67
diff changeset
1988 richloc.add_fixit_remove (where);
kono
parents: 67
diff changeset
1989
kono
parents: 67
diff changeset
1990 print_parseable_fixits (&pp, &richloc);
kono
parents: 67
diff changeset
1991 ASSERT_STREQ ("fix-it:\"test.c\":{5:10-5:21}:\"\"\n",
kono
parents: 67
diff changeset
1992 pp_formatted_text (&pp));
kono
parents: 67
diff changeset
1993 }
kono
parents: 67
diff changeset
1994
kono
parents: 67
diff changeset
1995 /* Verify that print_parseable_fixits does the right thing if there
kono
parents: 67
diff changeset
1996 is an replacement fixit hint. */
kono
parents: 67
diff changeset
1997
kono
parents: 67
diff changeset
1998 static void
kono
parents: 67
diff changeset
1999 test_print_parseable_fixits_replace ()
kono
parents: 67
diff changeset
2000 {
kono
parents: 67
diff changeset
2001 pretty_printer pp;
kono
parents: 67
diff changeset
2002 rich_location richloc (line_table, UNKNOWN_LOCATION);
kono
parents: 67
diff changeset
2003
kono
parents: 67
diff changeset
2004 linemap_add (line_table, LC_ENTER, false, "test.c", 0);
kono
parents: 67
diff changeset
2005 linemap_line_start (line_table, 5, 100);
kono
parents: 67
diff changeset
2006 linemap_add (line_table, LC_LEAVE, false, NULL, 0);
kono
parents: 67
diff changeset
2007 source_range where;
kono
parents: 67
diff changeset
2008 where.m_start = linemap_position_for_column (line_table, 10);
kono
parents: 67
diff changeset
2009 where.m_finish = linemap_position_for_column (line_table, 20);
kono
parents: 67
diff changeset
2010 richloc.add_fixit_replace (where, "replacement");
kono
parents: 67
diff changeset
2011
kono
parents: 67
diff changeset
2012 print_parseable_fixits (&pp, &richloc);
kono
parents: 67
diff changeset
2013 ASSERT_STREQ ("fix-it:\"test.c\":{5:10-5:21}:\"replacement\"\n",
kono
parents: 67
diff changeset
2014 pp_formatted_text (&pp));
kono
parents: 67
diff changeset
2015 }
kono
parents: 67
diff changeset
2016
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2017 /* Verify that
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2018 diagnostic_get_location_text (..., SHOW_COLUMN)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2019 generates EXPECTED_LOC_TEXT, given FILENAME, LINE, COLUMN, with
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2020 colorization disabled. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2021
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2022 static void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2023 assert_location_text (const char *expected_loc_text,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2024 const char *filename, int line, int column,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2025 bool show_column)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2026 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2027 test_diagnostic_context dc;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2028 dc.show_column = show_column;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2029
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2030 expanded_location xloc;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2031 xloc.file = filename;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2032 xloc.line = line;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2033 xloc.column = column;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2034 xloc.data = NULL;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2035 xloc.sysp = false;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2036
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2037 char *actual_loc_text = diagnostic_get_location_text (&dc, xloc);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2038 ASSERT_STREQ (expected_loc_text, actual_loc_text);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2039 free (actual_loc_text);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2040 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2041
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2042 /* Verify that diagnostic_get_location_text works as expected. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2043
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2044 static void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2045 test_diagnostic_get_location_text ()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2046 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2047 const char *old_progname = progname;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2048 progname = "PROGNAME";
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2049 assert_location_text ("PROGNAME:", NULL, 0, 0, true);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2050 assert_location_text ("<built-in>:", "<built-in>", 42, 10, true);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2051 assert_location_text ("foo.c:42:10:", "foo.c", 42, 10, true);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2052 assert_location_text ("foo.c:42:", "foo.c", 42, 0, true);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2053 assert_location_text ("foo.c:", "foo.c", 0, 10, true);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2054 assert_location_text ("foo.c:42:", "foo.c", 42, 10, false);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2055 assert_location_text ("foo.c:", "foo.c", 0, 10, false);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2056
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2057 maybe_line_and_column (INT_MAX, INT_MAX);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2058 maybe_line_and_column (INT_MIN, INT_MIN);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2059
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2060 progname = old_progname;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2061 }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2062
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2063 /* Selftest for num_digits. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2064
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2065 static void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2066 test_num_digits ()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2067 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2068 ASSERT_EQ (1, num_digits (0));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2069 ASSERT_EQ (1, num_digits (9));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2070 ASSERT_EQ (2, num_digits (10));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2071 ASSERT_EQ (2, num_digits (99));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2072 ASSERT_EQ (3, num_digits (100));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2073 ASSERT_EQ (3, num_digits (999));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2074 ASSERT_EQ (4, num_digits (1000));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2075 ASSERT_EQ (4, num_digits (9999));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2076 ASSERT_EQ (5, num_digits (10000));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2077 ASSERT_EQ (5, num_digits (99999));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2078 ASSERT_EQ (6, num_digits (100000));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2079 ASSERT_EQ (6, num_digits (999999));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2080 ASSERT_EQ (7, num_digits (1000000));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2081 ASSERT_EQ (7, num_digits (9999999));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2082 ASSERT_EQ (8, num_digits (10000000));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2083 ASSERT_EQ (8, num_digits (99999999));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2084 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2085
111
kono
parents: 67
diff changeset
2086 /* Run all of the selftests within this file. */
kono
parents: 67
diff changeset
2087
kono
parents: 67
diff changeset
2088 void
kono
parents: 67
diff changeset
2089 diagnostic_c_tests ()
kono
parents: 67
diff changeset
2090 {
kono
parents: 67
diff changeset
2091 test_print_escaped_string ();
kono
parents: 67
diff changeset
2092 test_print_parseable_fixits_none ();
kono
parents: 67
diff changeset
2093 test_print_parseable_fixits_insert ();
kono
parents: 67
diff changeset
2094 test_print_parseable_fixits_remove ();
kono
parents: 67
diff changeset
2095 test_print_parseable_fixits_replace ();
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2096 test_diagnostic_get_location_text ();
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2097 test_num_digits ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2098
111
kono
parents: 67
diff changeset
2099 }
kono
parents: 67
diff changeset
2100
kono
parents: 67
diff changeset
2101 } // namespace selftest
kono
parents: 67
diff changeset
2102
kono
parents: 67
diff changeset
2103 #endif /* #if CHECKING_P */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2104
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2105 #if __GNUC__ >= 10
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2106 # pragma GCC diagnostic pop
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2107 #endif