LCOV - code coverage report
Current view: top level - gcc - diagnostic-global-context.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 90.4 % 457 413
Test Date: 2026-11-14 16:39:50 Functions: 94.4 % 36 34
Legend: Lines:     hit not hit

            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        50108 : emit_diagnostic (enum diagnostics::kind kind,
      66              :                  location_t location,
      67              :                  diagnostics::option_id option_id,
      68              :                  const char *gmsgid, ...)
      69              : {
      70        50108 :   auto logger = global_dc->get_logger ();
      71       100216 :   log_function_params (logger, __func__)
      72        50108 :     .log_param_location_t ("location", location)
      73        50108 :     .log_param_option_id ("option_id", option_id)
      74        50108 :     .log_param_string ("gmsgid", gmsgid);
      75        50108 :   auto_inc_log_depth depth_sentinel (logger);
      76              : 
      77        50108 :   auto_diagnostic_group d;
      78        50108 :   va_list ap;
      79        50108 :   va_start (ap, gmsgid);
      80        50108 :   rich_location richloc (line_table, location);
      81        50108 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
      82              :                                          gmsgid, &ap, kind);
      83        50107 :   va_end (ap);
      84              : 
      85        50107 :   if (logger)
      86            0 :     logger->log_bool_return ("emit_diagnostic", ret);
      87              : 
      88       100214 :   return ret;
      89        50107 : }
      90              : 
      91              : /* As above, but for rich_location *.  */
      92              : 
      93              : bool
      94          142 : emit_diagnostic (enum diagnostics::kind kind,
      95              :                  rich_location *richloc,
      96              :                  diagnostics::option_id option_id,
      97              :                  const char *gmsgid, ...)
      98              : {
      99          142 :   auto logger = global_dc->get_logger ();
     100          284 :   log_function_params (logger, __func__)
     101          142 :     .log_param_rich_location ("richloc", richloc)
     102          142 :     .log_param_option_id ("option_id", option_id)
     103          142 :     .log_param_string ("gmsgid", gmsgid);
     104          142 :   auto_inc_log_depth depth_sentinel (logger);
     105              : 
     106          142 :   auto_diagnostic_group d;
     107          142 :   va_list ap;
     108          142 :   va_start (ap, gmsgid);
     109          142 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
     110              :                                          gmsgid, &ap, kind);
     111          142 :   va_end (ap);
     112              : 
     113          142 :   if (logger)
     114            0 :     logger->log_bool_return ("emit_diagnostic", ret);
     115              : 
     116          284 :   return ret;
     117          142 : }
     118              : 
     119              : /* As above, but taking a variable argument list.  */
     120              : 
     121              : bool
     122         3428 : 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         3428 :   auto logger = global_dc->get_logger ();
     128         6856 :   log_function_params (logger, __func__)
     129         3428 :     .log_param_location_t ("location", location)
     130         3428 :     .log_param_option_id ("option_id", option_id)
     131         3428 :     .log_param_string ("gmsgid", gmsgid);
     132         3428 :   auto_inc_log_depth depth_sentinel (logger);
     133              : 
     134         3428 :   rich_location richloc (line_table, location);
     135         3428 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     136              :                                          gmsgid, ap, kind);
     137              : 
     138         3428 :   if (logger)
     139            0 :     logger->log_bool_return ("emit_diagnostic_valist", ret);
     140              : 
     141         6856 :   return ret;
     142         3428 : }
     143              : 
     144              : /* As above, but with rich_location and metadata.  */
     145              : 
     146              : bool
     147         4331 : 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         4331 :   auto logger = global_dc->get_logger ();
     154         8662 :   log_function_params (logger, __func__)
     155         4331 :     .log_param_rich_location ("richloc", richloc)
     156         4331 :     .log_param_option_id ("option_id", option_id)
     157         4331 :     .log_param_string ("gmsgid", gmsgid);
     158         4331 :   auto_inc_log_depth depth_sentinel (logger);
     159              : 
     160         4331 :   bool ret = global_dc->diagnostic_impl (richloc, metadata, option_id,
     161              :                                          gmsgid, ap, kind);
     162              : 
     163         4331 :   if (logger)
     164            0 :     logger->log_bool_return ("emit_diagnostic_valist_meta", ret);
     165              : 
     166         4331 :   return ret;
     167         4331 : }
     168              : 
     169              : /* An informative note at LOCATION.  Use this for additional details on an error
     170              :    message.  */
     171              : void
     172       124842 : inform (location_t location, const char *gmsgid, ...)
     173              : {
     174       124842 :   auto logger = global_dc->get_logger ();
     175       249684 :   log_function_params (logger, __func__)
     176       124842 :     .log_param_location_t ("location", location)
     177       124842 :     .log_param_string ("gmsgid", gmsgid);
     178       124842 :   auto_inc_log_depth depth_sentinel (logger);
     179              : 
     180       124842 :   auto_diagnostic_group d;
     181       124842 :   va_list ap;
     182       124842 :   va_start (ap, gmsgid);
     183       124842 :   rich_location richloc (line_table, location);
     184       124842 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     185              :                               diagnostics::kind::note);
     186       124842 :   va_end (ap);
     187       124842 : }
     188              : 
     189              : /* Same as "inform" above, but at RICHLOC.  */
     190              : void
     191         4702 : inform (rich_location *richloc, const char *gmsgid, ...)
     192              : {
     193         4702 :   gcc_assert (richloc);
     194              : 
     195         4702 :   auto logger = global_dc->get_logger ();
     196         9404 :   log_function_params (logger, __func__)
     197         4702 :     .log_param_rich_location ("richloc", richloc)
     198         4702 :     .log_param_string ("gmsgid", gmsgid);
     199         4702 :   auto_inc_log_depth depth_sentinel (logger);
     200              : 
     201         4702 :   auto_diagnostic_group d;
     202         4702 :   va_list ap;
     203         4702 :   va_start (ap, gmsgid);
     204         4702 :   global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
     205              :                               diagnostics::kind::note);
     206         4702 :   va_end (ap);
     207         4702 : }
     208              : 
     209              : /* An informative note at LOCATION.  Use this for additional details on an
     210              :    error message.  */
     211              : void
     212         8347 : inform_n (location_t location, unsigned HOST_WIDE_INT n,
     213              :           const char *singular_gmsgid, const char *plural_gmsgid, ...)
     214              : {
     215         8347 :   auto logger = global_dc->get_logger ();
     216        16694 :   log_function_params (logger, __func__)
     217         8347 :     .log_param_location_t ("location", location)
     218         8347 :     .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
     219         8347 :   auto_inc_log_depth depth_sentinel (logger);
     220              : 
     221         8347 :   va_list ap;
     222         8347 :   va_start (ap, plural_gmsgid);
     223         8347 :   auto_diagnostic_group d;
     224         8347 :   rich_location richloc (line_table, location);
     225         8347 :   global_dc->diagnostic_n_impl (&richloc, nullptr, -1, n,
     226              :                                 singular_gmsgid, plural_gmsgid,
     227              :                                 &ap, diagnostics::kind::note);
     228         8347 :   va_end (ap);
     229         8347 : }
     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    101343494 : warning (diagnostics::option_id option_id, const char *gmsgid, ...)
     236              : {
     237    101343494 :   auto logger = global_dc->get_logger ();
     238    202686988 :   log_function_params (logger, __func__)
     239    101343494 :     .log_param_option_id ("option_id", option_id)
     240    101343494 :     .log_param_string ("gmsgid", gmsgid);
     241    101343494 :   auto_inc_log_depth depth_sentinel (logger);
     242              : 
     243    101343494 :   auto_diagnostic_group d;
     244    101343494 :   va_list ap;
     245    101343494 :   va_start (ap, gmsgid);
     246    101343494 :   rich_location richloc (line_table, input_location);
     247    101343494 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     248              :                                          gmsgid, &ap,
     249              :                                          diagnostics::kind::warning);
     250    101343493 :   va_end (ap);
     251              : 
     252    101343493 :   if (logger)
     253            0 :     logger->log_bool_return ("warning", ret);
     254              : 
     255    202686986 :   return ret;
     256    101343493 : }
     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      5374390 : warning_at (location_t location,
     264              :             diagnostics::option_id option_id,
     265              :             const char *gmsgid, ...)
     266              : {
     267      5374390 :   auto logger = global_dc->get_logger ();
     268     10748780 :   log_function_params (logger, __func__)
     269      5374390 :     .log_param_location_t ("location", location)
     270      5374390 :     .log_param_option_id ("option_id", option_id)
     271      5374390 :     .log_param_string ("gmsgid", gmsgid);
     272      5374390 :   auto_inc_log_depth depth_sentinel (logger);
     273              : 
     274      5374390 :   auto_diagnostic_group d;
     275      5374390 :   va_list ap;
     276      5374390 :   va_start (ap, gmsgid);
     277      5374390 :   rich_location richloc (line_table, location);
     278      5374390 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     279              :                                          gmsgid, &ap,
     280              :                                          diagnostics::kind::warning);
     281      5374384 :   va_end (ap);
     282              : 
     283      5374384 :   if (logger)
     284            0 :     logger->log_bool_return ("warning_at", ret);
     285              : 
     286     10748768 :   return ret;
     287      5374384 : }
     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         2103 : 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         2103 :   gcc_assert (richloc);
     359              : 
     360         2103 :   auto logger = global_dc->get_logger ();
     361         4206 :   log_function_params (logger, __func__)
     362         2103 :     .log_param_rich_location ("richloc", richloc)
     363         2103 :     .log_param_option_id ("option_id", option_id)
     364         2103 :     .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
     365         2103 :   auto_inc_log_depth depth_sentinel (logger);
     366              : 
     367         2103 :   auto_diagnostic_group d;
     368         2103 :   va_list ap;
     369         2103 :   va_start (ap, plural_gmsgid);
     370         2103 :   bool ret = global_dc->diagnostic_n_impl (richloc, nullptr, option_id, n,
     371              :                                            singular_gmsgid, plural_gmsgid,
     372              :                                            &ap, diagnostics::kind::warning);
     373         2103 :   va_end (ap);
     374              : 
     375         2103 :   if (logger)
     376            0 :     logger->log_bool_return ("warning_n", ret);
     377              : 
     378         4206 :   return ret;
     379         2103 : }
     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         2689 : 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         2689 :   auto logger = global_dc->get_logger ();
     392         5378 :   log_function_params (logger, __func__)
     393         2689 :     .log_param_location_t ("location", location)
     394         2689 :     .log_param_option_id ("option_id", option_id)
     395         2689 :     .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
     396         2689 :   auto_inc_log_depth depth_sentinel (logger);
     397              : 
     398         2689 :   auto_diagnostic_group d;
     399         2689 :   va_list ap;
     400         2689 :   va_start (ap, plural_gmsgid);
     401         2689 :   rich_location richloc (line_table, location);
     402         2689 :   bool ret = global_dc->diagnostic_n_impl (&richloc, nullptr, option_id, n,
     403              :                                            singular_gmsgid, plural_gmsgid,
     404              :                                            &ap, diagnostics::kind::warning);
     405         2689 :   va_end (ap);
     406              : 
     407         2689 :   if (logger)
     408            0 :     logger->log_bool_return ("warning_n", ret);
     409              : 
     410         5378 :   return ret;
     411         2689 : }
     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       671787 : pedwarn (location_t location,
     428              :          diagnostics::option_id option_id,
     429              :          const char *gmsgid, ...)
     430              : {
     431       671787 :   auto logger = global_dc->get_logger ();
     432      1343574 :   log_function_params (logger, __func__)
     433       671787 :     .log_param_location_t ("location", location)
     434       671787 :     .log_param_option_id ("option_id", option_id)
     435       671787 :     .log_param_string ("gmsgid", gmsgid);
     436       671787 :   auto_inc_log_depth depth_sentinel (logger);
     437              : 
     438       671787 :   auto_diagnostic_group d;
     439       671787 :   va_list ap;
     440       671787 :   va_start (ap, gmsgid);
     441       671787 :   rich_location richloc (line_table, location);
     442       671787 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     443              :                                          gmsgid, &ap,
     444              :                                          diagnostics::kind::pedwarn);
     445       671787 :   va_end (ap);
     446              : 
     447       671787 :   if (logger)
     448            0 :     logger->log_bool_return ("pedwarn", ret);
     449              : 
     450      1343574 :   return ret;
     451       671787 : }
     452              : 
     453              : /* Same as pedwarn above, but using RICHLOC.  */
     454              : 
     455              : bool
     456          224 : pedwarn (rich_location *richloc,
     457              :          diagnostics::option_id option_id,
     458              :          const char *gmsgid, ...)
     459              : {
     460          224 :   gcc_assert (richloc);
     461              : 
     462          224 :   auto logger = global_dc->get_logger ();
     463          448 :   log_function_params (logger, __func__)
     464          224 :     .log_param_rich_location ("richloc", richloc)
     465          224 :     .log_param_option_id ("option_id", option_id)
     466          224 :     .log_param_string ("gmsgid", gmsgid);
     467          224 :   auto_inc_log_depth depth_sentinel (logger);
     468              : 
     469          224 :   auto_diagnostic_group d;
     470          224 :   va_list ap;
     471          224 :   va_start (ap, gmsgid);
     472          224 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
     473              :                                          gmsgid, &ap,
     474              :                                          diagnostics::kind::pedwarn);
     475          224 :   va_end (ap);
     476              : 
     477          224 :   if (logger)
     478            0 :     logger->log_bool_return ("pedwarn", ret);
     479              : 
     480          448 :   return ret;
     481          224 : }
     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         2386 : permerror (location_t location, const char *gmsgid, ...)
     492              : {
     493         2386 :   auto logger = global_dc->get_logger ();
     494         4772 :   log_function_params (logger, __func__)
     495         2386 :     .log_param_location_t ("location", location)
     496         2386 :     .log_param_string ("gmsgid", gmsgid);
     497         2386 :   auto_inc_log_depth depth_sentinel (logger);
     498              : 
     499         2386 :   auto_diagnostic_group d;
     500         2386 :   va_list ap;
     501         2386 :   va_start (ap, gmsgid);
     502         2386 :   rich_location richloc (line_table, location);
     503         2386 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     504              :                                          diagnostics::kind::permerror);
     505         2386 :   va_end (ap);
     506              : 
     507         2386 :   if (logger)
     508            0 :     logger->log_bool_return ("permerror", ret);
     509              : 
     510         4772 :   return ret;
     511         2386 : }
     512              : 
     513              : /* Same as "permerror" above, but at RICHLOC.  */
     514              : 
     515              : bool
     516         1480 : permerror (rich_location *richloc, const char *gmsgid, ...)
     517              : {
     518         1480 :   gcc_assert (richloc);
     519              : 
     520         1480 :   auto logger = global_dc->get_logger ();
     521         2960 :   log_function_params (logger, __func__)
     522         1480 :     .log_param_rich_location ("richloc", richloc)
     523         1480 :     .log_param_string ("gmsgid", gmsgid);
     524         1480 :   auto_inc_log_depth depth_sentinel (logger);
     525              : 
     526         1480 :   auto_diagnostic_group d;
     527         1480 :   va_list ap;
     528         1480 :   va_start (ap, gmsgid);
     529         1480 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
     530              :                                          diagnostics::kind::permerror);
     531         1480 :   va_end (ap);
     532              : 
     533         1480 :   if (logger)
     534            0 :     logger->log_bool_return ("permerror", ret);
     535              : 
     536         2960 :   return ret;
     537         1480 : }
     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        43330 : permerror_opt (location_t location,
     545              :                diagnostics::option_id option_id,
     546              :                const char *gmsgid, ...)
     547              : {
     548        43330 :   auto logger = global_dc->get_logger ();
     549        86660 :   log_function_params (logger, __func__)
     550        43330 :     .log_param_location_t ("location", location)
     551        43330 :     .log_param_option_id ("option_id", option_id)
     552        43330 :     .log_param_string ("gmsgid", gmsgid);
     553        43330 :   auto_inc_log_depth depth_sentinel (logger);
     554              : 
     555        43330 :   auto_diagnostic_group d;
     556        43330 :   va_list ap;
     557        43330 :   va_start (ap, gmsgid);
     558        43330 :   rich_location richloc (line_table, location);
     559        43330 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     560              :                                          gmsgid, &ap,
     561              :                                          diagnostics::kind::permerror);
     562        43330 :   va_end (ap);
     563              : 
     564        43330 :   if (logger)
     565            0 :     logger->log_bool_return ("permerror_opt", ret);
     566              : 
     567        86660 :   return ret;
     568        43330 : }
     569              : 
     570              : /* Same as "permerror" above, but at RICHLOC.  */
     571              : 
     572              : bool
     573         1558 : permerror_opt (rich_location *richloc,
     574              :                diagnostics::option_id option_id,
     575              :                const char *gmsgid, ...)
     576              : {
     577         1558 :   gcc_assert (richloc);
     578              : 
     579         1558 :   auto logger = global_dc->get_logger ();
     580         3116 :   log_function_params (logger, __func__)
     581         1558 :     .log_param_rich_location ("richloc", richloc)
     582         1558 :     .log_param_option_id ("option_id", option_id)
     583         1558 :     .log_param_string ("gmsgid", gmsgid);
     584         1558 :   auto_inc_log_depth depth_sentinel (logger);
     585              : 
     586         1558 :   auto_diagnostic_group d;
     587         1558 :   va_list ap;
     588         1558 :   va_start (ap, gmsgid);
     589         1558 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
     590              :                                          gmsgid, &ap,
     591              :                                          diagnostics::kind::permerror);
     592         1558 :   va_end (ap);
     593              : 
     594         1558 :   if (logger)
     595            0 :     logger->log_bool_return ("permerror_opt", ret);
     596              : 
     597         3116 :   return ret;
     598         1558 : }
     599              : 
     600              : /* A hard error: the code is definitely ill-formed, and an object file
     601              :    will not be produced.  */
     602              : void
     603        23342 : error (const char *gmsgid, ...)
     604              : {
     605        23342 :   auto logger = global_dc->get_logger ();
     606        46684 :   log_function_params (logger, __func__)
     607        23342 :     .log_param_string ("gmsgid", gmsgid);
     608        23342 :   auto_inc_log_depth depth_sentinel (logger);
     609              : 
     610        23342 :   auto_diagnostic_group d;
     611        23342 :   va_list ap;
     612        23342 :   va_start (ap, gmsgid);
     613        23342 :   rich_location richloc (line_table, input_location);
     614        23342 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     615              :                               diagnostics::kind::error);
     616        23342 :   va_end (ap);
     617        23342 : }
     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        79213 : error_at (location_t loc, const char *gmsgid, ...)
     644              : {
     645        79213 :   auto logger = global_dc->get_logger ();
     646       158426 :   log_function_params (logger, __func__)
     647        79213 :     .log_param_location_t ("loc", loc)
     648        79213 :     .log_param_string ("gmsgid", gmsgid);
     649        79213 :   auto_inc_log_depth depth_sentinel (logger);
     650              : 
     651        79213 :   auto_diagnostic_group d;
     652        79213 :   va_list ap;
     653        79213 :   va_start (ap, gmsgid);
     654        79213 :   rich_location richloc (line_table, loc);
     655        79213 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     656              :                               diagnostics::kind::error);
     657        79213 :   va_end (ap);
     658        79213 : }
     659              : 
     660              : /* Same as above, but use RICH_LOC.  */
     661              : 
     662              : void
     663        14049 : error_at (rich_location *richloc, const char *gmsgid, ...)
     664              : {
     665        14049 :   gcc_assert (richloc);
     666              : 
     667        14049 :   auto logger = global_dc->get_logger ();
     668        28098 :   log_function_params (logger, __func__)
     669        14049 :     .log_param_rich_location ("richloc", richloc)
     670        14049 :     .log_param_string ("gmsgid", gmsgid);
     671        14049 :   auto_inc_log_depth depth_sentinel (logger);
     672              : 
     673        14049 :   auto_diagnostic_group d;
     674        14049 :   va_list ap;
     675        14049 :   va_start (ap, gmsgid);
     676        14049 :   global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
     677              :                               diagnostics::kind::error);
     678        14049 :   va_end (ap);
     679        14049 : }
     680              : 
     681              : /* Same as above, but with metadata.  */
     682              : 
     683              : void
     684          670 : error_meta (rich_location *richloc, const diagnostics::metadata &metadata,
     685              :             const char *gmsgid, ...)
     686              : {
     687          670 :   gcc_assert (richloc);
     688              : 
     689          670 :   auto logger = global_dc->get_logger ();
     690         1340 :   log_function_params (logger, __func__)
     691          670 :     .log_param_rich_location ("richloc", richloc)
     692          670 :     .log_param_string ("gmsgid", gmsgid);
     693          670 :   auto_inc_log_depth depth_sentinel (logger);
     694              : 
     695          670 :   auto_diagnostic_group d;
     696          670 :   va_list ap;
     697          670 :   va_start (ap, gmsgid);
     698          670 :   global_dc->diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap,
     699              :                               diagnostics::kind::error);
     700          670 :   va_end (ap);
     701          670 : }
     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          106 : sorry (const char *gmsgid, ...)
     708              : {
     709          106 :   auto logger = global_dc->get_logger ();
     710          212 :   log_function_params (logger, __func__)
     711          106 :     .log_param_string ("gmsgid", gmsgid);
     712          106 :   auto_inc_log_depth depth_sentinel (logger);
     713              : 
     714          106 :   auto_diagnostic_group d;
     715          106 :   va_list ap;
     716          106 :   va_start (ap, gmsgid);
     717          106 :   rich_location richloc (line_table, input_location);
     718          106 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     719              :                               diagnostics::kind::sorry);
     720          106 :   va_end (ap);
     721          106 : }
     722              : 
     723              : /* Same as above, but use location LOC instead of input_location.  */
     724              : void
     725          539 : sorry_at (location_t loc, const char *gmsgid, ...)
     726              : {
     727          539 :   auto logger = global_dc->get_logger ();
     728         1078 :   log_function_params (logger, __func__)
     729          539 :     .log_param_location_t ("loc", loc)
     730          539 :     .log_param_string ("gmsgid", gmsgid);
     731          539 :   auto_inc_log_depth depth_sentinel (logger);
     732              : 
     733          539 :   auto_diagnostic_group d;
     734          539 :   va_list ap;
     735          539 :   va_start (ap, gmsgid);
     736          539 :   rich_location richloc (line_table, loc);
     737          539 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     738              :                               diagnostics::kind::sorry);
     739          535 :   va_end (ap);
     740          535 : }
     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   1430434810 : seen_error (void)
     746              : {
     747   1430434810 :   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          313 : fatal_error (location_t loc, const char *gmsgid, ...)
     755              : {
     756          313 :   auto logger = global_dc->get_logger ();
     757          626 :   log_function_params (logger, __func__)
     758          313 :     .log_param_location_t ("loc", loc)
     759          313 :     .log_param_string ("gmsgid", gmsgid);
     760          313 :   auto_inc_log_depth depth_sentinel (logger);
     761              : 
     762          313 :   auto_diagnostic_group d;
     763          313 :   va_list ap;
     764          313 :   va_start (ap, gmsgid);
     765          313 :   rich_location richloc (line_table, loc);
     766          313 :   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           45 : internal_error (const char *gmsgid, ...)
     777              : {
     778           45 :   auto logger = global_dc->get_logger ();
     779           90 :   log_function_params (logger, __func__)
     780           45 :     .log_param_string ("gmsgid", gmsgid);
     781           45 :   auto_inc_log_depth depth_sentinel (logger);
     782              : 
     783           45 :   auto_diagnostic_group d;
     784           45 :   va_list ap;
     785           45 :   va_start (ap, gmsgid);
     786           45 :   rich_location richloc (line_table, input_location);
     787           45 :   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        24296 : 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        24296 :   if (file == stderr && global_dc)
     830        20988 :     if (!global_dc->supports_fnotice_on_stderr_p ())
     831            0 :       return;
     832              : 
     833        24296 :   va_list ap;
     834              : 
     835        24296 :   va_start (ap, cmsgid);
     836        24296 :   vfprintf (file, _(cmsgid), ap);
     837        24296 :   va_end (ap);
     838              : }
     839              : 
     840              : /* class auto_diagnostic_group.  */
     841              : 
     842              : /* Constructor: "push" this group into global_dc.  */
     843              : 
     844   1018203164 : auto_diagnostic_group::auto_diagnostic_group ()
     845              : {
     846   1018203164 :   global_dc->begin_group ();
     847   1018203164 : }
     848              : 
     849              : /* Destructor: "pop" this group from global_dc.  */
     850              : 
     851   1018202749 : auto_diagnostic_group::~auto_diagnostic_group ()
     852              : {
     853   1018202749 :   global_dc->end_group ();
     854   1018202749 : }
     855              : 
     856              : /* class auto_diagnostic_nesting_level.  */
     857              : 
     858        30919 : auto_diagnostic_nesting_level::auto_diagnostic_nesting_level ()
     859              : {
     860        30919 :   global_dc->push_nesting_level ();
     861        30919 : }
     862              : 
     863        30919 : auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level ()
     864              : {
     865        30919 :   global_dc->pop_nesting_level ();
     866        30919 : }
        

Generated by: LCOV version 2.5.0-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.