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-03-28 14:25:54 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        49639 : emit_diagnostic (enum diagnostics::kind kind,
      66              :                  location_t location,
      67              :                  diagnostics::option_id option_id,
      68              :                  const char *gmsgid, ...)
      69              : {
      70        49639 :   auto logger = global_dc->get_logger ();
      71        99278 :   log_function_params (logger, __func__)
      72        49639 :     .log_param_location_t ("location", location)
      73        49639 :     .log_param_option_id ("option_id", option_id)
      74        49639 :     .log_param_string ("gmsgid", gmsgid);
      75        49639 :   auto_inc_log_depth depth_sentinel (logger);
      76              : 
      77        49639 :   auto_diagnostic_group d;
      78        49639 :   va_list ap;
      79        49639 :   va_start (ap, gmsgid);
      80        49639 :   rich_location richloc (line_table, location);
      81        49639 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
      82              :                                          gmsgid, &ap, kind);
      83        49638 :   va_end (ap);
      84              : 
      85        49638 :   if (logger)
      86            0 :     logger->log_bool_return ("emit_diagnostic", ret);
      87              : 
      88        99276 :   return ret;
      89        49638 : }
      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         3929 : 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         3929 :   auto logger = global_dc->get_logger ();
     154         7858 :   log_function_params (logger, __func__)
     155         3929 :     .log_param_rich_location ("richloc", richloc)
     156         3929 :     .log_param_option_id ("option_id", option_id)
     157         3929 :     .log_param_string ("gmsgid", gmsgid);
     158         3929 :   auto_inc_log_depth depth_sentinel (logger);
     159              : 
     160         3929 :   bool ret = global_dc->diagnostic_impl (richloc, metadata, option_id,
     161              :                                          gmsgid, ap, kind);
     162              : 
     163         3929 :   if (logger)
     164            0 :     logger->log_bool_return ("emit_diagnostic_valist_meta", ret);
     165              : 
     166         3929 :   return ret;
     167         3929 : }
     168              : 
     169              : /* An informative note at LOCATION.  Use this for additional details on an error
     170              :    message.  */
     171              : void
     172        97876 : inform (location_t location, const char *gmsgid, ...)
     173              : {
     174        97876 :   auto logger = global_dc->get_logger ();
     175       195752 :   log_function_params (logger, __func__)
     176        97876 :     .log_param_location_t ("location", location)
     177        97876 :     .log_param_string ("gmsgid", gmsgid);
     178        97876 :   auto_inc_log_depth depth_sentinel (logger);
     179              : 
     180        97876 :   auto_diagnostic_group d;
     181        97876 :   va_list ap;
     182        97876 :   va_start (ap, gmsgid);
     183        97876 :   rich_location richloc (line_table, location);
     184        97876 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     185              :                               diagnostics::kind::note);
     186        97876 :   va_end (ap);
     187        97876 : }
     188              : 
     189              : /* Same as "inform" above, but at RICHLOC.  */
     190              : void
     191         4361 : inform (rich_location *richloc, const char *gmsgid, ...)
     192              : {
     193         4361 :   gcc_assert (richloc);
     194              : 
     195         4361 :   auto logger = global_dc->get_logger ();
     196         8722 :   log_function_params (logger, __func__)
     197         4361 :     .log_param_rich_location ("richloc", richloc)
     198         4361 :     .log_param_string ("gmsgid", gmsgid);
     199         4361 :   auto_inc_log_depth depth_sentinel (logger);
     200              : 
     201         4361 :   auto_diagnostic_group d;
     202         4361 :   va_list ap;
     203         4361 :   va_start (ap, gmsgid);
     204         4361 :   global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
     205              :                               diagnostics::kind::note);
     206         4361 :   va_end (ap);
     207         4361 : }
     208              : 
     209              : /* An informative note at LOCATION.  Use this for additional details on an
     210              :    error message.  */
     211              : void
     212         8131 : inform_n (location_t location, unsigned HOST_WIDE_INT n,
     213              :           const char *singular_gmsgid, const char *plural_gmsgid, ...)
     214              : {
     215         8131 :   auto logger = global_dc->get_logger ();
     216        16262 :   log_function_params (logger, __func__)
     217         8131 :     .log_param_location_t ("location", location)
     218         8131 :     .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
     219         8131 :   auto_inc_log_depth depth_sentinel (logger);
     220              : 
     221         8131 :   va_list ap;
     222         8131 :   va_start (ap, plural_gmsgid);
     223         8131 :   auto_diagnostic_group d;
     224         8131 :   rich_location richloc (line_table, location);
     225         8131 :   global_dc->diagnostic_n_impl (&richloc, nullptr, -1, n,
     226              :                                 singular_gmsgid, plural_gmsgid,
     227              :                                 &ap, diagnostics::kind::note);
     228         8131 :   va_end (ap);
     229         8131 : }
     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     94859848 : warning (diagnostics::option_id option_id, const char *gmsgid, ...)
     236              : {
     237     94859848 :   auto logger = global_dc->get_logger ();
     238    189719696 :   log_function_params (logger, __func__)
     239     94859848 :     .log_param_option_id ("option_id", option_id)
     240     94859848 :     .log_param_string ("gmsgid", gmsgid);
     241     94859848 :   auto_inc_log_depth depth_sentinel (logger);
     242              : 
     243     94859848 :   auto_diagnostic_group d;
     244     94859848 :   va_list ap;
     245     94859848 :   va_start (ap, gmsgid);
     246     94859848 :   rich_location richloc (line_table, input_location);
     247     94859848 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     248              :                                          gmsgid, &ap,
     249              :                                          diagnostics::kind::warning);
     250     94859847 :   va_end (ap);
     251              : 
     252     94859847 :   if (logger)
     253            0 :     logger->log_bool_return ("warning", ret);
     254              : 
     255    189719694 :   return ret;
     256     94859847 : }
     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      5355954 : warning_at (location_t location,
     264              :             diagnostics::option_id option_id,
     265              :             const char *gmsgid, ...)
     266              : {
     267      5355954 :   auto logger = global_dc->get_logger ();
     268     10711908 :   log_function_params (logger, __func__)
     269      5355954 :     .log_param_location_t ("location", location)
     270      5355954 :     .log_param_option_id ("option_id", option_id)
     271      5355954 :     .log_param_string ("gmsgid", gmsgid);
     272      5355954 :   auto_inc_log_depth depth_sentinel (logger);
     273              : 
     274      5355954 :   auto_diagnostic_group d;
     275      5355954 :   va_list ap;
     276      5355954 :   va_start (ap, gmsgid);
     277      5355954 :   rich_location richloc (line_table, location);
     278      5355954 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     279              :                                          gmsgid, &ap,
     280              :                                          diagnostics::kind::warning);
     281      5355948 :   va_end (ap);
     282              : 
     283      5355948 :   if (logger)
     284            0 :     logger->log_bool_return ("warning_at", ret);
     285              : 
     286     10711896 :   return ret;
     287      5355948 : }
     288              : 
     289              : /* Same as "warning at" above, but using RICHLOC.  */
     290              : 
     291              : bool
     292        10076 : warning_at (rich_location *richloc,
     293              :             diagnostics::option_id option_id,
     294              :             const char *gmsgid, ...)
     295              : {
     296        10076 :   gcc_assert (richloc);
     297              : 
     298        10076 :   auto logger = global_dc->get_logger ();
     299        20152 :   log_function_params (logger, __func__)
     300        10076 :     .log_param_rich_location ("richloc", richloc)
     301        10076 :     .log_param_option_id ("option_id", option_id)
     302        10076 :     .log_param_string ("gmsgid", gmsgid);
     303        10076 :   auto_inc_log_depth depth_sentinel (logger);
     304              : 
     305        10076 :   auto_diagnostic_group d;
     306        10076 :   va_list ap;
     307        10076 :   va_start (ap, gmsgid);
     308        10076 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
     309              :                                          gmsgid, &ap,
     310              :                                          diagnostics::kind::warning);
     311        10076 :   va_end (ap);
     312              : 
     313        10076 :   if (logger)
     314            0 :     logger->log_bool_return ("warning_at", ret);
     315              : 
     316        20152 :   return ret;
     317        10076 : }
     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       643598 : pedwarn (location_t location,
     428              :          diagnostics::option_id option_id,
     429              :          const char *gmsgid, ...)
     430              : {
     431       643598 :   auto logger = global_dc->get_logger ();
     432      1287196 :   log_function_params (logger, __func__)
     433       643598 :     .log_param_location_t ("location", location)
     434       643598 :     .log_param_option_id ("option_id", option_id)
     435       643598 :     .log_param_string ("gmsgid", gmsgid);
     436       643598 :   auto_inc_log_depth depth_sentinel (logger);
     437              : 
     438       643598 :   auto_diagnostic_group d;
     439       643598 :   va_list ap;
     440       643598 :   va_start (ap, gmsgid);
     441       643598 :   rich_location richloc (line_table, location);
     442       643598 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     443              :                                          gmsgid, &ap,
     444              :                                          diagnostics::kind::pedwarn);
     445       643598 :   va_end (ap);
     446              : 
     447       643598 :   if (logger)
     448            0 :     logger->log_bool_return ("pedwarn", ret);
     449              : 
     450      1287196 :   return ret;
     451       643598 : }
     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         1429 : permerror (rich_location *richloc, const char *gmsgid, ...)
     517              : {
     518         1429 :   gcc_assert (richloc);
     519              : 
     520         1429 :   auto logger = global_dc->get_logger ();
     521         2858 :   log_function_params (logger, __func__)
     522         1429 :     .log_param_rich_location ("richloc", richloc)
     523         1429 :     .log_param_string ("gmsgid", gmsgid);
     524         1429 :   auto_inc_log_depth depth_sentinel (logger);
     525              : 
     526         1429 :   auto_diagnostic_group d;
     527         1429 :   va_list ap;
     528         1429 :   va_start (ap, gmsgid);
     529         1429 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
     530              :                                          diagnostics::kind::permerror);
     531         1429 :   va_end (ap);
     532              : 
     533         1429 :   if (logger)
     534            0 :     logger->log_bool_return ("permerror", ret);
     535              : 
     536         2858 :   return ret;
     537         1429 : }
     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        12236 : permerror_opt (location_t location,
     545              :                diagnostics::option_id option_id,
     546              :                const char *gmsgid, ...)
     547              : {
     548        12236 :   auto logger = global_dc->get_logger ();
     549        24472 :   log_function_params (logger, __func__)
     550        12236 :     .log_param_location_t ("location", location)
     551        12236 :     .log_param_option_id ("option_id", option_id)
     552        12236 :     .log_param_string ("gmsgid", gmsgid);
     553        12236 :   auto_inc_log_depth depth_sentinel (logger);
     554              : 
     555        12236 :   auto_diagnostic_group d;
     556        12236 :   va_list ap;
     557        12236 :   va_start (ap, gmsgid);
     558        12236 :   rich_location richloc (line_table, location);
     559        12236 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     560              :                                          gmsgid, &ap,
     561              :                                          diagnostics::kind::permerror);
     562        12236 :   va_end (ap);
     563              : 
     564        12236 :   if (logger)
     565            0 :     logger->log_bool_return ("permerror_opt", ret);
     566              : 
     567        24472 :   return ret;
     568        12236 : }
     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        21976 : error (const char *gmsgid, ...)
     604              : {
     605        21976 :   auto logger = global_dc->get_logger ();
     606        43952 :   log_function_params (logger, __func__)
     607        21976 :     .log_param_string ("gmsgid", gmsgid);
     608        21976 :   auto_inc_log_depth depth_sentinel (logger);
     609              : 
     610        21976 :   auto_diagnostic_group d;
     611        21976 :   va_list ap;
     612        21976 :   va_start (ap, gmsgid);
     613        21976 :   rich_location richloc (line_table, input_location);
     614        21976 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     615              :                               diagnostics::kind::error);
     616        21976 :   va_end (ap);
     617        21976 : }
     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        74199 : error_at (location_t loc, const char *gmsgid, ...)
     644              : {
     645        74199 :   auto logger = global_dc->get_logger ();
     646       148398 :   log_function_params (logger, __func__)
     647        74199 :     .log_param_location_t ("loc", loc)
     648        74199 :     .log_param_string ("gmsgid", gmsgid);
     649        74199 :   auto_inc_log_depth depth_sentinel (logger);
     650              : 
     651        74199 :   auto_diagnostic_group d;
     652        74199 :   va_list ap;
     653        74199 :   va_start (ap, gmsgid);
     654        74199 :   rich_location richloc (line_table, loc);
     655        74199 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     656              :                               diagnostics::kind::error);
     657        74199 :   va_end (ap);
     658        74199 : }
     659              : 
     660              : /* Same as above, but use RICH_LOC.  */
     661              : 
     662              : void
     663        13293 : error_at (rich_location *richloc, const char *gmsgid, ...)
     664              : {
     665        13293 :   gcc_assert (richloc);
     666              : 
     667        13293 :   auto logger = global_dc->get_logger ();
     668        26586 :   log_function_params (logger, __func__)
     669        13293 :     .log_param_rich_location ("richloc", richloc)
     670        13293 :     .log_param_string ("gmsgid", gmsgid);
     671        13293 :   auto_inc_log_depth depth_sentinel (logger);
     672              : 
     673        13293 :   auto_diagnostic_group d;
     674        13293 :   va_list ap;
     675        13293 :   va_start (ap, gmsgid);
     676        13293 :   global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
     677              :                               diagnostics::kind::error);
     678        13293 :   va_end (ap);
     679        13293 : }
     680              : 
     681              : /* Same as above, but with metadata.  */
     682              : 
     683              : void
     684          453 : error_meta (rich_location *richloc, const diagnostics::metadata &metadata,
     685              :             const char *gmsgid, ...)
     686              : {
     687          453 :   gcc_assert (richloc);
     688              : 
     689          453 :   auto logger = global_dc->get_logger ();
     690          906 :   log_function_params (logger, __func__)
     691          453 :     .log_param_rich_location ("richloc", richloc)
     692          453 :     .log_param_string ("gmsgid", gmsgid);
     693          453 :   auto_inc_log_depth depth_sentinel (logger);
     694              : 
     695          453 :   auto_diagnostic_group d;
     696          453 :   va_list ap;
     697          453 :   va_start (ap, gmsgid);
     698          453 :   global_dc->diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap,
     699              :                               diagnostics::kind::error);
     700          453 :   va_end (ap);
     701          453 : }
     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          592 : sorry_at (location_t loc, const char *gmsgid, ...)
     726              : {
     727          592 :   auto logger = global_dc->get_logger ();
     728         1184 :   log_function_params (logger, __func__)
     729          592 :     .log_param_location_t ("loc", loc)
     730          592 :     .log_param_string ("gmsgid", gmsgid);
     731          592 :   auto_inc_log_depth depth_sentinel (logger);
     732              : 
     733          592 :   auto_diagnostic_group d;
     734          592 :   va_list ap;
     735          592 :   va_start (ap, gmsgid);
     736          592 :   rich_location richloc (line_table, loc);
     737          592 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     738              :                               diagnostics::kind::sorry);
     739          588 :   va_end (ap);
     740          588 : }
     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   1375379614 : seen_error (void)
     746              : {
     747   1375379614 :   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        23470 : 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        23470 :   if (file == stderr && global_dc)
     830        20386 :     if (!global_dc->supports_fnotice_on_stderr_p ())
     831            0 :       return;
     832              : 
     833        23470 :   va_list ap;
     834              : 
     835        23470 :   va_start (ap, cmsgid);
     836        23470 :   vfprintf (file, _(cmsgid), ap);
     837        23470 :   va_end (ap);
     838              : }
     839              : 
     840              : /* class auto_diagnostic_group.  */
     841              : 
     842              : /* Constructor: "push" this group into global_dc.  */
     843              : 
     844    896147711 : auto_diagnostic_group::auto_diagnostic_group ()
     845              : {
     846    896147711 :   global_dc->begin_group ();
     847    896147711 : }
     848              : 
     849              : /* Destructor: "pop" this group from global_dc.  */
     850              : 
     851    896147324 : auto_diagnostic_group::~auto_diagnostic_group ()
     852              : {
     853    896147324 :   global_dc->end_group ();
     854    896147324 : }
     855              : 
     856              : /* class auto_diagnostic_nesting_level.  */
     857              : 
     858        29829 : auto_diagnostic_nesting_level::auto_diagnostic_nesting_level ()
     859              : {
     860        29829 :   global_dc->push_nesting_level ();
     861        29829 : }
     862              : 
     863        29829 : auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level ()
     864              : {
     865        29829 :   global_dc->pop_nesting_level ();
     866        29829 : }
        

Generated by: LCOV version 2.4-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.