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