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: 2025-10-18 14:39:06 Functions: 94.4 % 36 34
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Language-independent diagnostic subroutines that implicitly use global_dc.
       2                 :             :    Copyright (C) 1999-2025 Free Software Foundation, Inc.
       3                 :             :    Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify it under
       8                 :             : the terms of the GNU General Public License as published by the Free
       9                 :             : Software Foundation; either version 3, or (at your option) any later
      10                 :             : version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :             : for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : 
      22                 :             : /* This file implements the parts of the language independent aspect
      23                 :             :    of diagnostic messages that implicitly use global_dc.  */
      24                 :             : 
      25                 :             : #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                 :       49545 : emit_diagnostic (enum diagnostics::kind kind,
      66                 :             :                  location_t location,
      67                 :             :                  diagnostics::option_id option_id,
      68                 :             :                  const char *gmsgid, ...)
      69                 :             : {
      70                 :       49545 :   auto logger = global_dc->get_logger ();
      71                 :       99090 :   log_function_params (logger, __func__)
      72                 :       49545 :     .log_param_location_t ("location", location)
      73                 :       49545 :     .log_param_option_id ("option_id", option_id)
      74                 :       49545 :     .log_param_string ("gmsgid", gmsgid);
      75                 :       49545 :   auto_inc_log_depth depth_sentinel (logger);
      76                 :             : 
      77                 :       49545 :   auto_diagnostic_group d;
      78                 :       49545 :   va_list ap;
      79                 :       49545 :   va_start (ap, gmsgid);
      80                 :       49545 :   rich_location richloc (line_table, location);
      81                 :       49545 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
      82                 :             :                                          gmsgid, &ap, kind);
      83                 :       49544 :   va_end (ap);
      84                 :             : 
      85                 :       49544 :   if (logger)
      86                 :           0 :     logger->log_bool_return ("emit_diagnostic", ret);
      87                 :             : 
      88                 :       99088 :   return ret;
      89                 :       49544 : }
      90                 :             : 
      91                 :             : /* As above, but for rich_location *.  */
      92                 :             : 
      93                 :             : bool
      94                 :          84 : emit_diagnostic (enum diagnostics::kind kind,
      95                 :             :                  rich_location *richloc,
      96                 :             :                  diagnostics::option_id option_id,
      97                 :             :                  const char *gmsgid, ...)
      98                 :             : {
      99                 :          84 :   auto logger = global_dc->get_logger ();
     100                 :         168 :   log_function_params (logger, __func__)
     101                 :          84 :     .log_param_rich_location ("richloc", richloc)
     102                 :          84 :     .log_param_option_id ("option_id", option_id)
     103                 :          84 :     .log_param_string ("gmsgid", gmsgid);
     104                 :          84 :   auto_inc_log_depth depth_sentinel (logger);
     105                 :             : 
     106                 :          84 :   auto_diagnostic_group d;
     107                 :          84 :   va_list ap;
     108                 :          84 :   va_start (ap, gmsgid);
     109                 :          84 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
     110                 :             :                                          gmsgid, &ap, kind);
     111                 :          84 :   va_end (ap);
     112                 :             : 
     113                 :          84 :   if (logger)
     114                 :           0 :     logger->log_bool_return ("emit_diagnostic", ret);
     115                 :             : 
     116                 :         168 :   return ret;
     117                 :          84 : }
     118                 :             : 
     119                 :             : /* As above, but taking a variable argument list.  */
     120                 :             : 
     121                 :             : bool
     122                 :        3480 : 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                 :        3480 :   auto logger = global_dc->get_logger ();
     128                 :        6960 :   log_function_params (logger, __func__)
     129                 :        3480 :     .log_param_location_t ("location", location)
     130                 :        3480 :     .log_param_option_id ("option_id", option_id)
     131                 :        3480 :     .log_param_string ("gmsgid", gmsgid);
     132                 :        3480 :   auto_inc_log_depth depth_sentinel (logger);
     133                 :             : 
     134                 :        3480 :   rich_location richloc (line_table, location);
     135                 :        3480 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     136                 :             :                                          gmsgid, ap, kind);
     137                 :             : 
     138                 :        3480 :   if (logger)
     139                 :           0 :     logger->log_bool_return ("emit_diagnostic_valist", ret);
     140                 :             : 
     141                 :        6960 :   return ret;
     142                 :        3480 : }
     143                 :             : 
     144                 :             : /* As above, but with rich_location and metadata.  */
     145                 :             : 
     146                 :             : bool
     147                 :        3916 : 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                 :        3916 :   auto logger = global_dc->get_logger ();
     154                 :        7832 :   log_function_params (logger, __func__)
     155                 :        3916 :     .log_param_rich_location ("richloc", richloc)
     156                 :        3916 :     .log_param_option_id ("option_id", option_id)
     157                 :        3916 :     .log_param_string ("gmsgid", gmsgid);
     158                 :        3916 :   auto_inc_log_depth depth_sentinel (logger);
     159                 :             : 
     160                 :        3916 :   bool ret = global_dc->diagnostic_impl (richloc, metadata, option_id,
     161                 :             :                                          gmsgid, ap, kind);
     162                 :             : 
     163                 :        3916 :   if (logger)
     164                 :           0 :     logger->log_bool_return ("emit_diagnostic_valist_meta", ret);
     165                 :             : 
     166                 :        3916 :   return ret;
     167                 :        3916 : }
     168                 :             : 
     169                 :             : /* An informative note at LOCATION.  Use this for additional details on an error
     170                 :             :    message.  */
     171                 :             : void
     172                 :       98993 : inform (location_t location, const char *gmsgid, ...)
     173                 :             : {
     174                 :       98993 :   auto logger = global_dc->get_logger ();
     175                 :      197986 :   log_function_params (logger, __func__)
     176                 :       98993 :     .log_param_location_t ("location", location)
     177                 :       98993 :     .log_param_string ("gmsgid", gmsgid);
     178                 :       98993 :   auto_inc_log_depth depth_sentinel (logger);
     179                 :             : 
     180                 :       98993 :   auto_diagnostic_group d;
     181                 :       98993 :   va_list ap;
     182                 :       98993 :   va_start (ap, gmsgid);
     183                 :       98993 :   rich_location richloc (line_table, location);
     184                 :       98993 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     185                 :             :                               diagnostics::kind::note);
     186                 :       98993 :   va_end (ap);
     187                 :       98993 : }
     188                 :             : 
     189                 :             : /* Same as "inform" above, but at RICHLOC.  */
     190                 :             : void
     191                 :        4232 : inform (rich_location *richloc, const char *gmsgid, ...)
     192                 :             : {
     193                 :        4232 :   gcc_assert (richloc);
     194                 :             : 
     195                 :        4232 :   auto logger = global_dc->get_logger ();
     196                 :        8464 :   log_function_params (logger, __func__)
     197                 :        4232 :     .log_param_rich_location ("richloc", richloc)
     198                 :        4232 :     .log_param_string ("gmsgid", gmsgid);
     199                 :        4232 :   auto_inc_log_depth depth_sentinel (logger);
     200                 :             : 
     201                 :        4232 :   auto_diagnostic_group d;
     202                 :        4232 :   va_list ap;
     203                 :        4232 :   va_start (ap, gmsgid);
     204                 :        4232 :   global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
     205                 :             :                               diagnostics::kind::note);
     206                 :        4232 :   va_end (ap);
     207                 :        4232 : }
     208                 :             : 
     209                 :             : /* An informative note at LOCATION.  Use this for additional details on an
     210                 :             :    error message.  */
     211                 :             : void
     212                 :        7359 : inform_n (location_t location, unsigned HOST_WIDE_INT n,
     213                 :             :           const char *singular_gmsgid, const char *plural_gmsgid, ...)
     214                 :             : {
     215                 :        7359 :   auto logger = global_dc->get_logger ();
     216                 :       14718 :   log_function_params (logger, __func__)
     217                 :        7359 :     .log_param_location_t ("location", location)
     218                 :        7359 :     .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
     219                 :        7359 :   auto_inc_log_depth depth_sentinel (logger);
     220                 :             : 
     221                 :        7359 :   va_list ap;
     222                 :        7359 :   va_start (ap, plural_gmsgid);
     223                 :        7359 :   auto_diagnostic_group d;
     224                 :        7359 :   rich_location richloc (line_table, location);
     225                 :        7359 :   global_dc->diagnostic_n_impl (&richloc, nullptr, -1, n,
     226                 :             :                                 singular_gmsgid, plural_gmsgid,
     227                 :             :                                 &ap, diagnostics::kind::note);
     228                 :        7359 :   va_end (ap);
     229                 :        7359 : }
     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                 :    85916584 : warning (diagnostics::option_id option_id, const char *gmsgid, ...)
     236                 :             : {
     237                 :    85916584 :   auto logger = global_dc->get_logger ();
     238                 :   171833168 :   log_function_params (logger, __func__)
     239                 :    85916584 :     .log_param_option_id ("option_id", option_id)
     240                 :    85916584 :     .log_param_string ("gmsgid", gmsgid);
     241                 :    85916584 :   auto_inc_log_depth depth_sentinel (logger);
     242                 :             : 
     243                 :    85916584 :   auto_diagnostic_group d;
     244                 :    85916584 :   va_list ap;
     245                 :    85916584 :   va_start (ap, gmsgid);
     246                 :    85916584 :   rich_location richloc (line_table, input_location);
     247                 :    85916584 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     248                 :             :                                          gmsgid, &ap,
     249                 :             :                                          diagnostics::kind::warning);
     250                 :    85916583 :   va_end (ap);
     251                 :             : 
     252                 :    85916583 :   if (logger)
     253                 :           0 :     logger->log_bool_return ("warning", ret);
     254                 :             : 
     255                 :   171833166 :   return ret;
     256                 :    85916583 : }
     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                 :     4649255 : warning_at (location_t location,
     264                 :             :             diagnostics::option_id option_id,
     265                 :             :             const char *gmsgid, ...)
     266                 :             : {
     267                 :     4649255 :   auto logger = global_dc->get_logger ();
     268                 :     9298510 :   log_function_params (logger, __func__)
     269                 :     4649255 :     .log_param_location_t ("location", location)
     270                 :     4649255 :     .log_param_option_id ("option_id", option_id)
     271                 :     4649255 :     .log_param_string ("gmsgid", gmsgid);
     272                 :     4649255 :   auto_inc_log_depth depth_sentinel (logger);
     273                 :             : 
     274                 :     4649255 :   auto_diagnostic_group d;
     275                 :     4649255 :   va_list ap;
     276                 :     4649255 :   va_start (ap, gmsgid);
     277                 :     4649255 :   rich_location richloc (line_table, location);
     278                 :     4649255 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     279                 :             :                                          gmsgid, &ap,
     280                 :             :                                          diagnostics::kind::warning);
     281                 :     4649249 :   va_end (ap);
     282                 :             : 
     283                 :     4649249 :   if (logger)
     284                 :           0 :     logger->log_bool_return ("warning_at", ret);
     285                 :             : 
     286                 :     9298498 :   return ret;
     287                 :     4649249 : }
     288                 :             : 
     289                 :             : /* Same as "warning at" above, but using RICHLOC.  */
     290                 :             : 
     291                 :             : bool
     292                 :        7610 : warning_at (rich_location *richloc,
     293                 :             :             diagnostics::option_id option_id,
     294                 :             :             const char *gmsgid, ...)
     295                 :             : {
     296                 :        7610 :   gcc_assert (richloc);
     297                 :             : 
     298                 :        7610 :   auto logger = global_dc->get_logger ();
     299                 :       15220 :   log_function_params (logger, __func__)
     300                 :        7610 :     .log_param_rich_location ("richloc", richloc)
     301                 :        7610 :     .log_param_option_id ("option_id", option_id)
     302                 :        7610 :     .log_param_string ("gmsgid", gmsgid);
     303                 :        7610 :   auto_inc_log_depth depth_sentinel (logger);
     304                 :             : 
     305                 :        7610 :   auto_diagnostic_group d;
     306                 :        7610 :   va_list ap;
     307                 :        7610 :   va_start (ap, gmsgid);
     308                 :        7610 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
     309                 :             :                                          gmsgid, &ap,
     310                 :             :                                          diagnostics::kind::warning);
     311                 :        7610 :   va_end (ap);
     312                 :             : 
     313                 :        7610 :   if (logger)
     314                 :           0 :     logger->log_bool_return ("warning_at", ret);
     315                 :             : 
     316                 :       15220 :   return ret;
     317                 :        7610 : }
     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                 :        1800 : 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                 :        1800 :   gcc_assert (richloc);
     359                 :             : 
     360                 :        1800 :   auto logger = global_dc->get_logger ();
     361                 :        3600 :   log_function_params (logger, __func__)
     362                 :        1800 :     .log_param_rich_location ("richloc", richloc)
     363                 :        1800 :     .log_param_option_id ("option_id", option_id)
     364                 :        1800 :     .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
     365                 :        1800 :   auto_inc_log_depth depth_sentinel (logger);
     366                 :             : 
     367                 :        1800 :   auto_diagnostic_group d;
     368                 :        1800 :   va_list ap;
     369                 :        1800 :   va_start (ap, plural_gmsgid);
     370                 :        1800 :   bool ret = global_dc->diagnostic_n_impl (richloc, nullptr, option_id, n,
     371                 :             :                                            singular_gmsgid, plural_gmsgid,
     372                 :             :                                            &ap, diagnostics::kind::warning);
     373                 :        1800 :   va_end (ap);
     374                 :             : 
     375                 :        1800 :   if (logger)
     376                 :           0 :     logger->log_bool_return ("warning_n", ret);
     377                 :             : 
     378                 :        3600 :   return ret;
     379                 :        1800 : }
     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                 :        2673 : 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                 :        2673 :   auto logger = global_dc->get_logger ();
     392                 :        5346 :   log_function_params (logger, __func__)
     393                 :        2673 :     .log_param_location_t ("location", location)
     394                 :        2673 :     .log_param_option_id ("option_id", option_id)
     395                 :        2673 :     .log_params_n_gmsgids (n, singular_gmsgid, plural_gmsgid);
     396                 :        2673 :   auto_inc_log_depth depth_sentinel (logger);
     397                 :             : 
     398                 :        2673 :   auto_diagnostic_group d;
     399                 :        2673 :   va_list ap;
     400                 :        2673 :   va_start (ap, plural_gmsgid);
     401                 :        2673 :   rich_location richloc (line_table, location);
     402                 :        2673 :   bool ret = global_dc->diagnostic_n_impl (&richloc, nullptr, option_id, n,
     403                 :             :                                            singular_gmsgid, plural_gmsgid,
     404                 :             :                                            &ap, diagnostics::kind::warning);
     405                 :        2673 :   va_end (ap);
     406                 :             : 
     407                 :        2673 :   if (logger)
     408                 :           0 :     logger->log_bool_return ("warning_n", ret);
     409                 :             : 
     410                 :        5346 :   return ret;
     411                 :        2673 : }
     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                 :      364150 : pedwarn (location_t location,
     428                 :             :          diagnostics::option_id option_id,
     429                 :             :          const char *gmsgid, ...)
     430                 :             : {
     431                 :      364150 :   auto logger = global_dc->get_logger ();
     432                 :      728300 :   log_function_params (logger, __func__)
     433                 :      364150 :     .log_param_location_t ("location", location)
     434                 :      364150 :     .log_param_option_id ("option_id", option_id)
     435                 :      364150 :     .log_param_string ("gmsgid", gmsgid);
     436                 :      364150 :   auto_inc_log_depth depth_sentinel (logger);
     437                 :             : 
     438                 :      364150 :   auto_diagnostic_group d;
     439                 :      364150 :   va_list ap;
     440                 :      364150 :   va_start (ap, gmsgid);
     441                 :      364150 :   rich_location richloc (line_table, location);
     442                 :      364150 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     443                 :             :                                          gmsgid, &ap,
     444                 :             :                                          diagnostics::kind::pedwarn);
     445                 :      364150 :   va_end (ap);
     446                 :             : 
     447                 :      364150 :   if (logger)
     448                 :           0 :     logger->log_bool_return ("pedwarn", ret);
     449                 :             : 
     450                 :      728300 :   return ret;
     451                 :      364150 : }
     452                 :             : 
     453                 :             : /* Same as pedwarn above, but using RICHLOC.  */
     454                 :             : 
     455                 :             : bool
     456                 :         229 : pedwarn (rich_location *richloc,
     457                 :             :          diagnostics::option_id option_id,
     458                 :             :          const char *gmsgid, ...)
     459                 :             : {
     460                 :         229 :   gcc_assert (richloc);
     461                 :             : 
     462                 :         229 :   auto logger = global_dc->get_logger ();
     463                 :         458 :   log_function_params (logger, __func__)
     464                 :         229 :     .log_param_rich_location ("richloc", richloc)
     465                 :         229 :     .log_param_option_id ("option_id", option_id)
     466                 :         229 :     .log_param_string ("gmsgid", gmsgid);
     467                 :         229 :   auto_inc_log_depth depth_sentinel (logger);
     468                 :             : 
     469                 :         229 :   auto_diagnostic_group d;
     470                 :         229 :   va_list ap;
     471                 :         229 :   va_start (ap, gmsgid);
     472                 :         229 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
     473                 :             :                                          gmsgid, &ap,
     474                 :             :                                          diagnostics::kind::pedwarn);
     475                 :         229 :   va_end (ap);
     476                 :             : 
     477                 :         229 :   if (logger)
     478                 :           0 :     logger->log_bool_return ("pedwarn", ret);
     479                 :             : 
     480                 :         458 :   return ret;
     481                 :         229 : }
     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                 :        2388 : permerror (location_t location, const char *gmsgid, ...)
     492                 :             : {
     493                 :        2388 :   auto logger = global_dc->get_logger ();
     494                 :        4776 :   log_function_params (logger, __func__)
     495                 :        2388 :     .log_param_location_t ("location", location)
     496                 :        2388 :     .log_param_string ("gmsgid", gmsgid);
     497                 :        2388 :   auto_inc_log_depth depth_sentinel (logger);
     498                 :             : 
     499                 :        2388 :   auto_diagnostic_group d;
     500                 :        2388 :   va_list ap;
     501                 :        2388 :   va_start (ap, gmsgid);
     502                 :        2388 :   rich_location richloc (line_table, location);
     503                 :        2388 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     504                 :             :                                          diagnostics::kind::permerror);
     505                 :        2388 :   va_end (ap);
     506                 :             : 
     507                 :        2388 :   if (logger)
     508                 :           0 :     logger->log_bool_return ("permerror", ret);
     509                 :             : 
     510                 :        4776 :   return ret;
     511                 :        2388 : }
     512                 :             : 
     513                 :             : /* Same as "permerror" above, but at RICHLOC.  */
     514                 :             : 
     515                 :             : bool
     516                 :        1496 : permerror (rich_location *richloc, const char *gmsgid, ...)
     517                 :             : {
     518                 :        1496 :   gcc_assert (richloc);
     519                 :             : 
     520                 :        1496 :   auto logger = global_dc->get_logger ();
     521                 :        2992 :   log_function_params (logger, __func__)
     522                 :        1496 :     .log_param_rich_location ("richloc", richloc)
     523                 :        1496 :     .log_param_string ("gmsgid", gmsgid);
     524                 :        1496 :   auto_inc_log_depth depth_sentinel (logger);
     525                 :             : 
     526                 :        1496 :   auto_diagnostic_group d;
     527                 :        1496 :   va_list ap;
     528                 :        1496 :   va_start (ap, gmsgid);
     529                 :        1496 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
     530                 :             :                                          diagnostics::kind::permerror);
     531                 :        1496 :   va_end (ap);
     532                 :             : 
     533                 :        1496 :   if (logger)
     534                 :           0 :     logger->log_bool_return ("permerror", ret);
     535                 :             : 
     536                 :        2992 :   return ret;
     537                 :        1496 : }
     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                 :       12229 : permerror_opt (location_t location,
     545                 :             :                diagnostics::option_id option_id,
     546                 :             :                const char *gmsgid, ...)
     547                 :             : {
     548                 :       12229 :   auto logger = global_dc->get_logger ();
     549                 :       24458 :   log_function_params (logger, __func__)
     550                 :       12229 :     .log_param_location_t ("location", location)
     551                 :       12229 :     .log_param_option_id ("option_id", option_id)
     552                 :       12229 :     .log_param_string ("gmsgid", gmsgid);
     553                 :       12229 :   auto_inc_log_depth depth_sentinel (logger);
     554                 :             : 
     555                 :       12229 :   auto_diagnostic_group d;
     556                 :       12229 :   va_list ap;
     557                 :       12229 :   va_start (ap, gmsgid);
     558                 :       12229 :   rich_location richloc (line_table, location);
     559                 :       12229 :   bool ret = global_dc->diagnostic_impl (&richloc, nullptr, option_id,
     560                 :             :                                          gmsgid, &ap,
     561                 :             :                                          diagnostics::kind::permerror);
     562                 :       12229 :   va_end (ap);
     563                 :             : 
     564                 :       12229 :   if (logger)
     565                 :           0 :     logger->log_bool_return ("permerror_opt", ret);
     566                 :             : 
     567                 :       24458 :   return ret;
     568                 :       12229 : }
     569                 :             : 
     570                 :             : /* Same as "permerror" above, but at RICHLOC.  */
     571                 :             : 
     572                 :             : bool
     573                 :        1556 : permerror_opt (rich_location *richloc,
     574                 :             :                diagnostics::option_id option_id,
     575                 :             :                const char *gmsgid, ...)
     576                 :             : {
     577                 :        1556 :   gcc_assert (richloc);
     578                 :             : 
     579                 :        1556 :   auto logger = global_dc->get_logger ();
     580                 :        3112 :   log_function_params (logger, __func__)
     581                 :        1556 :     .log_param_rich_location ("richloc", richloc)
     582                 :        1556 :     .log_param_option_id ("option_id", option_id)
     583                 :        1556 :     .log_param_string ("gmsgid", gmsgid);
     584                 :        1556 :   auto_inc_log_depth depth_sentinel (logger);
     585                 :             : 
     586                 :        1556 :   auto_diagnostic_group d;
     587                 :        1556 :   va_list ap;
     588                 :        1556 :   va_start (ap, gmsgid);
     589                 :        1556 :   bool ret = global_dc->diagnostic_impl (richloc, nullptr, option_id,
     590                 :             :                                          gmsgid, &ap,
     591                 :             :                                          diagnostics::kind::permerror);
     592                 :        1556 :   va_end (ap);
     593                 :             : 
     594                 :        1556 :   if (logger)
     595                 :           0 :     logger->log_bool_return ("permerror_opt", ret);
     596                 :             : 
     597                 :        3112 :   return ret;
     598                 :        1556 : }
     599                 :             : 
     600                 :             : /* A hard error: the code is definitely ill-formed, and an object file
     601                 :             :    will not be produced.  */
     602                 :             : void
     603                 :       21567 : error (const char *gmsgid, ...)
     604                 :             : {
     605                 :       21567 :   auto logger = global_dc->get_logger ();
     606                 :       43134 :   log_function_params (logger, __func__)
     607                 :       21567 :     .log_param_string ("gmsgid", gmsgid);
     608                 :       21567 :   auto_inc_log_depth depth_sentinel (logger);
     609                 :             : 
     610                 :       21567 :   auto_diagnostic_group d;
     611                 :       21567 :   va_list ap;
     612                 :       21567 :   va_start (ap, gmsgid);
     613                 :       21567 :   rich_location richloc (line_table, input_location);
     614                 :       21567 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     615                 :             :                               diagnostics::kind::error);
     616                 :       21567 :   va_end (ap);
     617                 :       21567 : }
     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                 :       73674 : error_at (location_t loc, const char *gmsgid, ...)
     644                 :             : {
     645                 :       73674 :   auto logger = global_dc->get_logger ();
     646                 :      147348 :   log_function_params (logger, __func__)
     647                 :       73674 :     .log_param_location_t ("loc", loc)
     648                 :       73674 :     .log_param_string ("gmsgid", gmsgid);
     649                 :       73674 :   auto_inc_log_depth depth_sentinel (logger);
     650                 :             : 
     651                 :       73674 :   auto_diagnostic_group d;
     652                 :       73674 :   va_list ap;
     653                 :       73674 :   va_start (ap, gmsgid);
     654                 :       73674 :   rich_location richloc (line_table, loc);
     655                 :       73674 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     656                 :             :                               diagnostics::kind::error);
     657                 :       73674 :   va_end (ap);
     658                 :       73674 : }
     659                 :             : 
     660                 :             : /* Same as above, but use RICH_LOC.  */
     661                 :             : 
     662                 :             : void
     663                 :       13150 : error_at (rich_location *richloc, const char *gmsgid, ...)
     664                 :             : {
     665                 :       13150 :   gcc_assert (richloc);
     666                 :             : 
     667                 :       13150 :   auto logger = global_dc->get_logger ();
     668                 :       26300 :   log_function_params (logger, __func__)
     669                 :       13150 :     .log_param_rich_location ("richloc", richloc)
     670                 :       13150 :     .log_param_string ("gmsgid", gmsgid);
     671                 :       13150 :   auto_inc_log_depth depth_sentinel (logger);
     672                 :             : 
     673                 :       13150 :   auto_diagnostic_group d;
     674                 :       13150 :   va_list ap;
     675                 :       13150 :   va_start (ap, gmsgid);
     676                 :       13150 :   global_dc->diagnostic_impl (richloc, nullptr, -1, gmsgid, &ap,
     677                 :             :                               diagnostics::kind::error);
     678                 :       13150 :   va_end (ap);
     679                 :       13150 : }
     680                 :             : 
     681                 :             : /* Same as above, but with metadata.  */
     682                 :             : 
     683                 :             : void
     684                 :         401 : error_meta (rich_location *richloc, const diagnostics::metadata &metadata,
     685                 :             :             const char *gmsgid, ...)
     686                 :             : {
     687                 :         401 :   gcc_assert (richloc);
     688                 :             : 
     689                 :         401 :   auto logger = global_dc->get_logger ();
     690                 :         802 :   log_function_params (logger, __func__)
     691                 :         401 :     .log_param_rich_location ("richloc", richloc)
     692                 :         401 :     .log_param_string ("gmsgid", gmsgid);
     693                 :         401 :   auto_inc_log_depth depth_sentinel (logger);
     694                 :             : 
     695                 :         401 :   auto_diagnostic_group d;
     696                 :         401 :   va_list ap;
     697                 :         401 :   va_start (ap, gmsgid);
     698                 :         401 :   global_dc->diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap,
     699                 :             :                               diagnostics::kind::error);
     700                 :         401 :   va_end (ap);
     701                 :         401 : }
     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                 :         394 : sorry_at (location_t loc, const char *gmsgid, ...)
     726                 :             : {
     727                 :         394 :   auto logger = global_dc->get_logger ();
     728                 :         788 :   log_function_params (logger, __func__)
     729                 :         394 :     .log_param_location_t ("loc", loc)
     730                 :         394 :     .log_param_string ("gmsgid", gmsgid);
     731                 :         394 :   auto_inc_log_depth depth_sentinel (logger);
     732                 :             : 
     733                 :         394 :   auto_diagnostic_group d;
     734                 :         394 :   va_list ap;
     735                 :         394 :   va_start (ap, gmsgid);
     736                 :         394 :   rich_location richloc (line_table, loc);
     737                 :         394 :   global_dc->diagnostic_impl (&richloc, nullptr, -1, gmsgid, &ap,
     738                 :             :                               diagnostics::kind::sorry);
     739                 :         390 :   va_end (ap);
     740                 :         390 : }
     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                 :  1378314774 : seen_error (void)
     746                 :             : {
     747                 :  1378314774 :   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                 :         312 : fatal_error (location_t loc, const char *gmsgid, ...)
     755                 :             : {
     756                 :         312 :   auto logger = global_dc->get_logger ();
     757                 :         624 :   log_function_params (logger, __func__)
     758                 :         312 :     .log_param_location_t ("loc", loc)
     759                 :         312 :     .log_param_string ("gmsgid", gmsgid);
     760                 :         312 :   auto_inc_log_depth depth_sentinel (logger);
     761                 :             : 
     762                 :         312 :   auto_diagnostic_group d;
     763                 :         312 :   va_list ap;
     764                 :         312 :   va_start (ap, gmsgid);
     765                 :         312 :   rich_location richloc (line_table, loc);
     766                 :         312 :   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                 :          20 : internal_error (const char *gmsgid, ...)
     777                 :             : {
     778                 :          20 :   auto logger = global_dc->get_logger ();
     779                 :          40 :   log_function_params (logger, __func__)
     780                 :          20 :     .log_param_string ("gmsgid", gmsgid);
     781                 :          20 :   auto_inc_log_depth depth_sentinel (logger);
     782                 :             : 
     783                 :          20 :   auto_diagnostic_group d;
     784                 :          20 :   va_list ap;
     785                 :          20 :   va_start (ap, gmsgid);
     786                 :          20 :   rich_location richloc (line_table, input_location);
     787                 :          20 :   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                 :       21656 : 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                 :       21656 :   if (file == stderr && global_dc)
     830                 :       18614 :     if (!global_dc->supports_fnotice_on_stderr_p ())
     831                 :           0 :       return;
     832                 :             : 
     833                 :       21656 :   va_list ap;
     834                 :             : 
     835                 :       21656 :   va_start (ap, cmsgid);
     836                 :       21656 :   vfprintf (file, _(cmsgid), ap);
     837                 :       21656 :   va_end (ap);
     838                 :             : }
     839                 :             : 
     840                 :             : /* class auto_diagnostic_group.  */
     841                 :             : 
     842                 :             : /* Constructor: "push" this group into global_dc.  */
     843                 :             : 
     844                 :   847028728 : auto_diagnostic_group::auto_diagnostic_group ()
     845                 :             : {
     846                 :   847028728 :   global_dc->begin_group ();
     847                 :   847028728 : }
     848                 :             : 
     849                 :             : /* Destructor: "pop" this group from global_dc.  */
     850                 :             : 
     851                 :   847028339 : auto_diagnostic_group::~auto_diagnostic_group ()
     852                 :             : {
     853                 :   847028339 :   global_dc->end_group ();
     854                 :   847028339 : }
     855                 :             : 
     856                 :             : /* class auto_diagnostic_nesting_level.  */
     857                 :             : 
     858                 :       29145 : auto_diagnostic_nesting_level::auto_diagnostic_nesting_level ()
     859                 :             : {
     860                 :       29145 :   global_dc->push_nesting_level ();
     861                 :       29145 : }
     862                 :             : 
     863                 :       29145 : auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level ()
     864                 :             : {
     865                 :       29145 :   global_dc->pop_nesting_level ();
     866                 :       29145 : }
        

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