Branch data Line data Source code
1 : : /* Language-independent diagnostic subroutines that implicitly use global_dc.
2 : : Copyright (C) 1999-2025 Free Software Foundation, Inc.
3 : : Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify it under
8 : : the terms of the GNU General Public License as published by the Free
9 : : Software Foundation; either version 3, or (at your option) any later
10 : : version.
11 : :
12 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : : for more details.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : :
22 : : /* This file implements the parts of the language independent aspect
23 : : of diagnostic messages that implicitly use global_dc. */
24 : :
25 : : #include "config.h"
26 : : #include "system.h"
27 : : #include "coretypes.h"
28 : : #include "intl.h"
29 : : #include "diagnostic.h"
30 : : #include "diagnostics/sink.h"
31 : : #include "diagnostics/logging.h"
32 : :
33 : : /* A diagnostics::context surrogate for stderr. */
34 : : static diagnostics::context global_diagnostic_context;
35 : : diagnostics::context *global_dc = &global_diagnostic_context;
36 : :
37 : : using log_function_params = diagnostics::logging::log_function_params;
38 : : using auto_inc_log_depth = diagnostics::logging::auto_inc_depth;
39 : :
40 : : /* Standard error reporting routines in increasing order of severity. */
41 : :
42 : : /* Text to be emitted verbatim to the error message stream; this
43 : : produces no prefix and disables line-wrapping. Use rarely.
44 : : It is ignored for machine-readable output formats. */
45 : : void
46 : 0 : verbatim (const char *gmsgid, ...)
47 : : {
48 : 0 : auto logger = global_dc->get_logger ();
49 : 0 : log_function_params (logger, __func__)
50 : 0 : .log_param_string ("gmsgid", gmsgid);
51 : 0 : auto_inc_log_depth depth_sentinel (logger);
52 : :
53 : 0 : va_list ap;
54 : 0 : va_start (ap, gmsgid);
55 : 0 : text_info text (_(gmsgid), &ap, errno);
56 : 0 : global_dc->report_verbatim (text);
57 : 0 : va_end (ap);
58 : 0 : }
59 : :
60 : : /* Wrapper around diagnostics::context::diagnostic_impl
61 : : implying global_dc and taking a variable argument list. */
62 : :
63 : : bool
64 : 49538 : emit_diagnostic (enum diagnostics::kind kind,
65 : : location_t location,
66 : : diagnostics::option_id option_id,
67 : : const char *gmsgid, ...)
68 : : {
69 : 49538 : auto logger = global_dc->get_logger ();
70 : 99076 : log_function_params (logger, __func__)
71 : 49538 : .log_param_location_t ("location", location)
72 : 49538 : .log_param_option_id ("option_id", option_id)
73 : 49538 : .log_param_string ("gmsgid", gmsgid);
74 : 49538 : auto_inc_log_depth depth_sentinel (logger);
75 : :
76 : 49538 : auto_diagnostic_group d;
77 : 49538 : va_list ap;
78 : 49538 : va_start (ap, gmsgid);
79 : 49538 : rich_location richloc (line_table, location);
80 : 49538 : bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
81 : : gmsgid, &ap, kind);
82 : 49537 : va_end (ap);
83 : :
84 : 49537 : if (logger)
85 : 0 : logger->log_bool_return ("emit_diagnostic", ret);
86 : :
87 : 99074 : return ret;
88 : 49537 : }
89 : :
90 : : /* As above, but for rich_location *. */
91 : :
92 : : bool
93 : 84 : emit_diagnostic (enum diagnostics::kind kind,
94 : : rich_location *richloc,
95 : : diagnostics::option_id option_id,
96 : : const char *gmsgid, ...)
97 : : {
98 : 84 : auto logger = global_dc->get_logger ();
99 : 168 : log_function_params (logger, __func__)
100 : 84 : .log_param_rich_location ("richloc", richloc)
101 : 84 : .log_param_option_id ("option_id", option_id)
102 : 84 : .log_param_string ("gmsgid", gmsgid);
103 : 84 : auto_inc_log_depth depth_sentinel (logger);
104 : :
105 : 84 : auto_diagnostic_group d;
106 : 84 : va_list ap;
107 : 84 : va_start (ap, gmsgid);
108 : 84 : bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
109 : : gmsgid, &ap, kind);
110 : 84 : va_end (ap);
111 : :
112 : 84 : if (logger)
113 : 0 : logger->log_bool_return ("emit_diagnostic", ret);
114 : :
115 : 168 : return ret;
116 : 84 : }
117 : :
118 : : /* As above, but taking a variable argument list. */
119 : :
120 : : bool
121 : 3419 : emit_diagnostic_valist (enum diagnostics::kind kind,
122 : : location_t location,
123 : : diagnostics::option_id option_id,
124 : : const char *gmsgid, va_list *ap)
125 : : {
126 : 3419 : auto logger = global_dc->get_logger ();
127 : 6838 : log_function_params (logger, __func__)
128 : 3419 : .log_param_location_t ("location", location)
129 : 3419 : .log_param_option_id ("option_id", option_id)
130 : 3419 : .log_param_string ("gmsgid", gmsgid);
131 : 3419 : auto_inc_log_depth depth_sentinel (logger);
132 : :
133 : 3419 : rich_location richloc (line_table, location);
134 : 3419 : bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
135 : : gmsgid, ap, kind);
136 : :
137 : 3419 : if (logger)
138 : 0 : logger->log_bool_return ("emit_diagnostic_valist", ret);
139 : :
140 : 6838 : return ret;
141 : 3419 : }
142 : :
143 : : /* As above, but with rich_location and metadata. */
144 : :
145 : : bool
146 : 3918 : emit_diagnostic_valist_meta (enum diagnostics::kind kind,
147 : : rich_location *richloc,
148 : : const diagnostics::metadata *metadata,
149 : : diagnostics::option_id option_id,
150 : : const char *gmsgid, va_list *ap)
151 : : {
152 : 3918 : auto logger = global_dc->get_logger ();
153 : 7836 : log_function_params (logger, __func__)
154 : 3918 : .log_param_rich_location ("richloc", richloc)
155 : 3918 : .log_param_option_id ("option_id", option_id)
156 : 3918 : .log_param_string ("gmsgid", gmsgid);
157 : 3918 : auto_inc_log_depth depth_sentinel (logger);
158 : :
159 : 3918 : bool ret = global_dc->diagnostic_impl (richloc, metadata, option_id,
160 : : gmsgid, ap, kind);
161 : :
162 : 3918 : if (logger)
163 : 0 : logger->log_bool_return ("emit_diagnostic_valist_meta", ret);
164 : :
165 : 3918 : return ret;
166 : 3918 : }
167 : :
168 : : /* An informative note at LOCATION. Use this for additional details on an error
169 : : message. */
170 : : void
171 : 98596 : inform (location_t location, const char *gmsgid, ...)
172 : : {
173 : 98596 : auto logger = global_dc->get_logger ();
174 : 197192 : log_function_params (logger, __func__)
175 : 98596 : .log_param_location_t ("location", location)
176 : 98596 : .log_param_string ("gmsgid", gmsgid);
177 : 98596 : auto_inc_log_depth depth_sentinel (logger);
178 : :
179 : 98596 : auto_diagnostic_group d;
180 : 98596 : va_list ap;
181 : 98596 : va_start (ap, gmsgid);
182 : 98596 : rich_location richloc (line_table, location);
183 : 98596 : global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
184 : : diagnostics::kind::note);
185 : 98596 : va_end (ap);
186 : 98596 : }
187 : :
188 : : /* Same as "inform" above, but at RICHLOC. */
189 : : void
190 : 4232 : inform (rich_location *richloc, const char *gmsgid, ...)
191 : : {
192 : 4232 : gcc_assert (richloc);
193 : :
194 : 4232 : auto logger = global_dc->get_logger ();
195 : 8464 : log_function_params (logger, __func__)
196 : 4232 : .log_param_rich_location ("richloc", richloc)
197 : 4232 : .log_param_string ("gmsgid", gmsgid);
198 : 4232 : auto_inc_log_depth depth_sentinel (logger);
199 : :
200 : 4232 : auto_diagnostic_group d;
201 : 4232 : va_list ap;
202 : 4232 : va_start (ap, gmsgid);
203 : 4232 : global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
204 : : diagnostics::kind::note);
205 : 4232 : va_end (ap);
206 : 4232 : }
207 : :
208 : : /* An informative note at LOCATION. Use this for additional details on an
209 : : error message. */
210 : : void
211 : 7359 : inform_n (location_t location, unsigned HOST_WIDE_INT n,
212 : : const char *singular_gmsgid, const char *plural_gmsgid, ...)
213 : : {
214 : 7359 : auto logger = global_dc->get_logger ();
215 : 14718 : log_function_params (logger, __func__)
216 : 7359 : .log_param_location_t ("location", location)
217 : 7359 : .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
218 : 7359 : auto_inc_log_depth depth_sentinel (logger);
219 : :
220 : 7359 : va_list ap;
221 : 7359 : va_start (ap, plural_gmsgid);
222 : 7359 : auto_diagnostic_group d;
223 : 7359 : rich_location richloc (line_table, location);
224 : 7359 : global_dc->diagnostic_n_impl (&richloc, nullptr, -1, n,
225 : : singular_gmsgid, plural_gmsgid,
226 : : &ap, diagnostics::kind::note);
227 : 7359 : va_end (ap);
228 : 7359 : }
229 : :
230 : : /* A warning at INPUT_LOCATION. Use this for code which is correct according
231 : : to the relevant language specification but is likely to be buggy anyway.
232 : : Returns true if the warning was printed, false if it was inhibited. */
233 : : bool
234 : 87389155 : warning (diagnostics::option_id option_id, const char *gmsgid, ...)
235 : : {
236 : 87389155 : auto logger = global_dc->get_logger ();
237 : 174778310 : log_function_params (logger, __func__)
238 : 87389155 : .log_param_option_id ("option_id", option_id)
239 : 87389155 : .log_param_string ("gmsgid", gmsgid);
240 : 87389155 : auto_inc_log_depth depth_sentinel (logger);
241 : :
242 : 87389155 : auto_diagnostic_group d;
243 : 87389155 : va_list ap;
244 : 87389155 : va_start (ap, gmsgid);
245 : 87389155 : rich_location richloc (line_table, input_location);
246 : 87389155 : bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
247 : : gmsgid, &ap,
248 : : diagnostics::kind::warning);
249 : 87389154 : va_end (ap);
250 : :
251 : 87389154 : if (logger)
252 : 0 : logger->log_bool_return ("warning", ret);
253 : :
254 : 174778308 : return ret;
255 : 87389154 : }
256 : :
257 : : /* A warning at LOCATION. Use this for code which is correct according to the
258 : : relevant language specification but is likely to be buggy anyway.
259 : : Returns true if the warning was printed, false if it was inhibited. */
260 : :
261 : : bool
262 : 4684294 : warning_at (location_t location,
263 : : diagnostics::option_id option_id,
264 : : const char *gmsgid, ...)
265 : : {
266 : 4684294 : auto logger = global_dc->get_logger ();
267 : 9368588 : log_function_params (logger, __func__)
268 : 4684294 : .log_param_location_t ("location", location)
269 : 4684294 : .log_param_option_id ("option_id", option_id)
270 : 4684294 : .log_param_string ("gmsgid", gmsgid);
271 : 4684294 : auto_inc_log_depth depth_sentinel (logger);
272 : :
273 : 4684294 : auto_diagnostic_group d;
274 : 4684294 : va_list ap;
275 : 4684294 : va_start (ap, gmsgid);
276 : 4684294 : rich_location richloc (line_table, location);
277 : 4684294 : bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
278 : : gmsgid, &ap,
279 : : diagnostics::kind::warning);
280 : 4684288 : va_end (ap);
281 : :
282 : 4684288 : if (logger)
283 : 0 : logger->log_bool_return ("warning_at", ret);
284 : :
285 : 9368576 : return ret;
286 : 4684288 : }
287 : :
288 : : /* Same as "warning at" above, but using RICHLOC. */
289 : :
290 : : bool
291 : 7610 : warning_at (rich_location *richloc,
292 : : diagnostics::option_id option_id,
293 : : const char *gmsgid, ...)
294 : : {
295 : 7610 : gcc_assert (richloc);
296 : :
297 : 7610 : auto logger = global_dc->get_logger ();
298 : 15220 : log_function_params (logger, __func__)
299 : 7610 : .log_param_rich_location ("richloc", richloc)
300 : 7610 : .log_param_option_id ("option_id", option_id)
301 : 7610 : .log_param_string ("gmsgid", gmsgid);
302 : 7610 : auto_inc_log_depth depth_sentinel (logger);
303 : :
304 : 7610 : auto_diagnostic_group d;
305 : 7610 : va_list ap;
306 : 7610 : va_start (ap, gmsgid);
307 : 7610 : bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
308 : : gmsgid, &ap,
309 : : diagnostics::kind::warning);
310 : 7610 : va_end (ap);
311 : :
312 : 7610 : if (logger)
313 : 0 : logger->log_bool_return ("warning_at", ret);
314 : :
315 : 15220 : return ret;
316 : 7610 : }
317 : :
318 : : /* Same as "warning at" above, but using METADATA. */
319 : :
320 : : bool
321 : 13 : warning_meta (rich_location *richloc,
322 : : const diagnostics::metadata &metadata,
323 : : diagnostics::option_id option_id,
324 : : const char *gmsgid, ...)
325 : : {
326 : 13 : gcc_assert (richloc);
327 : :
328 : 13 : auto logger = global_dc->get_logger ();
329 : 26 : log_function_params (logger, __func__)
330 : 13 : .log_param_rich_location ("richloc", richloc)
331 : 13 : .log_param_option_id ("option_id", option_id)
332 : 13 : .log_param_string ("gmsgid", gmsgid);
333 : 13 : auto_inc_log_depth depth_sentinel (logger);
334 : :
335 : 13 : auto_diagnostic_group d;
336 : 13 : va_list ap;
337 : 13 : va_start (ap, gmsgid);
338 : 13 : bool ret = global_dc->diagnostic_impl (richloc, &metadata, option_id,
339 : : gmsgid, &ap,
340 : : diagnostics::kind::warning);
341 : 13 : va_end (ap);
342 : :
343 : 13 : if (logger)
344 : 0 : logger->log_bool_return ("warning_meta", ret);
345 : :
346 : 26 : return ret;
347 : 13 : }
348 : :
349 : : /* Same as warning_n plural variant below, but using RICHLOC. */
350 : :
351 : : bool
352 : 1794 : warning_n (rich_location *richloc,
353 : : diagnostics::option_id option_id,
354 : : unsigned HOST_WIDE_INT n,
355 : : const char *singular_gmsgid, const char *plural_gmsgid, ...)
356 : : {
357 : 1794 : gcc_assert (richloc);
358 : :
359 : 1794 : auto logger = global_dc->get_logger ();
360 : 3588 : log_function_params (logger, __func__)
361 : 1794 : .log_param_rich_location ("richloc", richloc)
362 : 1794 : .log_param_option_id ("option_id", option_id)
363 : 1794 : .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
364 : 1794 : auto_inc_log_depth depth_sentinel (logger);
365 : :
366 : 1794 : auto_diagnostic_group d;
367 : 1794 : va_list ap;
368 : 1794 : va_start (ap, plural_gmsgid);
369 : 1794 : bool ret = global_dc->diagnostic_n_impl (richloc, nullptr, option_id, n,
370 : : singular_gmsgid, plural_gmsgid,
371 : : &ap, diagnostics::kind::warning);
372 : 1794 : va_end (ap);
373 : :
374 : 1794 : if (logger)
375 : 0 : logger->log_bool_return ("warning_n", ret);
376 : :
377 : 3588 : return ret;
378 : 1794 : }
379 : :
380 : : /* A warning at LOCATION. Use this for code which is correct according to the
381 : : relevant language specification but is likely to be buggy anyway.
382 : : Returns true if the warning was printed, false if it was inhibited. */
383 : :
384 : : bool
385 : 2679 : warning_n (location_t location,
386 : : diagnostics::option_id option_id,
387 : : unsigned HOST_WIDE_INT n,
388 : : const char *singular_gmsgid, const char *plural_gmsgid, ...)
389 : : {
390 : 2679 : auto logger = global_dc->get_logger ();
391 : 5358 : log_function_params (logger, __func__)
392 : 2679 : .log_param_location_t ("location", location)
393 : 2679 : .log_param_option_id ("option_id", option_id)
394 : 2679 : .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
395 : 2679 : auto_inc_log_depth depth_sentinel (logger);
396 : :
397 : 2679 : auto_diagnostic_group d;
398 : 2679 : va_list ap;
399 : 2679 : va_start (ap, plural_gmsgid);
400 : 2679 : rich_location richloc (line_table, location);
401 : 2679 : bool ret = global_dc->diagnostic_n_impl (&richloc, nullptr, option_id, n,
402 : : singular_gmsgid, plural_gmsgid,
403 : : &ap, diagnostics::kind::warning);
404 : 2679 : va_end (ap);
405 : :
406 : 2679 : if (logger)
407 : 0 : logger->log_bool_return ("warning_n", ret);
408 : :
409 : 5358 : return ret;
410 : 2679 : }
411 : :
412 : : /* A "pedantic" warning at LOCATION: issues a warning unless
413 : : -pedantic-errors was given on the command line, in which case it
414 : : issues an error. Use this for diagnostics required by the relevant
415 : : language standard, if you have chosen not to make them errors.
416 : :
417 : : Note that these diagnostics are issued independent of the setting
418 : : of the -Wpedantic command-line switch. To get a warning enabled
419 : : only with that switch, use either "if (pedantic) pedwarn
420 : : (OPT_Wpedantic,...)" or just "pedwarn (OPT_Wpedantic,..)". To get a
421 : : pedwarn independently of the -Wpedantic switch use "pedwarn (0,...)".
422 : :
423 : : Returns true if the warning was printed, false if it was inhibited. */
424 : :
425 : : bool
426 : 363735 : pedwarn (location_t location,
427 : : diagnostics::option_id option_id,
428 : : const char *gmsgid, ...)
429 : : {
430 : 363735 : auto logger = global_dc->get_logger ();
431 : 727470 : log_function_params (logger, __func__)
432 : 363735 : .log_param_location_t ("location", location)
433 : 363735 : .log_param_option_id ("option_id", option_id)
434 : 363735 : .log_param_string ("gmsgid", gmsgid);
435 : 363735 : auto_inc_log_depth depth_sentinel (logger);
436 : :
437 : 363735 : auto_diagnostic_group d;
438 : 363735 : va_list ap;
439 : 363735 : va_start (ap, gmsgid);
440 : 363735 : rich_location richloc (line_table, location);
441 : 363735 : bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
442 : : gmsgid, &ap,
443 : : diagnostics::kind::pedwarn);
444 : 363735 : va_end (ap);
445 : :
446 : 363735 : if (logger)
447 : 0 : logger->log_bool_return ("pedwarn", ret);
448 : :
449 : 727470 : return ret;
450 : 363735 : }
451 : :
452 : : /* Same as pedwarn above, but using RICHLOC. */
453 : :
454 : : bool
455 : 228 : pedwarn (rich_location *richloc,
456 : : diagnostics::option_id option_id,
457 : : const char *gmsgid, ...)
458 : : {
459 : 228 : gcc_assert (richloc);
460 : :
461 : 228 : auto logger = global_dc->get_logger ();
462 : 456 : log_function_params (logger, __func__)
463 : 228 : .log_param_rich_location ("richloc", richloc)
464 : 228 : .log_param_option_id ("option_id", option_id)
465 : 228 : .log_param_string ("gmsgid", gmsgid);
466 : 228 : auto_inc_log_depth depth_sentinel (logger);
467 : :
468 : 228 : auto_diagnostic_group d;
469 : 228 : va_list ap;
470 : 228 : va_start (ap, gmsgid);
471 : 228 : bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
472 : : gmsgid, &ap,
473 : : diagnostics::kind::pedwarn);
474 : 228 : va_end (ap);
475 : :
476 : 228 : if (logger)
477 : 0 : logger->log_bool_return ("pedwarn", ret);
478 : :
479 : 456 : return ret;
480 : 228 : }
481 : :
482 : : /* A "permissive" error at LOCATION: issues an error unless
483 : : -fpermissive was given on the command line, in which case it issues
484 : : a warning. Use this for things that really should be errors but we
485 : : want to support legacy code.
486 : :
487 : : Returns true if the warning was printed, false if it was inhibited. */
488 : :
489 : : bool
490 : 2388 : permerror (location_t location, const char *gmsgid, ...)
491 : : {
492 : 2388 : auto logger = global_dc->get_logger ();
493 : 4776 : log_function_params (logger, __func__)
494 : 2388 : .log_param_location_t ("location", location)
495 : 2388 : .log_param_string ("gmsgid", gmsgid);
496 : 2388 : auto_inc_log_depth depth_sentinel (logger);
497 : :
498 : 2388 : auto_diagnostic_group d;
499 : 2388 : va_list ap;
500 : 2388 : va_start (ap, gmsgid);
501 : 2388 : rich_location richloc (line_table, location);
502 : 2388 : bool ret = global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
503 : : diagnostics::kind::permerror);
504 : 2388 : va_end (ap);
505 : :
506 : 2388 : if (logger)
507 : 0 : logger->log_bool_return ("permerror", ret);
508 : :
509 : 4776 : return ret;
510 : 2388 : }
511 : :
512 : : /* Same as "permerror" above, but at RICHLOC. */
513 : :
514 : : bool
515 : 1496 : permerror (rich_location *richloc, const char *gmsgid, ...)
516 : : {
517 : 1496 : gcc_assert (richloc);
518 : :
519 : 1496 : auto logger = global_dc->get_logger ();
520 : 2992 : log_function_params (logger, __func__)
521 : 1496 : .log_param_rich_location ("richloc", richloc)
522 : 1496 : .log_param_string ("gmsgid", gmsgid);
523 : 1496 : auto_inc_log_depth depth_sentinel (logger);
524 : :
525 : 1496 : auto_diagnostic_group d;
526 : 1496 : va_list ap;
527 : 1496 : va_start (ap, gmsgid);
528 : 1496 : bool ret = global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
529 : : diagnostics::kind::permerror);
530 : 1496 : va_end (ap);
531 : :
532 : 1496 : if (logger)
533 : 0 : logger->log_bool_return ("permerror", ret);
534 : :
535 : 2992 : return ret;
536 : 1496 : }
537 : :
538 : : /* Similar to the above, but controlled by a flag other than -fpermissive.
539 : : As above, an error by default or a warning with -fpermissive, but this
540 : : diagnostic can also be downgraded by -Wno-error=opt. */
541 : :
542 : : bool
543 : 12224 : permerror_opt (location_t location,
544 : : diagnostics::option_id option_id,
545 : : const char *gmsgid, ...)
546 : : {
547 : 12224 : auto logger = global_dc->get_logger ();
548 : 24448 : log_function_params (logger, __func__)
549 : 12224 : .log_param_location_t ("location", location)
550 : 12224 : .log_param_option_id ("option_id", option_id)
551 : 12224 : .log_param_string ("gmsgid", gmsgid);
552 : 12224 : auto_inc_log_depth depth_sentinel (logger);
553 : :
554 : 12224 : auto_diagnostic_group d;
555 : 12224 : va_list ap;
556 : 12224 : va_start (ap, gmsgid);
557 : 12224 : rich_location richloc (line_table, location);
558 : 12224 : bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
559 : : gmsgid, &ap,
560 : : diagnostics::kind::permerror);
561 : 12224 : va_end (ap);
562 : :
563 : 12224 : if (logger)
564 : 0 : logger->log_bool_return ("permerror_opt", ret);
565 : :
566 : 24448 : return ret;
567 : 12224 : }
568 : :
569 : : /* Same as "permerror" above, but at RICHLOC. */
570 : :
571 : : bool
572 : 1556 : permerror_opt (rich_location *richloc,
573 : : diagnostics::option_id option_id,
574 : : const char *gmsgid, ...)
575 : : {
576 : 1556 : gcc_assert (richloc);
577 : :
578 : 1556 : auto logger = global_dc->get_logger ();
579 : 3112 : log_function_params (logger, __func__)
580 : 1556 : .log_param_rich_location ("richloc", richloc)
581 : 1556 : .log_param_option_id ("option_id", option_id)
582 : 1556 : .log_param_string ("gmsgid", gmsgid);
583 : 1556 : auto_inc_log_depth depth_sentinel (logger);
584 : :
585 : 1556 : auto_diagnostic_group d;
586 : 1556 : va_list ap;
587 : 1556 : va_start (ap, gmsgid);
588 : 1556 : bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
589 : : gmsgid, &ap,
590 : : diagnostics::kind::permerror);
591 : 1556 : va_end (ap);
592 : :
593 : 1556 : if (logger)
594 : 0 : logger->log_bool_return ("permerror_opt", ret);
595 : :
596 : 3112 : return ret;
597 : 1556 : }
598 : :
599 : : /* A hard error: the code is definitely ill-formed, and an object file
600 : : will not be produced. */
601 : : void
602 : 21487 : error (const char *gmsgid, ...)
603 : : {
604 : 21487 : auto logger = global_dc->get_logger ();
605 : 42974 : log_function_params (logger, __func__)
606 : 21487 : .log_param_string ("gmsgid", gmsgid);
607 : 21487 : auto_inc_log_depth depth_sentinel (logger);
608 : :
609 : 21487 : auto_diagnostic_group d;
610 : 21487 : va_list ap;
611 : 21487 : va_start (ap, gmsgid);
612 : 21487 : rich_location richloc (line_table, input_location);
613 : 21487 : global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
614 : : diagnostics::kind::error);
615 : 21487 : va_end (ap);
616 : 21487 : }
617 : :
618 : : /* A hard error: the code is definitely ill-formed, and an object file
619 : : will not be produced. */
620 : : void
621 : 89 : error_n (location_t location, unsigned HOST_WIDE_INT n,
622 : : const char *singular_gmsgid, const char *plural_gmsgid, ...)
623 : : {
624 : 89 : auto logger = global_dc->get_logger ();
625 : 178 : log_function_params (logger, __func__)
626 : 89 : .log_param_location_t ("location", location)
627 : 89 : .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
628 : 89 : auto_inc_log_depth depth_sentinel (logger);
629 : :
630 : 89 : auto_diagnostic_group d;
631 : 89 : va_list ap;
632 : 89 : va_start (ap, plural_gmsgid);
633 : 89 : rich_location richloc (line_table, location);
634 : 89 : global_dc->diagnostic_n_impl (&richloc, nullptr, -1, n,
635 : : singular_gmsgid, plural_gmsgid,
636 : : &ap, diagnostics::kind::error);
637 : 89 : va_end (ap);
638 : 89 : }
639 : :
640 : : /* Same as above, but use location LOC instead of input_location. */
641 : : void
642 : 73125 : error_at (location_t loc, const char *gmsgid, ...)
643 : : {
644 : 73125 : auto logger = global_dc->get_logger ();
645 : 146250 : log_function_params (logger, __func__)
646 : 73125 : .log_param_location_t ("loc", loc)
647 : 73125 : .log_param_string ("gmsgid", gmsgid);
648 : 73125 : auto_inc_log_depth depth_sentinel (logger);
649 : :
650 : 73125 : auto_diagnostic_group d;
651 : 73125 : va_list ap;
652 : 73125 : va_start (ap, gmsgid);
653 : 73125 : rich_location richloc (line_table, loc);
654 : 73125 : global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
655 : : diagnostics::kind::error);
656 : 73125 : va_end (ap);
657 : 73125 : }
658 : :
659 : : /* Same as above, but use RICH_LOC. */
660 : :
661 : : void
662 : 13137 : error_at (rich_location *richloc, const char *gmsgid, ...)
663 : : {
664 : 13137 : gcc_assert (richloc);
665 : :
666 : 13137 : auto logger = global_dc->get_logger ();
667 : 26274 : log_function_params (logger, __func__)
668 : 13137 : .log_param_rich_location ("richloc", richloc)
669 : 13137 : .log_param_string ("gmsgid", gmsgid);
670 : 13137 : auto_inc_log_depth depth_sentinel (logger);
671 : :
672 : 13137 : auto_diagnostic_group d;
673 : 13137 : va_list ap;
674 : 13137 : va_start (ap, gmsgid);
675 : 13137 : global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
676 : : diagnostics::kind::error);
677 : 13137 : va_end (ap);
678 : 13137 : }
679 : :
680 : : /* Same as above, but with metadata. */
681 : :
682 : : void
683 : 401 : error_meta (rich_location *richloc, const diagnostics::metadata &metadata,
684 : : const char *gmsgid, ...)
685 : : {
686 : 401 : gcc_assert (richloc);
687 : :
688 : 401 : auto logger = global_dc->get_logger ();
689 : 802 : log_function_params (logger, __func__)
690 : 401 : .log_param_rich_location ("richloc", richloc)
691 : 401 : .log_param_string ("gmsgid", gmsgid);
692 : 401 : auto_inc_log_depth depth_sentinel (logger);
693 : :
694 : 401 : auto_diagnostic_group d;
695 : 401 : va_list ap;
696 : 401 : va_start (ap, gmsgid);
697 : 401 : global_dc->diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap,
698 : : diagnostics::kind::error);
699 : 401 : va_end (ap);
700 : 401 : }
701 : :
702 : : /* "Sorry, not implemented." Use for a language feature which is
703 : : required by the relevant specification but not implemented by GCC.
704 : : An object file will not be produced. */
705 : : void
706 : 99 : sorry (const char *gmsgid, ...)
707 : : {
708 : 99 : auto logger = global_dc->get_logger ();
709 : 198 : log_function_params (logger, __func__)
710 : 99 : .log_param_string ("gmsgid", gmsgid);
711 : 99 : auto_inc_log_depth depth_sentinel (logger);
712 : :
713 : 99 : auto_diagnostic_group d;
714 : 99 : va_list ap;
715 : 99 : va_start (ap, gmsgid);
716 : 99 : rich_location richloc (line_table, input_location);
717 : 99 : global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
718 : : diagnostics::kind::sorry);
719 : 99 : va_end (ap);
720 : 99 : }
721 : :
722 : : /* Same as above, but use location LOC instead of input_location. */
723 : : void
724 : 394 : sorry_at (location_t loc, const char *gmsgid, ...)
725 : : {
726 : 394 : auto logger = global_dc->get_logger ();
727 : 788 : log_function_params (logger, __func__)
728 : 394 : .log_param_location_t ("loc", loc)
729 : 394 : .log_param_string ("gmsgid", gmsgid);
730 : 394 : auto_inc_log_depth depth_sentinel (logger);
731 : :
732 : 394 : auto_diagnostic_group d;
733 : 394 : va_list ap;
734 : 394 : va_start (ap, gmsgid);
735 : 394 : rich_location richloc (line_table, loc);
736 : 394 : global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
737 : : diagnostics::kind::sorry);
738 : 390 : va_end (ap);
739 : 390 : }
740 : :
741 : : /* Return true if an error or a "sorry" has been seen on global_dc. Various
742 : : processing is disabled after errors. */
743 : : bool
744 : 1399870730 : seen_error (void)
745 : : {
746 : 1399870730 : return errorcount || sorrycount;
747 : : }
748 : :
749 : : /* An error which is severe enough that we make no attempt to
750 : : continue. Do not use this for internal consistency checks; that's
751 : : internal_error. Use of this function should be rare. */
752 : : void
753 : 309 : fatal_error (location_t loc, const char *gmsgid, ...)
754 : : {
755 : 309 : auto logger = global_dc->get_logger ();
756 : 618 : log_function_params (logger, __func__)
757 : 309 : .log_param_location_t ("loc", loc)
758 : 309 : .log_param_string ("gmsgid", gmsgid);
759 : 309 : auto_inc_log_depth depth_sentinel (logger);
760 : :
761 : 309 : auto_diagnostic_group d;
762 : 309 : va_list ap;
763 : 309 : va_start (ap, gmsgid);
764 : 309 : rich_location richloc (line_table, loc);
765 : 309 : global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
766 : : diagnostics::kind::fatal);
767 : 0 : va_end (ap);
768 : :
769 : 0 : gcc_unreachable ();
770 : : }
771 : :
772 : : /* An internal consistency check has failed. We make no attempt to
773 : : continue. */
774 : : void
775 : 50 : internal_error (const char *gmsgid, ...)
776 : : {
777 : 50 : auto logger = global_dc->get_logger ();
778 : 100 : log_function_params (logger, __func__)
779 : 50 : .log_param_string ("gmsgid", gmsgid);
780 : 50 : auto_inc_log_depth depth_sentinel (logger);
781 : :
782 : 50 : auto_diagnostic_group d;
783 : 50 : va_list ap;
784 : 50 : va_start (ap, gmsgid);
785 : 50 : rich_location richloc (line_table, input_location);
786 : 50 : global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
787 : : diagnostics::kind::ice);
788 : 0 : va_end (ap);
789 : :
790 : 0 : gcc_unreachable ();
791 : : }
792 : :
793 : : /* Like internal_error, but no backtrace will be printed. Used when
794 : : the internal error does not happen at the current location, but happened
795 : : somewhere else. */
796 : : void
797 : 0 : internal_error_no_backtrace (const char *gmsgid, ...)
798 : : {
799 : 0 : auto logger = global_dc->get_logger ();
800 : 0 : log_function_params (logger, __func__)
801 : 0 : .log_param_string ("gmsgid", gmsgid);
802 : 0 : auto_inc_log_depth depth_sentinel (logger);
803 : :
804 : 0 : auto_diagnostic_group d;
805 : 0 : va_list ap;
806 : 0 : va_start (ap, gmsgid);
807 : 0 : rich_location richloc (line_table, input_location);
808 : 0 : global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
809 : : diagnostics::kind::ice_nobt);
810 : 0 : va_end (ap);
811 : :
812 : 0 : gcc_unreachable ();
813 : : }
814 : :
815 : :
816 : : /* Special case error functions. Most are implemented in terms of the
817 : : above, or should be. */
818 : :
819 : : /* Print a diagnostic MSGID on FILE. This is just fprintf, except it
820 : : runs its second argument through gettext. */
821 : : void
822 : 21233 : fnotice (FILE *file, const char *cmsgid, ...)
823 : : {
824 : : /* If the user requested one of the machine-readable diagnostic output
825 : : formats on stderr (e.g. -fdiagnostics-format=sarif-stderr), then
826 : : emitting free-form text on stderr will lead to corrupt output.
827 : : Skip the message for such cases. */
828 : 21233 : if (file == stderr && global_dc)
829 : 18191 : if (!global_dc->supports_fnotice_on_stderr_p ())
830 : 0 : return;
831 : :
832 : 21233 : va_list ap;
833 : :
834 : 21233 : va_start (ap, cmsgid);
835 : 21233 : vfprintf (file, _(cmsgid), ap);
836 : 21233 : va_end (ap);
837 : : }
838 : :
839 : : /* class auto_diagnostic_group. */
840 : :
841 : : /* Constructor: "push" this group into global_dc. */
842 : :
843 : 857627555 : auto_diagnostic_group::auto_diagnostic_group ()
844 : : {
845 : 857627555 : global_dc->begin_group ();
846 : 857627555 : }
847 : :
848 : : /* Destructor: "pop" this group from global_dc. */
849 : :
850 : 857627139 : auto_diagnostic_group::~auto_diagnostic_group ()
851 : : {
852 : 857627139 : global_dc->end_group ();
853 : 857627139 : }
854 : :
855 : : /* class auto_diagnostic_nesting_level. */
856 : :
857 : 29095 : auto_diagnostic_nesting_level::auto_diagnostic_nesting_level ()
858 : : {
859 : 29095 : global_dc->push_nesting_level ();
860 : 29095 : }
861 : :
862 : 29095 : auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level ()
863 : : {
864 : 29095 : global_dc->pop_nesting_level ();
865 : 29095 : }
|