From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: dsterba@suse.cz, Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2 07/13] btrfs-progs: Fix Wmaybe-uninitialized warning
Date: Tue, 15 Jan 2019 18:42:47 +0100 [thread overview]
Message-ID: <20190115174247.GM2900@twin.jikos.cz> (raw)
In-Reply-To: <926908c6-14c0-5c10-7ce2-de4b810e702b@gmx.com>
On Wed, Dec 05, 2018 at 10:03:30PM +0800, Qu Wenruo wrote:
>
>
> On 2018/12/5 下午9:40, David Sterba wrote:
> > On Wed, Dec 05, 2018 at 02:40:12PM +0800, Qu Wenruo wrote:
> >> GCC 8.2.1 will report the following warning with "make W=1":
> >>
> >> ctree.c: In function 'btrfs_next_sibling_tree_block':
> >> ctree.c:2990:21: warning: 'slot' may be used uninitialized in this function [-Wmaybe-uninitialized]
> >> path->slots[level] = slot;
> >> ~~~~~~~~~~~~~~~~~~~^~~~~~
> >>
> >> The culprit is the following code:
> >>
> >> int slot; << Not initialized
> >> int level = path->lowest_level + 1;
> >> BUG_ON(path->lowest_level + 1 >= BTRFS_MAX_LEVEL);
> >> while(level < BTRFS_MAX_LEVEL) {
> >> slot = path->slots[level] + 1;
> >> ^^^^^^ but we initialize @slot here.
> >> ...
> >> }
> >> path->slots[level] = slot;
> >>
> >> It's possible that compiler doesn't get enough hint for BUG_ON() on
> >> lowest_level + 1 >= BTRFS_MAX_LEVEL case.
> >>
> >> Fix it by using a do {} while() loop other than while() {} loop, to
> >> ensure we will run the loop for at least once.
> >
> > I was hoping that we can actually add the hint to BUG_ON so the code
> > does not continue if the condition is true.
> >
> I checked that method, but I'm not that confident about things like:
>
> bugon_trace()
> {
> if (!val)
> return;
> __bugon_trace();
> }
>
> __attribute__ ((noreturn))
> static inline void __bugon_trace();
>
> This is as simple as just one extra function call, but the original
> problem is just one more function call before hitting abort().
>
> So I just give up screwing up things I'm not comfort enough to tweaking.
>
> The current do {} while() loop is the most direct solution, if gcc one
> day still gives such warning then I could say some harsh word then.
I was not able to make it work properly, patch applied so we rid of the
warning. Thanks.
next prev parent reply other threads:[~2019-01-15 17:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-05 6:40 [PATCH v2 00/13] btrfs-progs: Make W=1 great (no "again") Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 01/13] btrfs-progs: Makefile.extrawarn: Import cc-disable-warning Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 02/13] btrfs-progs: fix gcc8 default build warning caused by '-Wformat-truncation' Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 03/13] btrfs-progs: Makefile.extrawarn: Don't warn on sign compare Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 04/13] btrfs-progs: Fix Wempty-body warning Qu Wenruo
2018-12-13 18:59 ` David Sterba
2018-12-13 23:54 ` Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 05/13] btrfs-progs: Fix Wimplicit-fallthrough warning Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 06/13] btrfs-progs: Fix Wsuggest-attribute=format warning Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 07/13] btrfs-progs: Fix Wmaybe-uninitialized warning Qu Wenruo
2018-12-05 13:40 ` David Sterba
2018-12-05 14:03 ` Qu Wenruo
2019-01-15 17:42 ` David Sterba [this message]
2018-12-05 6:40 ` [PATCH v2 08/13] btrfs-progs: Fix Wtype-limits warning Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 09/13] btrfs-progs: Fix missing-prototypes warning caused by non-static functions Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 10/13] btrfs-progs: Move btrfs_check_nodesize to fsfeatures.c to fix missing-prototypes warning Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 11/13] btrfs-progs: Introduce rescue.h to resolve missing-prototypes for chunk and super rescue Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 12/13] btrfs-progs: Add utils.h include to solve missing-prototypes warning Qu Wenruo
2018-12-05 6:40 ` [PATCH v2 13/13] btrfs-progs: free-space-tree: Remove unsued function Qu Wenruo
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=20190115174247.GM2900@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.com \
--cc=wqu@suse.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;
as well as URLs for NNTP newsgroup(s).