Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Dead branch warning elimination doesn't trigger for global initialisation #8469

Open Quuxplusone opened 13 years ago

Quuxplusone commented 13 years ago
Bugzilla Link PR10030
Status NEW
Importance P normal
Reported by Jörg Sonnenberger (joerg@NetBSD.org)
Reported on 2011-05-26 17:58:45 -0700
Last modified on 2018-10-25 20:11:57 -0700
Version trunk
Hardware PC Linux
CC dimitry@andric.com, kremenek@apple.com, llvm-bugs@lists.llvm.org, manojgupta@google.com, matthew@dempsky.org, richard-llvm@metafoo.co.uk
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

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.

Quuxplusone commented 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.
Quuxplusone commented 13 years ago

Cloned to rdar://problem/9584097

Quuxplusone commented 13 years ago

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.

Quuxplusone commented 13 years ago

_Bug 9920 has been marked as a duplicate of this bug._

Quuxplusone commented 11 years ago

_Bug 16200 has been marked as a duplicate of this bug._

Quuxplusone commented 10 years ago

Still applies as of r200573.

Quuxplusone commented 7 years ago

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).

Quuxplusone commented 7 years ago
(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. :)