[llvm-bugs] [Bug 46991] New: False positives in core.NullDereference on non_odr_use_constant DeclRefExpr to non-capture
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Aug 4 10:24:39 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=46991
Bug ID: 46991
Summary: False positives in core.NullDereference on
non_odr_use_constant DeclRefExpr to non-capture
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Static Analyzer
Assignee: dcoughlin at apple.com
Reporter: aaronpuchert at alice-dsl.net
CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org
On the following code:
void foo(int v);
constexpr int VAL = 1;
void bar()
{
const int& val = VAL;
[]() {
foo(val);
}();
}
the static analyzer warns
<source>:7:13: warning: Dereference of undefined pointer value
[core.NullDereference]
foo(val);
^
<source>:6:5: note: Uninitialized value stored to 'val'
[]() {
^~~~~~
<source>:6:5: note: Calling 'operator()'
[]() {
^~~~~~
<source>:7:13: note: Dereference of undefined pointer value
foo(val);
^~~
I think that's wrong, val has an initializer expression. Note that the
DeclRefExpr referring to val is marked as non_odr_use_constant, and val doesn't
need to be captured. Adding an explicit capture fixes the Static Analyzer issue
but raises a regular Clang warning:
<source>:6:6: warning: lambda capture 'val' is not required to be captured for
this use [-Wunused-lambda-capture]
[val]() {
^~~
or
<source>:6:7: warning: lambda capture 'val' is not required to be captured for
this use [-Wunused-lambda-capture]
[&val]() {
~^~~
Using a capture-default expression, i.e. [=] or [&], does not fix the issue.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200804/5e93d940/attachment.html>
More information about the llvm-bugs
mailing list