| 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 | verbatim (const char *gmsgid, ...) |
| 48 | { |
| 49 | auto logger = global_dc->get_logger (); |
| 50 | log_function_params (logger, __func__) |
| 51 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 52 | auto_inc_log_depth depth_sentinel (logger); |
| 53 | |
| 54 | va_list ap; |
| 55 | va_start (ap, gmsgid); |
| 56 | text_info text (_(gmsgid), &ap, errno); |
| 57 | global_dc->report_verbatim (text); |
| 58 | va_end (ap); |
| 59 | } |
| 60 | |
| 61 | /* Wrapper around diagnostics::context::diagnostic_impl |
| 62 | implying global_dc and taking a variable argument list. */ |
| 63 | |
| 64 | bool |
| 65 | emit_diagnostic (enum diagnostics::kind kind, |
| 66 | location_t location, |
| 67 | diagnostics::option_id option_id, |
| 68 | const char *gmsgid, ...) |
| 69 | { |
| 70 | auto logger = global_dc->get_logger (); |
| 71 | log_function_params (logger, __func__) |
| 72 | .log_param_location_t (name: "location" , value: location) |
| 73 | .log_param_option_id (name: "option_id" , value: option_id) |
| 74 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 75 | auto_inc_log_depth depth_sentinel (logger); |
| 76 | |
| 77 | auto_diagnostic_group d; |
| 78 | va_list ap; |
| 79 | va_start (ap, gmsgid); |
| 80 | rich_location richloc (line_table, location); |
| 81 | bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, |
| 82 | gmsgid, &ap, kind); |
| 83 | va_end (ap); |
| 84 | |
| 85 | if (logger) |
| 86 | logger->log_bool_return (function_name: "emit_diagnostic" , retval: ret); |
| 87 | |
| 88 | return ret; |
| 89 | } |
| 90 | |
| 91 | /* As above, but for rich_location *. */ |
| 92 | |
| 93 | bool |
| 94 | emit_diagnostic (enum diagnostics::kind kind, |
| 95 | rich_location *richloc, |
| 96 | diagnostics::option_id option_id, |
| 97 | const char *gmsgid, ...) |
| 98 | { |
| 99 | auto logger = global_dc->get_logger (); |
| 100 | log_function_params (logger, __func__) |
| 101 | .log_param_rich_location (name: "richloc" , richloc) |
| 102 | .log_param_option_id (name: "option_id" , value: option_id) |
| 103 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 104 | auto_inc_log_depth depth_sentinel (logger); |
| 105 | |
| 106 | auto_diagnostic_group d; |
| 107 | va_list ap; |
| 108 | va_start (ap, gmsgid); |
| 109 | bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id, |
| 110 | gmsgid, &ap, kind); |
| 111 | va_end (ap); |
| 112 | |
| 113 | if (logger) |
| 114 | logger->log_bool_return (function_name: "emit_diagnostic" , retval: ret); |
| 115 | |
| 116 | return ret; |
| 117 | } |
| 118 | |
| 119 | /* As above, but taking a variable argument list. */ |
| 120 | |
| 121 | bool |
| 122 | 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 | auto logger = global_dc->get_logger (); |
| 128 | log_function_params (logger, __func__) |
| 129 | .log_param_location_t (name: "location" , value: location) |
| 130 | .log_param_option_id (name: "option_id" , value: option_id) |
| 131 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 132 | auto_inc_log_depth depth_sentinel (logger); |
| 133 | |
| 134 | rich_location richloc (line_table, location); |
| 135 | bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, |
| 136 | gmsgid, ap, kind); |
| 137 | |
| 138 | if (logger) |
| 139 | logger->log_bool_return (function_name: "emit_diagnostic_valist" , retval: ret); |
| 140 | |
| 141 | return ret; |
| 142 | } |
| 143 | |
| 144 | /* As above, but with rich_location and metadata. */ |
| 145 | |
| 146 | bool |
| 147 | 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 | auto logger = global_dc->get_logger (); |
| 154 | log_function_params (logger, __func__) |
| 155 | .log_param_rich_location (name: "richloc" , richloc) |
| 156 | .log_param_option_id (name: "option_id" , value: option_id) |
| 157 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 158 | auto_inc_log_depth depth_sentinel (logger); |
| 159 | |
| 160 | bool ret = global_dc->diagnostic_impl (richloc, metadata, option_id, |
| 161 | gmsgid, ap, kind); |
| 162 | |
| 163 | if (logger) |
| 164 | logger->log_bool_return (function_name: "emit_diagnostic_valist_meta" , retval: ret); |
| 165 | |
| 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | /* An informative note at LOCATION. Use this for additional details on an error |
| 170 | message. */ |
| 171 | void |
| 172 | inform (location_t location, const char *gmsgid, ...) |
| 173 | { |
| 174 | auto logger = global_dc->get_logger (); |
| 175 | log_function_params (logger, __func__) |
| 176 | .log_param_location_t (name: "location" , value: location) |
| 177 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 178 | auto_inc_log_depth depth_sentinel (logger); |
| 179 | |
| 180 | auto_diagnostic_group d; |
| 181 | va_list ap; |
| 182 | va_start (ap, gmsgid); |
| 183 | rich_location richloc (line_table, location); |
| 184 | global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, |
| 185 | diagnostics::kind::note); |
| 186 | va_end (ap); |
| 187 | } |
| 188 | |
| 189 | /* Same as "inform" above, but at RICHLOC. */ |
| 190 | void |
| 191 | inform (rich_location *richloc, const char *gmsgid, ...) |
| 192 | { |
| 193 | gcc_assert (richloc); |
| 194 | |
| 195 | auto logger = global_dc->get_logger (); |
| 196 | log_function_params (logger, __func__) |
| 197 | .log_param_rich_location (name: "richloc" , richloc) |
| 198 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 199 | auto_inc_log_depth depth_sentinel (logger); |
| 200 | |
| 201 | auto_diagnostic_group d; |
| 202 | va_list ap; |
| 203 | va_start (ap, gmsgid); |
| 204 | global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap, |
| 205 | diagnostics::kind::note); |
| 206 | va_end (ap); |
| 207 | } |
| 208 | |
| 209 | /* An informative note at LOCATION. Use this for additional details on an |
| 210 | error message. */ |
| 211 | void |
| 212 | inform_n (location_t location, unsigned HOST_WIDE_INT n, |
| 213 | const char *singular_gmsgid, const char *plural_gmsgid, ...) |
| 214 | { |
| 215 | auto logger = global_dc->get_logger (); |
| 216 | log_function_params (logger, __func__) |
| 217 | .log_param_location_t (name: "location" , value: location) |
| 218 | .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid); |
| 219 | auto_inc_log_depth depth_sentinel (logger); |
| 220 | |
| 221 | va_list ap; |
| 222 | va_start (ap, plural_gmsgid); |
| 223 | auto_diagnostic_group d; |
| 224 | rich_location richloc (line_table, location); |
| 225 | global_dc->diagnostic_n_impl (&richloc, nullptr, -1, n, |
| 226 | singular_gmsgid, plural_gmsgid, |
| 227 | &ap, diagnostics::kind::note); |
| 228 | va_end (ap); |
| 229 | } |
| 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 | warning (diagnostics::option_id option_id, const char *gmsgid, ...) |
| 236 | { |
| 237 | auto logger = global_dc->get_logger (); |
| 238 | log_function_params (logger, __func__) |
| 239 | .log_param_option_id (name: "option_id" , value: option_id) |
| 240 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 241 | auto_inc_log_depth depth_sentinel (logger); |
| 242 | |
| 243 | auto_diagnostic_group d; |
| 244 | va_list ap; |
| 245 | va_start (ap, gmsgid); |
| 246 | rich_location richloc (line_table, input_location); |
| 247 | bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, |
| 248 | gmsgid, &ap, |
| 249 | diagnostics::kind::warning); |
| 250 | va_end (ap); |
| 251 | |
| 252 | if (logger) |
| 253 | logger->log_bool_return (function_name: "warning" , retval: ret); |
| 254 | |
| 255 | return ret; |
| 256 | } |
| 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 | warning_at (location_t location, |
| 264 | diagnostics::option_id option_id, |
| 265 | const char *gmsgid, ...) |
| 266 | { |
| 267 | auto logger = global_dc->get_logger (); |
| 268 | log_function_params (logger, __func__) |
| 269 | .log_param_location_t (name: "location" , value: location) |
| 270 | .log_param_option_id (name: "option_id" , value: option_id) |
| 271 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 272 | auto_inc_log_depth depth_sentinel (logger); |
| 273 | |
| 274 | auto_diagnostic_group d; |
| 275 | va_list ap; |
| 276 | va_start (ap, gmsgid); |
| 277 | rich_location richloc (line_table, location); |
| 278 | bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, |
| 279 | gmsgid, &ap, |
| 280 | diagnostics::kind::warning); |
| 281 | va_end (ap); |
| 282 | |
| 283 | if (logger) |
| 284 | logger->log_bool_return (function_name: "warning_at" , retval: ret); |
| 285 | |
| 286 | return ret; |
| 287 | } |
| 288 | |
| 289 | /* Same as "warning at" above, but using RICHLOC. */ |
| 290 | |
| 291 | bool |
| 292 | warning_at (rich_location *richloc, |
| 293 | diagnostics::option_id option_id, |
| 294 | const char *gmsgid, ...) |
| 295 | { |
| 296 | gcc_assert (richloc); |
| 297 | |
| 298 | auto logger = global_dc->get_logger (); |
| 299 | log_function_params (logger, __func__) |
| 300 | .log_param_rich_location (name: "richloc" , richloc) |
| 301 | .log_param_option_id (name: "option_id" , value: option_id) |
| 302 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 303 | auto_inc_log_depth depth_sentinel (logger); |
| 304 | |
| 305 | auto_diagnostic_group d; |
| 306 | va_list ap; |
| 307 | va_start (ap, gmsgid); |
| 308 | bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id, |
| 309 | gmsgid, &ap, |
| 310 | diagnostics::kind::warning); |
| 311 | va_end (ap); |
| 312 | |
| 313 | if (logger) |
| 314 | logger->log_bool_return (function_name: "warning_at" , retval: ret); |
| 315 | |
| 316 | return ret; |
| 317 | } |
| 318 | |
| 319 | /* Same as "warning at" above, but using METADATA. */ |
| 320 | |
| 321 | bool |
| 322 | warning_meta (rich_location *richloc, |
| 323 | const diagnostics::metadata &metadata, |
| 324 | diagnostics::option_id option_id, |
| 325 | const char *gmsgid, ...) |
| 326 | { |
| 327 | gcc_assert (richloc); |
| 328 | |
| 329 | auto logger = global_dc->get_logger (); |
| 330 | log_function_params (logger, __func__) |
| 331 | .log_param_rich_location (name: "richloc" , richloc) |
| 332 | .log_param_option_id (name: "option_id" , value: option_id) |
| 333 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 334 | auto_inc_log_depth depth_sentinel (logger); |
| 335 | |
| 336 | auto_diagnostic_group d; |
| 337 | va_list ap; |
| 338 | va_start (ap, gmsgid); |
| 339 | bool ret = global_dc->diagnostic_impl (richloc, &metadata, option_id, |
| 340 | gmsgid, &ap, |
| 341 | diagnostics::kind::warning); |
| 342 | va_end (ap); |
| 343 | |
| 344 | if (logger) |
| 345 | logger->log_bool_return (function_name: "warning_meta" , retval: ret); |
| 346 | |
| 347 | return ret; |
| 348 | } |
| 349 | |
| 350 | /* Same as warning_n plural variant below, but using RICHLOC. */ |
| 351 | |
| 352 | bool |
| 353 | 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 | gcc_assert (richloc); |
| 359 | |
| 360 | auto logger = global_dc->get_logger (); |
| 361 | log_function_params (logger, __func__) |
| 362 | .log_param_rich_location (name: "richloc" , richloc) |
| 363 | .log_param_option_id (name: "option_id" , value: option_id) |
| 364 | .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid); |
| 365 | auto_inc_log_depth depth_sentinel (logger); |
| 366 | |
| 367 | auto_diagnostic_group d; |
| 368 | va_list ap; |
| 369 | va_start (ap, plural_gmsgid); |
| 370 | bool ret = global_dc->diagnostic_n_impl (richloc, nullptr, option_id, n, |
| 371 | singular_gmsgid, plural_gmsgid, |
| 372 | &ap, diagnostics::kind::warning); |
| 373 | va_end (ap); |
| 374 | |
| 375 | if (logger) |
| 376 | logger->log_bool_return (function_name: "warning_n" , retval: ret); |
| 377 | |
| 378 | return ret; |
| 379 | } |
| 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 | 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 | auto logger = global_dc->get_logger (); |
| 392 | log_function_params (logger, __func__) |
| 393 | .log_param_location_t (name: "location" , value: location) |
| 394 | .log_param_option_id (name: "option_id" , value: option_id) |
| 395 | .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid); |
| 396 | auto_inc_log_depth depth_sentinel (logger); |
| 397 | |
| 398 | auto_diagnostic_group d; |
| 399 | va_list ap; |
| 400 | va_start (ap, plural_gmsgid); |
| 401 | rich_location richloc (line_table, location); |
| 402 | bool ret = global_dc->diagnostic_n_impl (&richloc, nullptr, option_id, n, |
| 403 | singular_gmsgid, plural_gmsgid, |
| 404 | &ap, diagnostics::kind::warning); |
| 405 | va_end (ap); |
| 406 | |
| 407 | if (logger) |
| 408 | logger->log_bool_return (function_name: "warning_n" , retval: ret); |
| 409 | |
| 410 | return ret; |
| 411 | } |
| 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 | pedwarn (location_t location, |
| 428 | diagnostics::option_id option_id, |
| 429 | const char *gmsgid, ...) |
| 430 | { |
| 431 | auto logger = global_dc->get_logger (); |
| 432 | log_function_params (logger, __func__) |
| 433 | .log_param_location_t (name: "location" , value: location) |
| 434 | .log_param_option_id (name: "option_id" , value: option_id) |
| 435 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 436 | auto_inc_log_depth depth_sentinel (logger); |
| 437 | |
| 438 | auto_diagnostic_group d; |
| 439 | va_list ap; |
| 440 | va_start (ap, gmsgid); |
| 441 | rich_location richloc (line_table, location); |
| 442 | bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, |
| 443 | gmsgid, &ap, |
| 444 | diagnostics::kind::pedwarn); |
| 445 | va_end (ap); |
| 446 | |
| 447 | if (logger) |
| 448 | logger->log_bool_return (function_name: "pedwarn" , retval: ret); |
| 449 | |
| 450 | return ret; |
| 451 | } |
| 452 | |
| 453 | /* Same as pedwarn above, but using RICHLOC. */ |
| 454 | |
| 455 | bool |
| 456 | pedwarn (rich_location *richloc, |
| 457 | diagnostics::option_id option_id, |
| 458 | const char *gmsgid, ...) |
| 459 | { |
| 460 | gcc_assert (richloc); |
| 461 | |
| 462 | auto logger = global_dc->get_logger (); |
| 463 | log_function_params (logger, __func__) |
| 464 | .log_param_rich_location (name: "richloc" , richloc) |
| 465 | .log_param_option_id (name: "option_id" , value: option_id) |
| 466 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 467 | auto_inc_log_depth depth_sentinel (logger); |
| 468 | |
| 469 | auto_diagnostic_group d; |
| 470 | va_list ap; |
| 471 | va_start (ap, gmsgid); |
| 472 | bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id, |
| 473 | gmsgid, &ap, |
| 474 | diagnostics::kind::pedwarn); |
| 475 | va_end (ap); |
| 476 | |
| 477 | if (logger) |
| 478 | logger->log_bool_return (function_name: "pedwarn" , retval: ret); |
| 479 | |
| 480 | return ret; |
| 481 | } |
| 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 | permerror (location_t location, const char *gmsgid, ...) |
| 492 | { |
| 493 | auto logger = global_dc->get_logger (); |
| 494 | log_function_params (logger, __func__) |
| 495 | .log_param_location_t (name: "location" , value: location) |
| 496 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 497 | auto_inc_log_depth depth_sentinel (logger); |
| 498 | |
| 499 | auto_diagnostic_group d; |
| 500 | va_list ap; |
| 501 | va_start (ap, gmsgid); |
| 502 | rich_location richloc (line_table, location); |
| 503 | bool ret = global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, |
| 504 | diagnostics::kind::permerror); |
| 505 | va_end (ap); |
| 506 | |
| 507 | if (logger) |
| 508 | logger->log_bool_return (function_name: "permerror" , retval: ret); |
| 509 | |
| 510 | return ret; |
| 511 | } |
| 512 | |
| 513 | /* Same as "permerror" above, but at RICHLOC. */ |
| 514 | |
| 515 | bool |
| 516 | permerror (rich_location *richloc, const char *gmsgid, ...) |
| 517 | { |
| 518 | gcc_assert (richloc); |
| 519 | |
| 520 | auto logger = global_dc->get_logger (); |
| 521 | log_function_params (logger, __func__) |
| 522 | .log_param_rich_location (name: "richloc" , richloc) |
| 523 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 524 | auto_inc_log_depth depth_sentinel (logger); |
| 525 | |
| 526 | auto_diagnostic_group d; |
| 527 | va_list ap; |
| 528 | va_start (ap, gmsgid); |
| 529 | bool ret = global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap, |
| 530 | diagnostics::kind::permerror); |
| 531 | va_end (ap); |
| 532 | |
| 533 | if (logger) |
| 534 | logger->log_bool_return (function_name: "permerror" , retval: ret); |
| 535 | |
| 536 | return ret; |
| 537 | } |
| 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 | permerror_opt (location_t location, |
| 545 | diagnostics::option_id option_id, |
| 546 | const char *gmsgid, ...) |
| 547 | { |
| 548 | auto logger = global_dc->get_logger (); |
| 549 | log_function_params (logger, __func__) |
| 550 | .log_param_location_t (name: "location" , value: location) |
| 551 | .log_param_option_id (name: "option_id" , value: option_id) |
| 552 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 553 | auto_inc_log_depth depth_sentinel (logger); |
| 554 | |
| 555 | auto_diagnostic_group d; |
| 556 | va_list ap; |
| 557 | va_start (ap, gmsgid); |
| 558 | rich_location richloc (line_table, location); |
| 559 | bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id, |
| 560 | gmsgid, &ap, |
| 561 | diagnostics::kind::permerror); |
| 562 | va_end (ap); |
| 563 | |
| 564 | if (logger) |
| 565 | logger->log_bool_return (function_name: "permerror_opt" , retval: ret); |
| 566 | |
| 567 | return ret; |
| 568 | } |
| 569 | |
| 570 | /* Same as "permerror" above, but at RICHLOC. */ |
| 571 | |
| 572 | bool |
| 573 | permerror_opt (rich_location *richloc, |
| 574 | diagnostics::option_id option_id, |
| 575 | const char *gmsgid, ...) |
| 576 | { |
| 577 | gcc_assert (richloc); |
| 578 | |
| 579 | auto logger = global_dc->get_logger (); |
| 580 | log_function_params (logger, __func__) |
| 581 | .log_param_rich_location (name: "richloc" , richloc) |
| 582 | .log_param_option_id (name: "option_id" , value: option_id) |
| 583 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 584 | auto_inc_log_depth depth_sentinel (logger); |
| 585 | |
| 586 | auto_diagnostic_group d; |
| 587 | va_list ap; |
| 588 | va_start (ap, gmsgid); |
| 589 | bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id, |
| 590 | gmsgid, &ap, |
| 591 | diagnostics::kind::permerror); |
| 592 | va_end (ap); |
| 593 | |
| 594 | if (logger) |
| 595 | logger->log_bool_return (function_name: "permerror_opt" , retval: ret); |
| 596 | |
| 597 | return ret; |
| 598 | } |
| 599 | |
| 600 | /* A hard error: the code is definitely ill-formed, and an object file |
| 601 | will not be produced. */ |
| 602 | void |
| 603 | error (const char *gmsgid, ...) |
| 604 | { |
| 605 | auto logger = global_dc->get_logger (); |
| 606 | log_function_params (logger, __func__) |
| 607 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 608 | auto_inc_log_depth depth_sentinel (logger); |
| 609 | |
| 610 | auto_diagnostic_group d; |
| 611 | va_list ap; |
| 612 | va_start (ap, gmsgid); |
| 613 | rich_location richloc (line_table, input_location); |
| 614 | global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, |
| 615 | diagnostics::kind::error); |
| 616 | va_end (ap); |
| 617 | } |
| 618 | |
| 619 | /* A hard error: the code is definitely ill-formed, and an object file |
| 620 | will not be produced. */ |
| 621 | void |
| 622 | error_n (location_t location, unsigned HOST_WIDE_INT n, |
| 623 | const char *singular_gmsgid, const char *plural_gmsgid, ...) |
| 624 | { |
| 625 | auto logger = global_dc->get_logger (); |
| 626 | log_function_params (logger, __func__) |
| 627 | .log_param_location_t (name: "location" , value: location) |
| 628 | .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid); |
| 629 | auto_inc_log_depth depth_sentinel (logger); |
| 630 | |
| 631 | auto_diagnostic_group d; |
| 632 | va_list ap; |
| 633 | va_start (ap, plural_gmsgid); |
| 634 | rich_location richloc (line_table, location); |
| 635 | global_dc->diagnostic_n_impl (&richloc, nullptr, -1, n, |
| 636 | singular_gmsgid, plural_gmsgid, |
| 637 | &ap, diagnostics::kind::error); |
| 638 | va_end (ap); |
| 639 | } |
| 640 | |
| 641 | /* Same as above, but use location LOC instead of input_location. */ |
| 642 | void |
| 643 | error_at (location_t loc, const char *gmsgid, ...) |
| 644 | { |
| 645 | auto logger = global_dc->get_logger (); |
| 646 | log_function_params (logger, __func__) |
| 647 | .log_param_location_t (name: "loc" , value: loc) |
| 648 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 649 | auto_inc_log_depth depth_sentinel (logger); |
| 650 | |
| 651 | auto_diagnostic_group d; |
| 652 | va_list ap; |
| 653 | va_start (ap, gmsgid); |
| 654 | rich_location richloc (line_table, loc); |
| 655 | global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, |
| 656 | diagnostics::kind::error); |
| 657 | va_end (ap); |
| 658 | } |
| 659 | |
| 660 | /* Same as above, but use RICH_LOC. */ |
| 661 | |
| 662 | void |
| 663 | error_at (rich_location *richloc, const char *gmsgid, ...) |
| 664 | { |
| 665 | gcc_assert (richloc); |
| 666 | |
| 667 | auto logger = global_dc->get_logger (); |
| 668 | log_function_params (logger, __func__) |
| 669 | .log_param_rich_location (name: "richloc" , richloc) |
| 670 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 671 | auto_inc_log_depth depth_sentinel (logger); |
| 672 | |
| 673 | auto_diagnostic_group d; |
| 674 | va_list ap; |
| 675 | va_start (ap, gmsgid); |
| 676 | global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap, |
| 677 | diagnostics::kind::error); |
| 678 | va_end (ap); |
| 679 | } |
| 680 | |
| 681 | /* Same as above, but with metadata. */ |
| 682 | |
| 683 | void |
| 684 | error_meta (rich_location *richloc, const diagnostics::metadata &metadata, |
| 685 | const char *gmsgid, ...) |
| 686 | { |
| 687 | gcc_assert (richloc); |
| 688 | |
| 689 | auto logger = global_dc->get_logger (); |
| 690 | log_function_params (logger, __func__) |
| 691 | .log_param_rich_location (name: "richloc" , richloc) |
| 692 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 693 | auto_inc_log_depth depth_sentinel (logger); |
| 694 | |
| 695 | auto_diagnostic_group d; |
| 696 | va_list ap; |
| 697 | va_start (ap, gmsgid); |
| 698 | global_dc->diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap, |
| 699 | diagnostics::kind::error); |
| 700 | va_end (ap); |
| 701 | } |
| 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 | sorry (const char *gmsgid, ...) |
| 708 | { |
| 709 | auto logger = global_dc->get_logger (); |
| 710 | log_function_params (logger, __func__) |
| 711 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 712 | auto_inc_log_depth depth_sentinel (logger); |
| 713 | |
| 714 | auto_diagnostic_group d; |
| 715 | va_list ap; |
| 716 | va_start (ap, gmsgid); |
| 717 | rich_location richloc (line_table, input_location); |
| 718 | global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, |
| 719 | diagnostics::kind::sorry); |
| 720 | va_end (ap); |
| 721 | } |
| 722 | |
| 723 | /* Same as above, but use location LOC instead of input_location. */ |
| 724 | void |
| 725 | sorry_at (location_t loc, const char *gmsgid, ...) |
| 726 | { |
| 727 | auto logger = global_dc->get_logger (); |
| 728 | log_function_params (logger, __func__) |
| 729 | .log_param_location_t (name: "loc" , value: loc) |
| 730 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 731 | auto_inc_log_depth depth_sentinel (logger); |
| 732 | |
| 733 | auto_diagnostic_group d; |
| 734 | va_list ap; |
| 735 | va_start (ap, gmsgid); |
| 736 | rich_location richloc (line_table, loc); |
| 737 | global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, |
| 738 | diagnostics::kind::sorry); |
| 739 | va_end (ap); |
| 740 | } |
| 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 | seen_error (void) |
| 746 | { |
| 747 | 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 | fatal_error (location_t loc, const char *gmsgid, ...) |
| 755 | { |
| 756 | auto logger = global_dc->get_logger (); |
| 757 | log_function_params (logger, __func__) |
| 758 | .log_param_location_t (name: "loc" , value: loc) |
| 759 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 760 | auto_inc_log_depth depth_sentinel (logger); |
| 761 | |
| 762 | auto_diagnostic_group d; |
| 763 | va_list ap; |
| 764 | va_start (ap, gmsgid); |
| 765 | rich_location richloc (line_table, loc); |
| 766 | global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, |
| 767 | diagnostics::kind::fatal); |
| 768 | va_end (ap); |
| 769 | |
| 770 | gcc_unreachable (); |
| 771 | } |
| 772 | |
| 773 | /* An internal consistency check has failed. We make no attempt to |
| 774 | continue. */ |
| 775 | void |
| 776 | internal_error (const char *gmsgid, ...) |
| 777 | { |
| 778 | auto logger = global_dc->get_logger (); |
| 779 | log_function_params (logger, __func__) |
| 780 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 781 | auto_inc_log_depth depth_sentinel (logger); |
| 782 | |
| 783 | auto_diagnostic_group d; |
| 784 | va_list ap; |
| 785 | va_start (ap, gmsgid); |
| 786 | rich_location richloc (line_table, input_location); |
| 787 | global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, |
| 788 | diagnostics::kind::ice); |
| 789 | va_end (ap); |
| 790 | |
| 791 | 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 | internal_error_no_backtrace (const char *gmsgid, ...) |
| 799 | { |
| 800 | auto logger = global_dc->get_logger (); |
| 801 | log_function_params (logger, __func__) |
| 802 | .log_param_string (name: "gmsgid" , value: gmsgid); |
| 803 | auto_inc_log_depth depth_sentinel (logger); |
| 804 | |
| 805 | auto_diagnostic_group d; |
| 806 | va_list ap; |
| 807 | va_start (ap, gmsgid); |
| 808 | rich_location richloc (line_table, input_location); |
| 809 | global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap, |
| 810 | diagnostics::kind::ice_nobt); |
| 811 | va_end (ap); |
| 812 | |
| 813 | 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 | 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 | if (file == stderr && global_dc) |
| 830 | if (!global_dc->supports_fnotice_on_stderr_p ()) |
| 831 | return; |
| 832 | |
| 833 | va_list ap; |
| 834 | |
| 835 | va_start (ap, cmsgid); |
| 836 | vfprintf (s: file, _(cmsgid), arg: ap); |
| 837 | va_end (ap); |
| 838 | } |
| 839 | |
| 840 | /* class auto_diagnostic_group. */ |
| 841 | |
| 842 | /* Constructor: "push" this group into global_dc. */ |
| 843 | |
| 844 | auto_diagnostic_group::auto_diagnostic_group () |
| 845 | { |
| 846 | global_dc->begin_group (); |
| 847 | } |
| 848 | |
| 849 | /* Destructor: "pop" this group from global_dc. */ |
| 850 | |
| 851 | auto_diagnostic_group::~auto_diagnostic_group () |
| 852 | { |
| 853 | global_dc->end_group (); |
| 854 | } |
| 855 | |
| 856 | /* class auto_diagnostic_nesting_level. */ |
| 857 | |
| 858 | auto_diagnostic_nesting_level::auto_diagnostic_nesting_level () |
| 859 | { |
| 860 | global_dc->push_nesting_level (); |
| 861 | } |
| 862 | |
| 863 | auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level () |
| 864 | { |
| 865 | global_dc->pop_nesting_level (); |
| 866 | } |
| 867 | |