LCOV - code coverage report
Current view: top level - gcc - gcc-diagnostic-spec.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 100 100
Test Date: 2026-09-19 16:22:48 Functions: 100.0 % 5 5
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Functions to enable and disable individual warnings on an expression
       2              :    and statement basis.
       3              :    Copyright (C) 2021-2026 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 "gcc-diagnostic-spec.h"
      31              : #include "pretty-print.h"
      32              : #include "options.h"
      33              : 
      34              : /* Initialize *THIS from warning option OPT.  */
      35              : 
      36    554802878 : 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    554802878 :   switch (opt)
      41              :     {
      42        61949 :     case no_warning:
      43        61949 :       m_bits = 0;
      44        61949 :       break;
      45              : 
      46     27996104 :     case all_warnings:
      47     27996104 :       m_bits = -1;
      48     27996104 :       break;
      49              : 
      50              :       /* Flow-sensitive warnings about pointer problems issued by both
      51              :          front ends and the middle end.  */
      52       329086 :     case OPT_Waddress:
      53       329086 :     case OPT_Wnonnull:
      54       329086 :       m_bits = NW_NONNULL;
      55       329086 :       break;
      56              : 
      57              :       /* Flow-sensitive warnings about arithmetic overflow issued by both
      58              :          front ends and the middle end.  */
      59       675299 :     case OPT_Woverflow:
      60       675299 :     case OPT_Wshift_count_negative:
      61       675299 :     case OPT_Wshift_count_overflow:
      62       675299 :       m_bits = NW_VFLOW;
      63       675299 :       break;
      64              : 
      65              :       /* Lexical warnings issued by front ends.  */
      66    144182896 :     case OPT_Wabi:
      67    144182896 :     case OPT_Wlogical_op:
      68    144182896 :     case OPT_Wparentheses:
      69    144182896 :     case OPT_Wreturn_type:
      70    144182896 :     case OPT_Wsizeof_array_div:
      71    144182896 :     case OPT_Wstrict_aliasing:
      72    144182896 :     case OPT_Wunused:
      73    144182896 :     case OPT_Wunused_function:
      74    144182896 :     case OPT_Wunused_but_set_variable_:
      75    144182896 :     case OPT_Wunused_variable:
      76    144182896 :     case OPT_Wunused_but_set_parameter_:
      77    144182896 :       m_bits = NW_LEXICAL;
      78    144182896 :       break;
      79              : 
      80              :       /* Access warning group.  */
      81       808532 :     case OPT_Warray_bounds_:
      82       808532 :     case OPT_Wformat_overflow_:
      83       808532 :     case OPT_Wformat_truncation_:
      84       808532 :     case OPT_Wrestrict:
      85       808532 :     case OPT_Wsizeof_pointer_memaccess:
      86       808532 :     case OPT_Wstrict_aliasing_:
      87       808532 :     case OPT_Wstringop_overflow_:
      88       808532 :     case OPT_Wstringop_overread:
      89       808532 :     case OPT_Wstringop_truncation:
      90       808532 :       m_bits = NW_ACCESS;
      91       808532 :       break;
      92              : 
      93              :       /* Initialization warning group.  */
      94      2056298 :     case OPT_Winit_self:
      95      2056298 :     case OPT_Wuninitialized:
      96      2056298 :     case OPT_Wmaybe_uninitialized:
      97      2056298 :       m_bits = NW_UNINIT;
      98      2056298 :       break;
      99              : 
     100       935496 :     case OPT_Wdangling_pointer_:
     101       935496 :     case OPT_Wreturn_local_addr:
     102       935496 :     case OPT_Wuse_after_free_:
     103       935496 :       m_bits = NW_DANGLING;
     104       935496 :       break;
     105              : 
     106    374766009 :     case OPT_Wpessimizing_move:
     107    374766009 :     case OPT_Wredundant_move:
     108    374766009 :       m_bits = NW_REDUNDANT;
     109    374766009 :       break;
     110              : 
     111      2991209 :     default:
     112              :       /* A catchall group for everything else.  */
     113      2991209 :       m_bits = NW_OTHER;
     114              :     }
     115    554802878 : }
     116              : 
     117              : /* A mapping from a 'location_t' to the warning spec set for it.  */
     118              : 
     119              : GTY(()) nowarn_map_t *nowarn_map;
     120              : 
     121              : /* Return the no-warning disposition for location LOC and option OPT
     122              :    or for all/any options by default.  */
     123              : 
     124              : bool
     125       180745 : warning_suppressed_at (location_t loc, opt_code opt /* = all_warnings */)
     126              : {
     127       180745 :   gcc_checking_assert (!RESERVED_LOCATION_P (loc));
     128              : 
     129       180745 :   if (!nowarn_map)
     130              :     return false;
     131              : 
     132       180557 :   if (const nowarn_spec_t* const pspec = nowarn_map->get (loc))
     133              :     {
     134        26624 :       const nowarn_spec_t optspec (opt);
     135        26624 :       return *pspec & optspec;
     136              :     }
     137              : 
     138              :   return false;
     139              : }
     140              : 
     141              :  /* Change the suppression of warnings for location LOC.
     142              :     OPT controls which warnings are affected.
     143              :     The wildcard OPT of -1 controls all warnings.
     144              :     If SUPP is true (the default), enable the suppression of the warnings.
     145              :     If SUPP is false, disable the suppression of the warnings.  */
     146              : 
     147              : bool
     148    409889686 : suppress_warning_at (location_t loc, opt_code opt /* = all_warnings */,
     149              :                      bool supp /* = true */)
     150              : {
     151    409889686 :   gcc_checking_assert (!RESERVED_LOCATION_P (loc));
     152              : 
     153    409951635 :   const nowarn_spec_t optspec (supp ? opt : opt_code ());
     154              : 
     155    409889686 :   if (nowarn_spec_t *pspec = nowarn_map ? nowarn_map->get (loc) : nullptr)
     156              :     {
     157    120453912 :       if (supp)
     158              :         {
     159    120450939 :           *pspec |= optspec;
     160    120450939 :           return true;
     161              :         }
     162              : 
     163         2973 :       *pspec &= optspec;
     164         2973 :       if (*pspec)
     165              :         return true;
     166              : 
     167         2973 :       nowarn_map->remove (loc);
     168         2973 :       return false;
     169              :     }
     170              : 
     171    289435774 :   if (!supp || opt == no_warning)
     172              :     return false;
     173              : 
     174    289376798 :   if (!nowarn_map)
     175       186268 :     nowarn_map = nowarn_map_t::create_ggc (32);
     176              : 
     177    289376798 :   nowarn_map->put (loc, optspec);
     178    289376798 :   return true;
     179              : }
     180              : 
     181              : /* Change the warning disposition for LOC to match OPTSPEC.  */
     182              : 
     183              : void
     184       489646 : put_warning_spec_at (location_t loc, unsigned bits)
     185              : {
     186       489646 :   gcc_checking_assert (!RESERVED_LOCATION_P (loc));
     187              : 
     188       489646 :   nowarn_spec_t optspec = nowarn_spec_t::from_bits (bits);
     189       489646 :   if (!optspec)
     190              :     {
     191       203763 :       if (nowarn_map)
     192       203613 :         nowarn_map->remove (loc);
     193              :     }
     194              :   else
     195              :     {
     196       285883 :       if (!nowarn_map)
     197          211 :         nowarn_map = nowarn_map_t::create_ggc (32);
     198       285883 :       nowarn_map->put (loc, optspec);
     199              :     }
     200       489646 : }
     201              : 
     202              : /* Copy the no-warning disposition from one location to another.  */
     203              : 
     204              : void
     205    251294502 : copy_warning (location_t to, location_t from)
     206              : {
     207    251294502 :   if (!nowarn_map)
     208              :     return;
     209              : 
     210    238181569 :   nowarn_spec_t *from_spec;
     211    238181569 :   if (RESERVED_LOCATION_P (from))
     212              :     from_spec = nullptr;
     213              :   else
     214    216821654 :     from_spec = nowarn_map->get (from);
     215    238181569 :   if (RESERVED_LOCATION_P (to))
     216              :     /* We cannot set no-warning dispositions for 'to', so we have no chance but
     217              :        lose those potentially set for 'from'.  */
     218              :     ;
     219              :   else
     220              :     {
     221    217443799 :       if (from_spec)
     222              :         {
     223     64513788 :           nowarn_spec_t tem = *from_spec;
     224     64513788 :           nowarn_map->put (to, tem);
     225              :         }
     226              :       else
     227    152930011 :         nowarn_map->remove (to);
     228              :     }
     229              : }
        

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.