FS/XFS testing framework
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Zorro Lang <zlang@redhat.com>
Cc: Shiyang Ruan <ruansy.fnst@fujitsu.com>, fstests@vger.kernel.org
Subject: Re: [PATCH] include/builddefs.in: ignore unused-result warning
Date: Wed, 15 Jan 2025 13:45:47 -0800	[thread overview]
Message-ID: <20250115214547.GG3557695@frogsfrogsfrogs> (raw)
In-Reply-To: <20250115153327.izjczrhtpd2yjfjc@dell-per750-06-vm-08.rhts.eng.pek2.redhat.com>

On Wed, Jan 15, 2025 at 11:33:27PM +0800, Zorro Lang wrote:
> On Mon, Jan 06, 2025 at 05:59:06PM +0800, Shiyang Ruan wrote:
> > When build xfstests, a lot of "unused result" warning are reported:
> > 
> >     [CC] write_log.lo
> > write_log.c: In function 'wlog_record_write':
> > write_log.c:205:13: warning: ignoring return value of 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
> >   205 |             write(wfile->w_afd, wbuf, reclen);
> >       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > write_log.c:209:13: warning: ignoring return value of 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
> >   209 |             write(wfile->w_rfd, wbuf, reclen);
> >       |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >     [CC] random.lo
> 
> Hi,
> 
> I never hit this build warning:
> 
> # make
> ...
> Building lib
>     [LTDEP]
>     [CC] write_log.lo
>     [LD]
> Building ltp
>     [CC]    doio
>     [CC]    fsstress
> ...
> 
> Besides that ...
> 
> > 
> > Mostly are calused by not using the return value of read()/write()/...
> > Ignore this warning by adding `-Wno-unused-result` to CCFLAGS.  This
> > won't cause other problem but make the log clean.
> > 
> > Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com>
> > ---
> >  include/builddefs.in | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/include/builddefs.in b/include/builddefs.in
> > index 7274cde8d..edf87ff00 100644
> > --- a/include/builddefs.in
> > +++ b/include/builddefs.in
> > @@ -75,7 +75,7 @@ HAVE_RLIMIT_NOFILE = @have_rlimit_nofile@
> >  NEED_INTERNAL_XFS_IOC_EXCHANGE_RANGE = @need_internal_xfs_ioc_exchange_range@
> >  HAVE_FICLONE = @have_ficlone@
> >  
> > -GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall
> > +GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall -Wno-unused-result
> 
> I'm not an expert of gcc. From the manual of gcc, it says:
> 
>        -Wno-unused-result
>            Do not warn if a caller of a function marked with attribute "warn_unused_result" does not use its return value. The default is -Wunused-result.
> 
> Looks like the "-Wno-unused-result" works for "a function marked with
> attribute warn_unused_result", e.g.
> 
>     int __attribute__((warn_unused_result)) foo(void)
> 
> I think fstests doesn't use that attribute.

No, but unistd.h does for write():

extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur
    __attr_access ((__read_only__, 2, 3));

where "__wur" is a macro wrapping __attribute__
((__warn_unused_result__)) if available and FORTIFY_SOURCE is nonzero.

But, uh, shouldn't we fix these programs either to fail the test because
some part of its execution failed, or declare that the return value is
irrelevant if that's the case?

--D

> Thanks,
> Zorro
> 
> 
> >  
> >  ifeq ($(PKG_PLATFORM),linux)
> >  PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $(GCCFLAGS)
> > -- 
> > 2.43.0
> > 
> > 
> 
> 

  reply	other threads:[~2025-01-15 21:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-06  9:59 [PATCH] include/builddefs.in: ignore unused-result warning Shiyang Ruan
2025-01-15  9:15 ` Shiyang Ruan
2025-01-15 15:33 ` Zorro Lang
2025-01-15 21:45   ` Darrick J. Wong [this message]
2025-01-17  4:11     ` Zorro Lang
2025-01-16  9:55   ` Shiyang Ruan
2025-01-17  4:01     ` Zorro Lang
2025-01-17  5:55       ` Shiyang Ruan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250115214547.GG3557695@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=fstests@vger.kernel.org \
    --cc=ruansy.fnst@fujitsu.com \
    --cc=zlang@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox