Subject: bin/4027: lint wrongly reports "foo returns value which is always ignored"
To: None <gnats-bugs@gnats.netbsd.org>
From: Krister Walfridsson <cato@ulysses.df.lth.se>
List: netbsd-bugs
Date: 08/23/1997 18:55:51
>Number:         4027
>Category:       bin
>Synopsis:       lint wrongly reports "foo returns value which is always ignored"
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Aug 23 10:05:00 1997
>Last-Modified:
>Originator:     Krister Walfridsson
>Organization:
	
>Release:        NetBSD-current Aug 15 1997
>Environment:
	
System: NetBSD ulysses 1.2G NetBSD 1.2G (KWA) #0: Fri Aug 15 20:36:02 CEST 1997 cato@ulysses:/usr/src/sys/arch/sparc/compile/KWA sparc


>Description:
Lint doesn't always differ between the cases 

   foo returns value which is always ignored
   foo returns value which is sometimes ignored

The problem occurs when you have a function which returns a value
which never is used, and you cast it to void, but forgets some of
the calls. You will then get the message "... always ignored"


>How-To-Repeat:
Try lint -abcehruzx foo.c on a file containing

foo(void)
{
  return 23;
}

void
bar(void)
{
  (void)foo();
  foo();
}

This will give you the output

   bash$ lint -abcehruzx foo.c
   foo.c:
   Lint pass2:
   foo returns value which is always ignored

but it should be "foo returns value which is sometimes ignored"

>Fix:
One idea is to treat cast to void as if the value was used, by
changing src/usr.bin/xlint/lint2/chk.c as in

diff -u chk.c.old chk.c
--- chk.c.old   Sun Dec 22 14:15:39 1996
+++ chk.c       Fri Aug 22 23:48:22 1997
@@ -1182,7 +1182,7 @@
                /* function has return value */
                used = ignored = 0;
                for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
-                       used |= call->f_rused;
+                       used |= call->f_rused || call->f_rdisc;
                        ignored |= !call->f_rused && !call->f_rdisc;
                }
                /*

>Audit-Trail:
>Unformatted: