LCOV - code coverage report
Current view: top level - gcc/c - c-errors.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 70 70
Test Date: 2024-03-23 14:05:01 Functions: 100.0 % 3 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Various diagnostic subroutines for the GNU C language.
       2                 :             :    Copyright (C) 2000-2024 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                 :             : #include "config.h"
      22                 :             : #include "system.h"
      23                 :             : #include "coretypes.h"
      24                 :             : #include "tm.h"
      25                 :             : #include "c-tree.h"
      26                 :             : #include "opts.h"
      27                 :             : 
      28                 :             : /* Issue an ISO C11 pedantic warning MSGID if -pedantic outside C23 mode,
      29                 :             :    otherwise issue warning MSGID if -Wc11-c23-compat is specified.
      30                 :             :    This function is supposed to be used for matters that are allowed in
      31                 :             :    ISO C23 but not supported in ISO C11, thus we explicitly don't pedwarn
      32                 :             :    when C23 is specified.  */
      33                 :             : 
      34                 :             : bool
      35                 :      149144 : pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...)
      36                 :             : {
      37                 :      149144 :   diagnostic_info diagnostic;
      38                 :      149144 :   va_list ap;
      39                 :      149144 :   bool warned = false;
      40                 :      149144 :   rich_location richloc (line_table, location);
      41                 :             : 
      42                 :      149144 :   va_start (ap, gmsgid);
      43                 :             :   /* If desired, issue the C11/C23 compat warning, which is more specific
      44                 :             :      than -pedantic.  */
      45                 :      149144 :   if (warn_c11_c23_compat > 0)
      46                 :             :     {
      47                 :         124 :       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
      48                 :         124 :                            (pedantic && !flag_isoc23)
      49                 :             :                            ? DK_PEDWARN : DK_WARNING);
      50                 :         124 :       diagnostic.option_index = OPT_Wc11_c23_compat;
      51                 :         124 :       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
      52                 :             :     }
      53                 :             :   /* -Wno-c11-c23-compat suppresses even the pedwarns.  */
      54                 :      149020 :   else if (warn_c11_c23_compat == 0)
      55                 :             :     ;
      56                 :             :   /* For -pedantic outside C23, issue a pedwarn.  */
      57                 :      148938 :   else if (pedantic && !flag_isoc23)
      58                 :             :     {
      59                 :         311 :       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
      60                 :         311 :       diagnostic.option_index = opt;
      61                 :         311 :       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
      62                 :             :     }
      63                 :      149144 :   va_end (ap);
      64                 :      298288 :   return warned;
      65                 :      149144 : }
      66                 :             : 
      67                 :             : /* Issue an ISO C99 pedantic warning MSGID if -pedantic outside C11 mode,
      68                 :             :    otherwise issue warning MSGID if -Wc99-c11-compat is specified.
      69                 :             :    This function is supposed to be used for matters that are allowed in
      70                 :             :    ISO C11 but not supported in ISO C99, thus we explicitly don't pedwarn
      71                 :             :    when C11 is specified.  */
      72                 :             : 
      73                 :             : bool
      74                 :       66730 : pedwarn_c99 (location_t location, int opt, const char *gmsgid, ...)
      75                 :             : {
      76                 :       66730 :   diagnostic_info diagnostic;
      77                 :       66730 :   va_list ap;
      78                 :       66730 :   bool warned = false;
      79                 :       66730 :   rich_location richloc (line_table, location);
      80                 :             : 
      81                 :       66730 :   va_start (ap, gmsgid);
      82                 :             :   /* If desired, issue the C99/C11 compat warning, which is more specific
      83                 :             :      than -pedantic.  */
      84                 :       66730 :   if (warn_c99_c11_compat > 0)
      85                 :             :     {
      86                 :          53 :       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
      87                 :          53 :                            (pedantic && !flag_isoc11)
      88                 :             :                            ? DK_PEDWARN : DK_WARNING);
      89                 :          53 :       diagnostic.option_index = OPT_Wc99_c11_compat;
      90                 :          53 :       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
      91                 :             :     }
      92                 :             :   /* -Wno-c99-c11-compat suppresses even the pedwarns.  */
      93                 :       66677 :   else if (warn_c99_c11_compat == 0)
      94                 :             :     ;
      95                 :             :   /* For -pedantic outside C11, issue a pedwarn.  */
      96                 :       61009 :   else if (pedantic && !flag_isoc11)
      97                 :             :     {
      98                 :          81 :       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
      99                 :          81 :       diagnostic.option_index = opt;
     100                 :          81 :       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
     101                 :             :     }
     102                 :       66730 :   va_end (ap);
     103                 :      133460 :   return warned;
     104                 :       66730 : }
     105                 :             : 
     106                 :             : /* Issue an ISO C90 pedantic warning MSGID if -pedantic outside C99 mode,
     107                 :             :    otherwise issue warning MSGID if -Wc90-c99-compat is specified, or if
     108                 :             :    a specific option such as -Wlong-long is specified.
     109                 :             :    This function is supposed to be used for matters that are allowed in
     110                 :             :    ISO C99 but not supported in ISO C90, thus we explicitly don't pedwarn
     111                 :             :    when C99 is specified.  (There is no flag_c90.)  */
     112                 :             : 
     113                 :             : bool
     114                 :     3957662 : pedwarn_c90 (location_t location, int opt, const char *gmsgid, ...)
     115                 :             : {
     116                 :     3957662 :   diagnostic_info diagnostic;
     117                 :     3957662 :   va_list ap;
     118                 :     3957662 :   bool warned = false;
     119                 :     3957662 :   rich_location richloc (line_table, location);
     120                 :             : 
     121                 :     3957662 :   va_start (ap, gmsgid);
     122                 :             :   /* Warnings such as -Wvla are the most specific ones.  */
     123                 :     3957662 :   if (opt != OPT_Wpedantic)
     124                 :             :     {
     125                 :     2837151 :       int opt_var = *(int *) option_flag_var (opt, &global_options);
     126                 :     2837151 :       if (opt_var == 0)
     127                 :     2515598 :         goto out;
     128                 :      321553 :       else if (opt_var > 0)
     129                 :             :         {
     130                 :         612 :           diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
     131                 :         612 :                                (pedantic && !flag_isoc99)
     132                 :             :                                ? DK_PEDWARN : DK_WARNING);
     133                 :         612 :           diagnostic.option_index = opt;
     134                 :         612 :           diagnostic_report_diagnostic (global_dc, &diagnostic);
     135                 :         612 :           warned = true;
     136                 :         612 :           goto out;
     137                 :             :         }
     138                 :             :     }
     139                 :             :   /* Maybe we want to issue the C90/C99 compat warning, which is more
     140                 :             :      specific than -pedantic.  */
     141                 :     1441452 :   if (warn_c90_c99_compat > 0)
     142                 :             :     {
     143                 :          67 :       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
     144                 :          67 :                            (pedantic && !flag_isoc99)
     145                 :             :                            ? DK_PEDWARN : DK_WARNING);
     146                 :          67 :       diagnostic.option_index = OPT_Wc90_c99_compat;
     147                 :          67 :       diagnostic_report_diagnostic (global_dc, &diagnostic);
     148                 :             :     }
     149                 :             :   /* -Wno-c90-c99-compat suppresses the pedwarns.  */
     150                 :     1441385 :   else if (warn_c90_c99_compat == 0)
     151                 :             :     ;
     152                 :             :   /* For -pedantic outside C99, issue a pedwarn.  */
     153                 :     1031510 :   else if (pedantic && !flag_isoc99)
     154                 :             :     {
     155                 :         245 :       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_PEDWARN);
     156                 :         245 :       diagnostic.option_index = opt;
     157                 :         245 :       diagnostic_report_diagnostic (global_dc, &diagnostic);
     158                 :         245 :       warned = true;
     159                 :             :     }
     160                 :     1031265 : out:
     161                 :     3957662 :   va_end (ap);
     162                 :     7915324 :   return warned;
     163                 :     3957662 : }
        

Generated by: LCOV version 2.0-1

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.