Open Quuxplusone opened 13 years ago
(In reply to comment #0)
> Consider the following input:
>
> int foo = 1 > 2 ? 1 << -1 : 0;
>
> This results in a warning about the negative shift, even if that branch of the
> ternary operator is known to be unused. This does work inside a function e.g.
> as statement.
We currently don't construct control-flow graphs (CFGs) when processing
initializer expressions in a global context. CFGs have been used for doing a
variety of flow-based warnings in functions, but at this point they haven't
been used for global initializer expressions.
Doing the same kind of warning suppression for global initializers would be
doable using CFGs. If we did so, I'd argue that we lazily construct the CFGs,
and only do the analysis for suppressing such warnings when necessary.
Constructing the CFGs all the time would be cost prohibitive.
That said, I somewhat question the value in doing this, although I can see how
warnings for cases like the above are a result of macro expansion.
Cloned to rdar://problem/9584097
I reported the same issue in bug 9920, but it wasn't completely clear there, that this is only triggered for global initializations. So I'll set that one as a dupe.
_Bug 9920 has been marked as a duplicate of this bug._
_Bug 16200 has been marked as a duplicate of this bug._
Still applies as of r200573.
ChromeOS kernel devs are hitting this warning and this bug is making it hard to push patches for linux kernel ( https://lkml.org/lkml/2017/3/11/61).
(In reply to Manoj Gupta from comment #7)
> ChromeOS kernel devs are hitting this warning and this bug is making it hard
> to push patches for linux kernel ( https://lkml.org/lkml/2017/3/11/61).
Yep, this bug is really starting to smell a little. Even with a very recent
trunk r297742 (as of 2017-03-14):
$ clang -c pr10030-1.c
pr10030-1.c:1:21: warning: shift count is negative [-Wshift-count-negative]
int foo = 1 > 2 ? 1 << -1 : 0;
^ ~~
1 warning generated.
Either turn off the warning for global initializers, or fix it. :)
Consider the following input:
int foo = 1 > 2 ? 1 << -1 : 0;
This results in a warning about the negative shift, even if that branch of the ternary operator is known to be unused. This does work inside a function e.g. as statement.