Re: [PATCH] mac80211: Fix clang warning about constant operand in logical operation
From: Matthias Kaehlcke
Date: Thu Apr 06 2017 - 15:25:28 EST
Hi Johannes,
thanks for your comments
El Thu, Apr 06, 2017 at 09:11:18PM +0200 Johannes Berg ha dit:
> On Thu, 2017-04-06 at 11:56 -0700, Matthias Kaehlcke wrote:
> > Clang raises a warning about the expression 'strlen(CONFIG_XXX)'
> > being
> > used in a logical operation. Clangs' builtin strlen function resolves
> > the
> > expression to a constant at compile time, which causes clang to
> > generate
> > a 'constant-logical-operand' warning.
> >
> > Split the if statement in two to avoid using the const expression in
> > a logical operation.
> >
> I don't really see all much point in doing this for the warning's
> sake... hopefully it doesn't actually generate worse code, but I think
> the code ends up looking worse and people will forever wonder what the
> goto is really doing there.
I agree that the code looks worse :( I hoped to find a fix using a
preprocessor condition but wasn't successful.
Some projects (like Chrome OS) build their kernel with all warnings
being treated as errors. Besides changing the 'offending' code the
alternatives are to disable the warning completely or to tell clang
not to use the builtin(s). IMO changing the code is the preferable
solution, especially since this is so far the only occurrence of the
warning that I have encountered.
I used goto instead of nested ifs since other functions in this file
use the same pattern. If nested ifs are preferred I can change that.
Cheers
Matthias