LCOV - code coverage report
Current view: top level - gcc - diagnostic-spec.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 97.8 % 91 89
Test Date: 2024-04-13 14:00:49 Functions: 100.0 % 4 4
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Functions to enable and disable individual warnings on an expression
       2                 :             :    and statement basis.
       3                 :             :    Copyright (C) 2021-2024 Free Software Foundation, Inc.
       4                 :             :    Contributed by Martin Sebor <msebor@redhat.com>
       5                 :             : 
       6                 :             :    This file is part of GCC.
       7                 :             : 
       8                 :             :    GCC is free software; you can redistribute it and/or modify it under
       9                 :             :    the terms of the GNU General Public License as published by the Free
      10                 :             :    Software Foundation; either version 3, or (at your option) any later
      11                 :             :    version.
      12                 :             : 
      13                 :             :    GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      14                 :             :    WARRANTY; without even the implied warranty of MERCHANTABILITY or
      15                 :             :    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      16                 :             :    for more details.
      17                 :             : 
      18                 :             :    You should have received a copy of the GNU General Public License
      19                 :             :    along with GCC; see the file COPYING3.  If not see
      20                 :             :    <http://www.gnu.org/licenses/>.  */
      21                 :             : 
      22                 :             : #include "config.h"
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "backend.h"
      26                 :             : #include "bitmap.h"
      27                 :             : #include "tree.h"
      28                 :             : #include "cgraph.h"
      29                 :             : #include "hash-map.h"
      30                 :             : #include "diagnostic-spec.h"
      31                 :             : #include "pretty-print.h"
      32                 :             : #include "options.h"
      33                 :             : 
      34                 :             : /* Initialize *THIS from warning option OPT.  */
      35                 :             : 
      36                 :   384488146 : nowarn_spec_t::nowarn_spec_t (opt_code opt)
      37                 :             : {
      38                 :             :   /* Create a very simple mapping based on testing and experience.
      39                 :             :      It should become more refined with time. */
      40                 :   384488146 :   switch (opt)
      41                 :             :     {
      42                 :       89751 :     case no_warning:
      43                 :       89751 :       m_bits = 0;
      44                 :       89751 :       break;
      45                 :             : 
      46                 :    26070378 :     case all_warnings:
      47                 :    26070378 :       m_bits = -1;
      48                 :    26070378 :       break;
      49                 :             : 
      50                 :             :       /* Flow-sensitive warnings about pointer problems issued by both
      51                 :             :          front ends and the middle end.  */
      52                 :      339817 :     case OPT_Waddress:
      53                 :      339817 :     case OPT_Wnonnull:
      54                 :      339817 :       m_bits = NW_NONNULL;
      55                 :      339817 :       break;
      56                 :             : 
      57                 :             :       /* Flow-sensitive warnings about arithmetic overflow issued by both
      58                 :             :          front ends and the middle end.  */
      59                 :     6153091 :     case OPT_Woverflow:
      60                 :     6153091 :     case OPT_Wshift_count_negative:
      61                 :     6153091 :     case OPT_Wshift_count_overflow:
      62                 :     6153091 :     case OPT_Wstrict_overflow:
      63                 :     6153091 :       m_bits = NW_VFLOW;
      64                 :     6153091 :       break;
      65                 :             : 
      66                 :             :       /* Lexical warnings issued by front ends.  */
      67                 :    82319827 :     case OPT_Wabi:
      68                 :    82319827 :     case OPT_Wlogical_op:
      69                 :    82319827 :     case OPT_Wparentheses:
      70                 :    82319827 :     case OPT_Wreturn_type:
      71                 :    82319827 :     case OPT_Wsizeof_array_div:
      72                 :    82319827 :     case OPT_Wstrict_aliasing:
      73                 :    82319827 :     case OPT_Wunused:
      74                 :    82319827 :     case OPT_Wunused_function:
      75                 :    82319827 :     case OPT_Wunused_but_set_variable:
      76                 :    82319827 :     case OPT_Wunused_variable:
      77                 :    82319827 :     case OPT_Wunused_but_set_parameter:
      78                 :    82319827 :       m_bits = NW_LEXICAL;
      79                 :    82319827 :       break;
      80                 :             : 
      81                 :             :       /* Access warning group.  */
      82                 :      685914 :     case OPT_Warray_bounds_:
      83                 :      685914 :     case OPT_Wformat_overflow_:
      84                 :      685914 :     case OPT_Wformat_truncation_:
      85                 :      685914 :     case OPT_Wrestrict:
      86                 :      685914 :     case OPT_Wsizeof_pointer_memaccess:
      87                 :      685914 :     case OPT_Wstrict_aliasing_:
      88                 :      685914 :     case OPT_Wstringop_overflow_:
      89                 :      685914 :     case OPT_Wstringop_overread:
      90                 :      685914 :     case OPT_Wstringop_truncation:
      91                 :      685914 :       m_bits = NW_ACCESS;
      92                 :      685914 :       break;
      93                 :             : 
      94                 :             :       /* Initialization warning group.  */
      95                 :     1629046 :     case OPT_Winit_self:
      96                 :     1629046 :     case OPT_Wuninitialized:
      97                 :     1629046 :     case OPT_Wmaybe_uninitialized:
      98                 :     1629046 :       m_bits = NW_UNINIT;
      99                 :     1629046 :       break;
     100                 :             : 
     101                 :      653637 :     case OPT_Wdangling_pointer_:
     102                 :      653637 :     case OPT_Wreturn_local_addr:
     103                 :      653637 :     case OPT_Wuse_after_free_:
     104                 :      653637 :       m_bits = NW_DANGLING;
     105                 :      653637 :       break;
     106                 :             : 
     107                 :   265461552 :     case OPT_Wpessimizing_move:
     108                 :   265461552 :     case OPT_Wredundant_move:
     109                 :   265461552 :       m_bits = NW_REDUNDANT;
     110                 :   265461552 :       break;
     111                 :             : 
     112                 :     1085133 :     default:
     113                 :             :       /* A catchall group for everything else.  */
     114                 :     1085133 :       m_bits = NW_OTHER;
     115                 :             :     }
     116                 :   384488146 : }
     117                 :             : 
     118                 :             : /* A mapping from a 'location_t' to the warning spec set for it.  */
     119                 :             : 
     120                 :             : GTY(()) nowarn_map_t *nowarn_map;
     121                 :             : 
     122                 :             : /* Return the no-warning disposition for location LOC and option OPT
     123                 :             :    or for all/any otions by default.  */
     124                 :             : 
     125                 :             : bool
     126                 :          16 : warning_suppressed_at (location_t loc, opt_code opt /* = all_warnings */)
     127                 :             : {
     128                 :          16 :   gcc_checking_assert (!RESERVED_LOCATION_P (loc));
     129                 :             : 
     130                 :          16 :   if (!nowarn_map)
     131                 :             :     return false;
     132                 :             : 
     133                 :           8 :   if (const nowarn_spec_t* const pspec = nowarn_map->get (loc))
     134                 :             :     {
     135                 :           0 :       const nowarn_spec_t optspec (opt);
     136                 :           0 :       return *pspec & optspec;
     137                 :             :     }
     138                 :             : 
     139                 :             :   return false;
     140                 :             : }
     141                 :             : 
     142                 :             :  /* Change the supression of warnings for location LOC.
     143                 :             :     OPT controls which warnings are affected.
     144                 :             :     The wildcard OPT of -1 controls all warnings.
     145                 :             :     If SUPP is true (the default), enable the suppression of the warnings.
     146                 :             :     If SUPP is false, disable the suppression of the warnings.  */
     147                 :             : 
     148                 :             : bool
     149                 :   276080963 : suppress_warning_at (location_t loc, opt_code opt /* = all_warnings */,
     150                 :             :                      bool supp /* = true */)
     151                 :             : {
     152                 :   276080963 :   gcc_checking_assert (!RESERVED_LOCATION_P (loc));
     153                 :             : 
     154                 :   276170714 :   const nowarn_spec_t optspec (supp ? opt : opt_code ());
     155                 :             : 
     156                 :   276080963 :   if (nowarn_spec_t *pspec = nowarn_map ? nowarn_map->get (loc) : NULL)
     157                 :             :     {
     158                 :    66643778 :       if (supp)
     159                 :             :         {
     160                 :    66640774 :           *pspec |= optspec;
     161                 :    66640774 :           return true;
     162                 :             :         }
     163                 :             : 
     164                 :        3004 :       *pspec &= optspec;
     165                 :        3004 :       if (*pspec)
     166                 :             :         return true;
     167                 :             : 
     168                 :        3004 :       nowarn_map->remove (loc);
     169                 :        3004 :       return false;
     170                 :             :     }
     171                 :             : 
     172                 :   209437185 :   if (!supp || opt == no_warning)
     173                 :             :     return false;
     174                 :             : 
     175                 :   209350438 :   if (!nowarn_map)
     176                 :      174481 :     nowarn_map = nowarn_map_t::create_ggc (32);
     177                 :             : 
     178                 :   209350438 :   nowarn_map->put (loc, optspec);
     179                 :   209350438 :   return true;
     180                 :             : }
     181                 :             : 
     182                 :             : /* Copy the no-warning disposition from one location to another.  */
     183                 :             : 
     184                 :             : void
     185                 :   167133149 : copy_warning (location_t to, location_t from)
     186                 :             : {
     187                 :   167133149 :   if (!nowarn_map)
     188                 :             :     return;
     189                 :             : 
     190                 :   157306482 :   nowarn_spec_t *from_spec;
     191                 :   157306482 :   if (RESERVED_LOCATION_P (from))
     192                 :             :     from_spec = NULL;
     193                 :             :   else
     194                 :   150614851 :     from_spec = nowarn_map->get (from);
     195                 :   157306482 :   if (RESERVED_LOCATION_P (to))
     196                 :             :     /* We cannot set no-warning dispositions for 'to', so we have no chance but
     197                 :             :        lose those potentially set for 'from'.  */
     198                 :             :     ;
     199                 :             :   else
     200                 :             :     {
     201                 :   150832891 :       if (from_spec)
     202                 :             :         {
     203                 :    39476319 :           nowarn_spec_t tem = *from_spec;
     204                 :    39476319 :           nowarn_map->put (to, tem);
     205                 :             :         }
     206                 :             :       else
     207                 :   111356572 :         nowarn_map->remove (to);
     208                 :             :     }
     209                 :             : }
        

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.