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.