Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Dec 1998 16:32:44 -0800 (PST)
From:      Archie Cobbs <archie@whistle.com>
To:        freebsd-hackers@FreeBSD.ORG, cvs-committers@FreeBSD.ORG
Subject:   getting to -Wunused
Message-ID:  <199812060032.QAA01400@bubba.whistle.com>

next in thread | raw e-mail | index | archive | help
Hi,
It looks like the next kernel compilation -W flag to be slayed is
the "-Wunused" flag (see bsd.kern.mk).. right now, compiling LINT
with this flag yeilds about 350 unused variable or function warnings.

These warnings break down into several cases:

 (a) Variables (and a couple of goto labels) that are defined but
     simply never referenced within their scope.

 (b) Variables and static functions that are defined, but only referenced
     conditionally (ie, #ifdef some macro) within their scope

 (c) Static functions that are declared but never defined (ie, static
     function prototype at the top of the file but no corresponding
     function anywhere in the file).

 (d) Static functions that are declared and defined, but never used:

     (i)  Some of these are defined #ifdef DDB, and are clearly meant
          for debugging purposes (they're not used, but they're handy
          to call from the debugger to print out stuff, etc). These
          are "legitimate" unused functions.

     (ii) The rest seem to be left-over cruft that should be removed
          (but this job is best left to the maintainer of that code).

My proposal is to tackle these warnings in several steps..

 Step #1.  The "easy" stuff first:

            - Fix all (a) cases by removing the declaration.
            - Fix all (b) cases by making the declaration subject to
              the same #ifdef (or commenting out) as the use (sometimes
              this means relocating the declaration to an inner block).
            - Fix all (c) cases by removing the useless declaration.

           NOTE: this does *not* include variables initialized with a
           value that's the result of some function call (which could
           have side effects), nor variables meant to server as marks in
           the data segment, such as sys/ufs/mfs/mfs_vfsops.c:end_mfs_root.

 Step #2.  Add "__attribute__ ((unused))" to all cases of (d)(i), that is,
           obviously legitimate unused functions (I count only 2 so far).

 Step #3.  Turn on -Wunused in bsd.kern.mk so everybody can participate :-)

 Step #4.  Let any remaining warnings be handled by their respective
           maintainers.

Note that Steps #1 and #2 will *not* eliminate all the unused variable
warnings, because I can't do a kernel compile with every possible
permutation of kernel options.. but it should get most of them.

Step #2 (later!) will be a very small patch.

I plan to commit patches for step #1 in a couple of days if there's
no fears/complaints... these are available for review here:

  ftp://ftp.whistle.com/pub/archie/misc/PATCH.unused

There are 112 files affected.

COMMITTERS: if you are afraid of something getting screwed up by
Step #1, please review the patch for the file(s) you're interested in.

Thanks,
-Archie

___________________________________________________________________________
Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199812060032.QAA01400>